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.

The Real Luxuries In Life

https://feld.com/archives/2026/09/the-real-luxuries-in-life/
232•tosh•3h ago•89 comments

Finite time blowup for an averaged three-dimensional Navier-Stokes equation

https://terrytao.wordpress.com/2014/02/04/finite-time-blowup-for-an-averaged-three-dimensional-na...
19•gmays•30m ago•3 comments

Private German rocket makes history, reaches orbit from European soil

https://www.space.com/space-exploration/launches-spacecraft/isar-aerospace-second-launch-norway-a...
60•bookmtn•24m ago•7 comments

Learn Programming with OCaml

https://usr.lmf.cnrs.fr/lpo/
97•elvis70•4h ago•38 comments

The "$60 Gaming PC" – AMD BC-250 (2025)

https://devquasar.com/hardware/the-60-gaming-pc-amd-bc-250/
215•networked•7h ago•71 comments

Visualizing Rust's Vtables: How dyn Trait Works In Memory

https://sofiabelen.github.io/projects/visualizing-rusts-vtables-how-dyn-trait-works-in-memory/
80•torutofu•7h ago•6 comments

Discovery of a new OpenAI agent message board

https://collusion.wiki/
2025•moultano•1d ago•1488 comments

Isar Aerospace launch into orbit [video]

https://www.youtube.com/watch?v=Ss1DUqLjecc
24•stefan_•30m ago•2 comments

Balrogg: Demonically compacting (up to 15%) lossless Vorbis/Opus recompressor

https://github.com/iczelia/balrogg
20•palaiologos•2d ago•1 comments

Actively exploited sandbox RCE in all Chromium versions

https://nvd.nist.gov/vuln/detail/cve-2026-85046
720•negura•23h ago•413 comments

Nitter has more working instances than before the takedowns

https://codeberg.org/mv12star/shitter/wiki/Instances
566•Cider9986•20h ago•249 comments

Space industry lacks workers needed to rebuild satellites lost in war: report

https://www.defensenews.com/industry/techwatch/2026/09/04/space-industry-lacks-workers-needed-to-...
17•billybuckwheat•41m ago•8 comments

Steffen's Polyhedron

https://www.gregegan.net/SCIENCE/Steffen/Steffen.html
36•pavel_lishin•2d ago•2 comments

Terpstra Keyboard

http://terpstrakeyboard.com/
100•cl3misch•10h ago•44 comments

Formalizing Fermat's Last Theorem

https://www.anthropic.com/research/formalizing-fermats-last-theorem
726•jlebar•1d ago•463 comments

Stopping the Unstoppable: When an unstoppable force meets a dashpot snubber

https://practical.engineering/blog/2026/9/1/stopping-the-unstoppable
30•crescit_eundo•4d ago•2 comments

Delidded Intel I9-14900KS CT Scan

https://www.lttlabs.com/articles/2026/09/02/delidded-intel-i9-14900ks
20•willx86•3d ago•0 comments

Wikimedia Foundation Workers Overwhelmingly Vote to Form Union with CWA

https://wikiworkersunited.org/announcements/2026-09-04-us-wikimedia-foundation-workers-overwhelmi...
215•robin_reala•4h ago•91 comments

A bizarre Commodore 64 peripheral, a mime, and some pretty bad ads

https://buttondown.com/suchbadtechads/archive/spartan-and-the-mime/
60•rfarley04•8h ago•3 comments

Singapore subway (mrt) information display types

https://www.sgtrains.com/technology-infosys.html
34•gregorvand•3d ago•5 comments

Statichost.eu – European static site hosting

https://www.statichost.eu/
422•p4bl0•1d ago•191 comments

Can AI design circuit boards yet?

https://eebench.org/blog/can-ai-design-circuit-boards-yet/
345•iopapa•1d ago•202 comments

A Million Falcons Went Missing. Here’s How They Were Found

https://www.nationalgeographic.com/animals/article/falcons-migration-angola-falcopolis
57•bryanrasmussen•3d ago•25 comments

AI handles incidents, engineers lose touch with their systems

https://www.sylvainkalache.com/blog/ai-handles-incidents-engineers-lose-touch-with-their-systems
342•sylvainkalache•13h ago•296 comments

.gitignore Everything by Default

https://packagemain.tech/p/gitignore-everything-by-default
114•der_gopher•7h ago•132 comments

Git hosting that never leaves Europe

https://pushin.eu
285•sevenseacat•14h ago•141 comments

Show HN: Open-Source eInk Bike Computer

https://opentrailpaper.com
377•stingrae•1d ago•117 comments

Write Software in Latin (2025) [video]

https://www.youtube.com/watch?v=fGZpaqMha0o
32•akkartik•2d ago•13 comments

Shutting down our public encrypted DNS

https://mullvad.net/en/blog/shutting-down-our-public-encrypted-dns-servers-and-sponsoring-quad9-i...
429•mywacaday•1d ago•213 comments

Ask HN: Resources to get good at soldering?

218•tosmatos•3d ago•139 comments