frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

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.

OpenBSD 7.9 Released

https://www.openbsd.org/79.html
97•bradley_taunt•1h ago•28 comments

New accessibility features powered by Apple Intelligence

https://www.apple.com/newsroom/2026/05/apple-unveils-new-accessibility-features-and-updates-with-...
197•interpol_p•2h ago•80 comments

Gaussian Splat of a Strawberry

https://superspl.at/scene/84df8849
239•danybittel•3h ago•95 comments

Show HN: I made a 3D pose maker for artists

https://setpose.com/
12•augustvdv•18m ago•2 comments

I Found Ultra-Pure Quantum Crystals in an Abandoned Mine in the Atacama Desert

https://medium.com/@breid.at/ultra-pure-quantum-crystals-from-an-abandoned-mine-in-a-mysterious-d...
155•vi_sextus_vi•2d ago•40 comments

Hanoi's humble beer glass and the memory of a nation

https://sundaylongread.com/2026/05/15/hanois-humble-beer-glass-and-the-memory-of-a-nation/
11•NaOH•20h ago•0 comments

Nim-Presto – REST API Framework for Nim Language

https://github.com/status-im/nim-presto
30•TheWiggles•2d ago•3 comments

Polypad

https://polypad.amplify.com/
143•ivank•2d ago•13 comments

An Apple (II) for Teacher

https://technicshistory.com/2026/05/19/an-apple-ii-for-teacher/
13•cfmcdonald•13h ago•1 comments

Mini Shai-Hulud Strikes Again: 314 npm Packages Compromised

https://safedep.io/mini-shai-hulud-strikes-again-314-npm-packages-compromised/
208•theanonymousone•9h ago•126 comments

Peter Neumann has died

https://www.tuhs.org/pipermail/tuhs/2026-May/033748.html
221•pabs3•11h ago•19 comments

Photo GIMP – A Patch for GIMP 3 for Photoshop Users

https://github.com/Diolinux/PhotoGIMP
119•SockThief•2d ago•86 comments

Colonization of Venus

https://en.wikipedia.org/wiki/Colonization_of_Venus
50•simonebrunozzi•1h ago•23 comments

Click (2016)

https://clickclickclick.click/
336•andrewzeno•15h ago•84 comments

Kv4p HT – A homebrew 1W radio (VHF or UHF) that plugs into an Android phone

https://www.kv4p.com/
121•krupan•2d ago•46 comments

Cursor Introduces Composer 2.5

https://cursor.com/blog/composer-2-5
208•asar•21h ago•160 comments

Anthropic acquires Stainless

https://www.anthropic.com/news/anthropic-acquires-stainless
490•tomeraberbach•21h ago•350 comments

Intro to TLA+ for the LLM Era: Prompt Your Way to Victory

https://emptysqua.re/blog/intro-to-tla-plus-for-the-llm-era/
3•zdw•1d ago•0 comments

Energy return in running shoes explained (2025)

https://runrepeat.com/guides/energy-return-in-running-shoes
39•jstrieb•1d ago•38 comments

The lasting influence of Netscape Time

https://thehistoryoftheweb.com/the-lasting-influence-of-netscape-time/
71•zdw•2d ago•14 comments

PyTorch Landscape

https://pytorch.landscape2.io
64•salamo•9h ago•17 comments

1024000^2 Blocks, 2B2T Minecraft Server World Download Project, and Discoveries

https://github.com/2b2tplace/1m_release
162•exploraz•1d ago•101 comments

The last six months in LLMs in five minutes

https://simonwillison.net/2026/May/19/5-minute-llms/
567•yakkomajuri•12h ago•465 comments

We let AIs run radio stations

https://andonlabs.com/blog/andon-fm
311•lukaspetersson•20h ago•231 comments

Regex Chess: A 2-ply minimax chess engine in 84,688 regular expressions

https://nicholas.carlini.com/writing/2025/regex-chess.html
157•surprisetalk•4d ago•40 comments

CISA Admin Leaked AWS GovCloud Keys on GitHub

https://krebsonsecurity.com/2026/05/cisa-admin-leaked-aws-govcloud-keys-on-github/
35•LelouBil•6h ago•0 comments

Show HN: Number Gacha, a gacha game distilled to its essence

https://isabisabel.com/gacha/
198•babel16•5d ago•96 comments

Make ZIP files smaller with ZIP Shrinker

https://evanhahn.com/make-zip-files-smaller-with-zip-shrinker/
53•zdw•2d ago•36 comments

Hyperpolyglot Lisp: Common Lisp, Racket, Clojure, Emacs Lisp

https://hyperpolyglot.org/lisp
172•veqq•18h ago•42 comments

Show HN: Hsrs – Type-Safe Haskell Bindings Generator for Rust

https://github.com/harmont-dev/hsrs
45•suis_siva•10h ago•3 comments