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.

GPT-6 Astra

https://openai.com/index/gpt-6-astra/
635•kibae•2h ago•368 comments

Qwen 3.8 27B available on Cerebras at 1500 tokens/s

https://inference-docs.cerebras.ai/models/overview
276•altertable•2h ago•93 comments

.name Termination

https://neil.fraser.name/news/2026/09/03/
1009•pavel_lishin•5h ago•302 comments

Any Human Ever – One life, drawn at random from all who have ever lived

https://anyhumanever.com/
333•thinkingemote•5h ago•148 comments

K2 Horizon: A connected fleet of six open models

https://ifm.ai/blog/k2/
201•karimf•5h ago•66 comments

Porting my 1993 Amiga game to Godot, with an LLM reading the 68000 assembly

https://babyloniantwins.com/blog/porting-a-1993-amiga-game-to-godot/
98•rabahs•6h ago•34 comments

Artificial beaver dams saw juvenile coho salmon survival rates go from 8% to 60%

https://www.discoverwildlife.com/animal-facts/artificial-beaver-dams-california
69•speckx•4h ago•14 comments

Unusual Suspects

https://neal.fun/unusual-suspects/
48•beeperboy95•1d ago•12 comments

The largest electric aircraft just flew [video]

https://www.youtube.com/watch?v=nM86DBOqgPM
25•feb•2d ago•13 comments

OpenAI's GPT-6 Astra on ARC-AGI-3

https://arcprize.org/blog/astra
47•vignesh_warar•57m ago•17 comments

The death of San Francisco's Market Street

https://www.noahpinion.blog/p/the-death-of-market-street
19•A_D_E_P_T•1h ago•14 comments

The true horror of Edgar Allan Poe’s stories lies in their confessions

https://yalereview.org/article/emily-ogden-edgar-allan-poe
22•lermontov•1d ago•3 comments

Gooseworks (YC W23) Is Hiring – Founding Creative Engineer

https://www.ycombinator.com/companies/gooseworks/jobs/rfgY8La-founding-creative-engineer
1•shivsak•3h ago

GPS glitched across the US by as much as 33 feet

https://www.sciencealert.com/gps-glitched-across-the-us-by-as-much-as-33-feet-scientists-have-nev...
45•thread_id•19h ago•12 comments

Audacity 4.0

https://github.com/audacity/audacity/releases/tag/Audacity-4.0.0
957•ClydeN•9h ago•212 comments

Ask HN: Why were OpenAI, Claude, and Grok simultaneously down?

270•halcdev•5h ago•483 comments

Xanadu was waiting for agents

https://zed.dev/blog/agentic-xanadu
22•nsm•2d ago•8 comments

Static Allocation, Constant Work

https://matklad.github.io/2026/09/02/static-allocation-constant-work.html
83•surprisetalk•1d ago•13 comments

VC isn't VC anymore

https://www.anildash.com/2026/09/02/cancer-capital/
124•cdrnsf•22h ago•126 comments

Launch HN: Mireye (YC S26) – Infrastructure for Physical World AI Agents

24•anshchokshi•4h ago•1 comments

Gloria Steinem has died

https://www.theguardian.com/books/2026/sep/03/gloria-steinem-groundbreaking-feminist-campaigner-d...
68•mellosouls•10h ago•23 comments

The asteroid currently hitting front end web development

https://nolanlawson.com/2026/08/23/the-asteroid-currently-hitting-frontend-web-development/
20•codechicago277•1h ago•13 comments

How concerned should we be about Astra's recurrent architecture?

https://www.lesswrong.com/posts/PLisnSFir8y5AHkmP/how-concerned-should-we-be-about-astra-s-recurrent
43•yurivish•3h ago•23 comments

Go grandmaster Shin defeats AI KataGo with a two-stone handicap

https://www.kedglobal.com/artificial-intelligence/newsView/ked202607210007
91•gmays•19h ago•19 comments

“We want it to really confuse people, but also really make people happy”

https://unsung.aresluna.org/we-want-it-to-really-confuse-people-but-also-really-make-people-happy/
41•zdw•4d ago•12 comments

Google Antigravity TOS: 3rd party usage can get Google account suspended

https://twitter.com/GergelyOrosz/status/2095453567955968398
218•tosh•9h ago•151 comments

How to get a free .arpa domain

https://hawksley.dev/blog/get-free-arpa-domain
76•ethanhawksley•2d ago•8 comments

Unified Arabic

https://worksthatwork.com/6/unified-arabic
53•spacebuffer•1d ago•5 comments

Astronomers Detect a 10-Sided Structure in Saturn's Atmosphere

https://www.sciencealert.com/astronomers-spot-an-uncannily-geometric-10-sided-structure-in-saturn...
72•jjgreen•6h ago•28 comments

Pre-Release of Polars 2.0

https://pola.rs/posts/announcing-polars-2/
366•komape•13h ago•120 comments