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•11mo ago

Comments

LegionMammal978•11mo 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•11mo 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•11mo 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 Bromine Chokepoint

https://warontherocks.com/cogs-of-war/the-bromine-chokepoint-how-strife-in-the-middle-east-could-...
126•crescit_eundo•5h ago•58 comments

Vercel April 2026 security incident

https://www.bleepingcomputer.com/news/security/vercel-confirms-breach-as-hackers-claim-to-be-sell...
431•colesantiago•8h ago•275 comments

2,100 Swiss municipalities showing which provider handles their official email

https://mxmap.ch/
8•doener•17m ago•1 comments

Swiss authorities want to reduce dependency on Microsoft

https://www.swissinfo.ch/eng/swiss-ai/swiss-authorities-want-to-reduce-dependency-on-microsoft/91...
186•doener•2h ago•65 comments

Prove You Are a Robot: CAPTCHAs for Agents

https://browser-use.com/posts/prove-you-are-a-robot
27•lukasec•4d ago•17 comments

Show HN: Faceoff – A terminal UI for following NHL games

https://www.vincentgregoire.com/faceoff/
82•vcf•5h ago•29 comments

Changes in the system prompt between Claude Opus 4.6 and 4.7

https://simonwillison.net/2026/Apr/18/opus-system-prompt/
156•pretext•12h ago•95 comments

I wrote a CHIP-8 emulator in my own programming language

https://github.com/navid-m/chip8emu
33•pizza_man•3h ago•9 comments

Archive of BYTE magazine, starting with issue #1 in 1975

https://archive.org/details/byte-magazine-1975-09
514•DamnInteresting•2d ago•129 comments

The seven programming ur-languages (2022)

https://madhadron.com/programming/seven_ur_languages.html
262•helloplanets•15h ago•98 comments

Six Levels of Dark Mode

https://cssence.com/2024/six-levels-of-dark-mode/
20•Akcium•4h ago•5 comments

Game devs explain the tricks involved with letting you pause a game

https://kotaku.com/video-game-devs-explain-how-pausing-works-and-sometimes-it-gets-weird-2000686339
396•speckx•3d ago•220 comments

Nanopass Framework: Clean Compiler Creation Language

https://nanopass.org/
109•NordStreamYacht•4d ago•25 comments

The RAM shortage could last years

https://www.theverge.com/ai-artificial-intelligence/914672/the-ram-shortage-could-last-years
146•omer_k•15h ago•139 comments

A. J. Ayer – ‘What I Saw When I Was Dead’ (1988)

https://www.philosopher.eu/others-writings/a-j-ayer-what-i-saw-when-i-was-dead/
52•isomorphy•3h ago•61 comments

Notion leaks email addresses of all editors of any public page

https://twitter.com/weezerOSINT/status/2045849358462222720
300•Tiberium•7h ago•104 comments

SPEAKE(a)R: Turn Speakers to Microphones for Fun and Profit [pdf] (2017)

https://www.usenix.org/system/files/conference/woot17/woot17-paper-guri.pdf
154•Eridanus2•14h ago•66 comments

3D-Printing a Trombone

https://unnamed.website/posts/3d-printing-trombone/
9•surprisetalk•3d ago•0 comments

What are skiplists good for?

https://antithesis.com/blog/2026/skiptrees/
252•mfiguiere•2d ago•59 comments

Reverse Engineering ME2's USB with a Heat Gun and a Knife

https://github.com/coremaze/ME2-Writeup
46•Bawoosette•1d ago•7 comments

Blue Origin's rocket reuse achievement marred by upper stage failure

https://arstechnica.com/space/2026/04/errant-upper-stage-spoils-blue-origins-success-in-reusing-n...
46•rbanffy•3h ago•7 comments

KTaO3-Based Supercurrent Diode

https://pubs.acs.org/doi/10.1021/acs.nanolett.5c05590
24•PaulHoule•4d ago•2 comments

I learned Unity the wrong way

https://darkounity.com/blog/how-i-learned-unity-the-wrong-way
79•lelanthran•3d ago•33 comments

Reading Input from an USB RFID Card Reader

https://kevwe.com/blog/usb-rfid-reader
30•kevwedotse•2d ago•5 comments

Show HN: Shader Lab, like Photoshop but for shaders

https://eng.basement.studio/tools/shader-lab
130•ragojose•3d ago•38 comments

C++26: Reflection, Memory Safety, Contracts, and a New Async Model

https://www.infoq.com/news/2026/04/cpp-26-reflection-safety-async/
17•birdculture•2h ago•1 comments

Hot Wiring the Lisp Machine

https://scheatkode.com/blog/019d463d-38b3-7e63-80fd-6ed97bd8815e/hot-wiring-the-lisp-machine/
13•spudlyo•6h ago•0 comments

Eliza a Play by Tom Holloway

https://www.mtc.com.au/plays-and-tickets/whats-on/season-2026/eliza
10•abrax3141•2d ago•6 comments

4-bit floating point FP4

https://www.johndcook.com/blog/2026/04/17/fp4/
70•chmaynard•1d ago•47 comments

The world in which IPv6 was a good design (2017)

https://apenwarr.ca/log/20170810
204•signa11•20h ago•109 comments