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.

Vercel April 2026 security incident

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

A Brief History of Fish Sauce

https://www.legalnomads.com/fish-sauce/
140•vinhnx•20h ago•58 comments

Stop trying to engineer your way out of listening to people

https://ashley.rolfmore.com/stop-trying-to-engineer-your-way-out-of-listening-to-people/
114•walterbell•9h ago•27 comments

The Bromine Chokepoint

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

Sudo for Windows

https://github.com/microsoft/sudo
51•luispa•5h ago•24 comments

Claude Token Counter, now with model comparisons

https://simonwillison.net/2026/Apr/20/claude-token-counts/
38•twapi•4h ago•9 comments

Monumental ship burial beneath ancient Norwegian mound predates the Viking Age

https://phys.org/news/2026-04-monumental-ship-burial-beneath-ancient.html
14•pseudolus•2d ago•1 comments

Show HN: Run TRELLIS.2 Image-to-3D generation natively on Apple Silicon

https://github.com/shivampkumar/trellis-mac
124•shivampkumar•5h ago•21 comments

Turtle WoW classic server announces shutdown after Blizzard wins injunction

https://www.pcgamer.com/games/world-of-warcraft/turtle-wow-classic-server-announces-shutdown-afte...
178•Brajeshwar•13h ago•151 comments

Mechanical Keyboard Sounds – A listening Museum

https://sheets.works/data-viz/keyboard-sounds
71•akashwadhwani35•4d 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/
261•pretext•18h ago•152 comments

Swiss AI Initiative (2023)

https://www.swiss-ai.org
38•doener•6h ago•13 comments

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

https://mxmap.ch/
106•doener•6h ago•33 comments

Prove you are a robot: CAPTCHAs for agents

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

The RAM shortage could last years

https://www.theverge.com/ai-artificial-intelligence/914672/the-ram-shortage-could-last-years
244•omer_k•22h ago•273 comments

Scientific datasets are riddled with copy-paste errors

https://www.sciencedetective.org/scientific-datasets-are-riddled-with-copy-paste-errors/
65•jruohonen•10h ago•9 comments

Show HN: A lightweight way to make agents talk without paying for API usage

https://juanpabloaj.com/2026/04/16/a-lightweight-way-to-make-agents-talk-without-paying-for-api-u...
20•juanpabloaj•5h ago•5 comments

A cache-friendly IPv6 LPM with AVX-512 (linearized B+-tree, real BGP benchmarks)

https://github.com/esutcu/planb-lpm
8•debugga•2h ago•1 comments

A Common MVP Evolution: Service to System Integration to Product (2017)

https://www.skmurphy.com/blog/2017/08/07/a-common-evolution-service-to-system-integration-to-prod...
8•skmurphy•2d ago•2 comments

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

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

The seven programming ur-languages (2022)

https://madhadron.com/programming/seven_ur_languages.html
319•helloplanets•21h ago•120 comments

Recovering Windows Live Writer Files

https://benovermyer.com/blog/2026/04/recovering-windows-live-writer-files/
18•bovermyer•5d ago•6 comments

Six Levels of Dark Mode (2024)

https://cssence.com/2024/six-levels-of-dark-mode/
64•Akcium•10h ago•28 comments

Interesting Map Geometry and Mathematics

https://www.markrjohnsongames.com/2026/04/11/ultima-ratio-regum-0-11-update-57-interesting-map-ge...
18•Hooke•1d ago•0 comments

Show HN: A working reference implementation of context engineering

https://github.com/outcomeops/context-engineering
39•linsys•2d ago•11 comments

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

https://github.com/navid-m/chip8emu
59•pizza_man•10h ago•14 comments

Nanopass Framework: Clean Compiler Creation Language

https://nanopass.org/
126•NordStreamYacht•4d ago•29 comments

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

https://www.vincentgregoire.com/faceoff/
109•vcf•11h ago•35 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
169•Eridanus2•20h ago•69 comments

PopOS Linux: Creating a Bootable Backup USB With Encryption

https://hajo.me/blog/2026/02/16/popos-linux-creating-bootable-backup-USB-with-encryption/
13•fxtentacle•2d ago•1 comments