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.

Livenerf: Has Opus 5.5 been nerfed yet?

https://github.com/ninjahawk/livenerf
399•bryan0•6h ago•159 comments

LinkedIn Larpmaxxing

https://hereticpleb.vercel.app/blog/linkedin-larpmaxxing/
16•BurnerBurner•59m ago•11 comments

PSSA: A non-transformer language model written from scratch in Rust

https://github.com/Sparticle62ops/pssa
39•sparticle62•1h ago•11 comments

Dots: Always-on agents

https://openai.com/index/introducing-dots/
517•alvis•12h ago•392 comments

U.S. postal inspectors shut down website selling counterfeit postage labels

https://postalemployeenetwork.com/news/2026/09/26/u-s-postal-inspectors-shut-down-website-selling...
199•ilamont•9h ago•118 comments

Vermont replacing power plants with home batteries

https://www.bbc.com/future/article/20260928-a-virtual-power-plant-hidden-in-vermont-homes-is-keep...
134•devonnull•11h ago•113 comments

Responsible Release of AI-Generated Mathematics

https://agmai.org/general-sep29/
14•aureianimus•2h ago•2 comments

NASA asked several former SR-71A staffers to help secret restart

https://aviationweek.com/defense/aircraft-propulsion/nasa-asked-several-former-sr-71a-staffers-he...
94•ilamont•19h ago•93 comments

America.gov

https://america.gov/
475•plesiv•15h ago•378 comments

Show HN: Real-time Solar System with 526k asteroids and all tracked satellites

https://space.bl2.net/
172•wanick•10h ago•39 comments

GPT 6.1 Sol: Near-Astra intelligence for a fifth of the price

https://openai.com/index/introducing-gpt-6-1-sol/
848•crorella•12h ago•774 comments

How Delhi cut electricity loss from 50 to 5 percent

https://spectrum.ieee.org/delhi-electricity-loss
474•rbanffy•16h ago•274 comments

PS5 Relapse Exploit

https://github.com/ntfargo/Relapse-Exploit
267•therepanic•13h ago•149 comments

Language models for text classification: From bag-of-words to Jev

https://magazine.sebastianraschka.com/p/classifier-history-and-jev
65•Anon84•18h ago•2 comments

Backblaze drive stats for Q2 2026

https://www.backblaze.com/blog/backblaze-drive-stats-for-q2-2026/
129•HieronymusBosch•15h ago•30 comments

Needed 1+1, built a functional programming language

https://hereticpleb.vercel.app/blog/needed-one-plus-one/
60•birdculture•13h ago•16 comments

Phyllotaxis: An audio-reactive LED display

https://jagi.studio/posts/phyllotaxis/
271•evakhoury•1d ago•45 comments

When oil prices spike, where does the money go?

https://theconversation.com/when-oil-prices-spike-where-does-the-money-go-280763
52•thelastgallon•1d ago•46 comments

We’re forgetting what darkness feels like

https://www.theguardian.com/environment/2026/sep/29/night-sky-darkness-city-regulation
111•pseudolus•10h ago•66 comments

NAND-16: a computer built from 277,248 NAND gates

https://somethingbig.ai/computer
119•rossant•2d ago•68 comments

Tesla takes on $30B in credit as it approaches unprofitability

https://electrek.co/2026/09/29/tesla-takes-on-30-billion-in-credit-as-it-approaches-unprofitability/
9•ciconia•41m ago•0 comments

RSS Feeds for Last.fm

https://lfm.xiffy.nl/
12•Baljhin•2h ago•3 comments

Testing WebGPU data layouts with Facet

https://www.mattkeeter.com/blog/2026-08-23-wgpu-facet/
3•luu•1d ago•0 comments

Ask HN: What are you reading?

202•dan-bailey•15h ago•457 comments

A Staff Engineer's Guide to Inventing Work

https://sujithjay.com/inventing-work
228•amortize•1d ago•45 comments

Deser: Rethinking Rust Serialization

https://lucumr.pocoo.org/2026/9/29/deser/
49•tosh•7h ago•6 comments

Show HN: A working 3D model of an Enigma machine

https://enigma.design
51•primitivesuave•12h ago•18 comments

Ballmer Peak

https://en.wikipedia.org/wiki/Ballmer_Peak
23•thunderbong•2h ago•0 comments

Show HN: NSL – WSL for Linux

https://frostyard.github.io/nsl/
105•bketelsen•14h ago•73 comments

Strange Parodies of Atari 2600 Video Game Box Cover Art (2008)

https://mightygodking.com/2008/04/21/fun-from-yesterday/
24•peter_d_sherman•3h ago•17 comments