frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•1y ago

Comments

LegionMammal978•1y ago
I'd argue that any equality comparison of floating-point numbers is asking for trouble, unless you're specifically working with small dyadic fractions (using exact comparison) or testing a purely heuristic 'closeness' condition (using fuzzy comparison).

Of course, inequalities show up in a lot more places, but are similarly fraught with difficulty, since mathematical statements may fail to translate to floating-point inequalities. E.g., in computational geometry, people have written entire papers about optimizing correct orientation predicates [0], since the naive method can easily break at small angles. This sort of thing is what often shows up as tiny seams in 3D video-game geometry.

[0] https://www.cs.cmu.edu/~quake/robust.html

mtklein•1y ago
My preferred way to compare floats as being interchangeably equivalent in unit tests is

    bool equiv(float x, float y) {
        return (x <= y && y <= x)
            || (x != x && y != y);
    }
This handles things like ±0 and NaNs (while NaNs can't be IEEE-754-equal per se, they're almost always interchangeable), and convinces -Wfloat-equal you kinda know what you're doing. Also everything visually lines up real neat and tidy, which I find makes it easy to remember.

Outside unit tests... I haven't really encountered many places where float equality is actually what I want to test. It's usually some < or <= condition instead.

sph•1y ago
I have built a production Javascript library with decent amounts of users that incorporates the following hack to deal with float error (avert your eyes if you're sensitive):

  // 1.2 - 1.0 === 0.19999999999999996
  // fixFloatError(1.2 - 1.0) === 0.2
  var fixFloatError = function (n) {
    return parseFloat(n.toPrecision(12));
  };
It felt correct at the time, but after reading the article, I cringe at how fundamentally broken it is. I got away with it because the library is used to convert betting odds, which are mostly small floating point numbers, so the error is often < 10^-12.

Beauty in DVD Menus

https://vale.rocks/posts/dvd-menus
60•speckx•1h ago•33 comments

“Math 2.0” will need to value mathematical progress more holistically

https://mathstodon.xyz/@tao/117395269325940185
468•ent101•9h ago•448 comments

The Slow Formation of Durable Software

https://newsletter.dancohen.org/archive/the-slow-formation-of-durable-software/
111•benbreen•1d ago•30 comments

Telnet BBS Guide

https://www.telnetbbsguide.com/
44•kmstout•2h ago•19 comments

OpenAI Withdraws 3 Math Papers

https://github.com/openai/math/blob/main/history.md
247•theemathas•6h ago•192 comments

Claude Haiku 5.5

https://www.anthropic.com/claude-haiku-5-5
964•sfkgtbor•20h ago•452 comments

The 15-year search for a band that charted once and vanished

https://shahidhussain.com/writing/search-for-salvage/
249•shahidhussain•3d ago•92 comments

I gave Opus 5.5 one prompt and six hours to visualize Invisible Cities

https://quesma.com/blog/invisible-cities-one-shot/
160•stared•2h ago•89 comments

Time Travel in Braid (2015)

https://qntm.org/braid
38•Ariarule•3d ago•9 comments

Living off-grid: Hundred Rabbits

https://100r.ca/site/home.html
300•Muhammad523•2d ago•113 comments

Margaret Hamilton has died

https://news.mit.edu/2026/margaret-hamilton-computing-pioneer-dies-1007
1883•muglug•17h ago•210 comments

GPT‑6 and Intelligent UI for everyone

https://openai.com/index/gpt-6-for-everyone/
702•joshuawright11•20h ago•410 comments

How did Rosalind Franklin miss the helix in her iconic DNA image? She didn't

https://www.science.org/content/article/how-did-rosalind-franklin-miss-helix-her-iconic-dna-image...
242•pavel_lishin•2d ago•83 comments

'Jonathan' is the oldest land animal on Earth

https://www.404media.co/oldest-living-land-animal-jonathan-the-tortoise/
211•gumby•18h ago•116 comments

Anne Carson wins Nobel Prize in literature 2026

https://www.theguardian.com/books/2026/oct/08/wins-the-nobel-prize-in-literature-2026
79•sonabinu•2h ago•6 comments

The Mathocalypse

https://scottaaronson.blog/?p=10169
318•6bitquant•19h ago•325 comments

Cleo (Mathematician)

https://en.wikipedia.org/wiki/Cleo_(mathematician)
209•djoldman•1d ago•39 comments

Show HN: Bigwords.page – Turn any screen into a sign. The URL is the app

https://bigwords.page/
595•SpeakingOfBrad•23h ago•144 comments

Float and integer arithmetic follow two different paradigms

https://blog.pkh.me/p/49-float-and-integer-arithmetic-follow-two-different-paradigms.html
15•ibobev•3d ago•2 comments

Bloody Cavemen

https://www.lrb.co.uk/the-paper/v48/n18/edmund-gordon/bloody-cavemen
28•Thevet•1d ago•3 comments

AHM Statement on OpenAI's October 6 Release of Mathematical Documents

https://www.ahmath.org/statements
36•kkoncevicius•5h ago•33 comments

Sharing AI progress in mathematics

https://openai.com/index/sharing-ai-progress-in-mathematics/
1299•OfficialTurkey•1d ago•1476 comments

In Vienna and Beijing, the first (thorium) nuclear clocks begin to tick

https://www.nytimes.com/2026/10/07/science/first-nuclear-clocks-thorium-229.html
133•gumby•20h ago•40 comments

New repository settings for configuring pull request access

https://github.blog/changelog/2026-02-13-new-repository-settings-for-configuring-pull-request-acc...
35•Bluestein•2d ago•21 comments

Dat-ecosystem: high level applications built on top of P2P protocols

https://dat-ecosystem.org/
34•janandonly•8h ago•14 comments

'The eels were climbing out of the water to die'

https://www.theguardian.com/environment/2026/sep/24/furnace-book-east-sussex-fishing-lake
21•speckx•2d ago•5 comments

Why the AI future will be awesome

https://nullpaste.org/raw/t-0Um6AUv_CJ
5•samstress•30m ago•1 comments

Docker Agent

https://github.com/docker/docker-agent
275•saikatsg•20h ago•126 comments

Push ifs up and fors down: The idiom, its algebra, and its limits

https://debasishg.github.io/blog/push-ifs-up-fors-down/
168•speckx•20h ago•77 comments

Classic PC demoscene productions running natively in the browser

https://treylorswift.github.io/demoscene-recomp/web/
128•adunk•8h ago•115 comments