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.

Google broke its promise to me – now ICE has my data

https://www.eff.org/deeplinks/2026/04/google-broke-its-promise-me-now-ice-has-my-data
694•Brajeshwar•3h ago•279 comments

God sleeps in the minerals

https://wchambliss.wordpress.com/2026/03/03/god-sleeps-in-the-minerals/
389•speckx•7h ago•86 comments

Live Nation illegally monopolized ticketing market, jury finds

https://www.bloomberg.com/news/articles/2026-04-15/live-nation-illegally-monopolized-ticketing-ma...
152•Alex_Bond•1h ago•40 comments

Cal.com is going closed source

https://cal.com/blog/cal-com-goes-closed-source-why
116•Benjamin_Dobell•5h ago•109 comments

PiCore - Raspberry Pi Port of Tiny Core Linux

http://tinycorelinux.net/5.x/armv6/releases/README
15•gregsadetsky•1h ago•1 comments

Fix monitor that goes black, off or blinks due to static electricity in chair

https://aalonso.dev/blog/2023/how-to-fix-monitor-that-goes-black-off-due-to-static-electricity-in...
80•cyclopeanutopia•3d ago•39 comments

Cybersecurity looks like proof of work now

https://www.dbreunig.com/2026/04/14/cybersecurity-is-proof-of-work-now.html
13•dbreunig•1d ago•0 comments

Want to write a compiler? Just read these two papers (2008)

https://prog21.dadgum.com/30.html
410•downbad_•11h ago•125 comments

Golden eagles' return to English skies

https://www.bbc.co.uk/news/articles/cje4zlxqkqdo
19•techterrier•3d ago•11 comments

Good Sleep, Good Learning (2012)

https://super-memory.com/articles/sleep.htm
318•downbad_•11h ago•155 comments

Do you even need a database?

https://www.dbpro.app/blog/do-you-even-need-a-database
148•upmostly•8h ago•210 comments

Farmer Arrested for Speaking Too Long at Datacenter Town Hall Vows to Fight

https://www.404media.co/farmer-arrested-for-speaking-too-long-at-datacenter-town-hall-vows-to-fight/
55•sudonanohome•1h ago•16 comments

Anna's Archive loses $322M Spotify piracy case without a fight

https://torrentfreak.com/annas-archive-loses-322-million-spotify-piracy-case-without-a-fight/
244•askl•12h ago•249 comments

Adaptional (YC S25) Is Hiring Founding AI Engineers

https://www.ycombinator.com/companies/adaptional/jobs/k7W6ge9-founding-engineer
1•acesohc•3h ago

Show HN: GNU Grep as a PHP Extension

https://github.com/hparadiz/ext-gnu-grep
24•hparadiz•5d ago•4 comments

Kalshi CEO expects US DOJ to prosecute insider trading cases

https://www.semafor.com/article/04/15/2026/kalshi-ceo-tarek-mansour-expects-us-doj-to-prosecute-i...
79•thm•2h ago•78 comments

Why are Flock employees watching our children?

https://substack.com/home/post/p-193593234
117•enaaem•1h ago•24 comments

Forcing an inversion of control on the SaaS stack

https://www.100x.bot/a/client-side-injection-inversion-of-control-saas
57•shardullavekar•5d ago•38 comments

Show HN: Jeeves – TUI for browsing and resuming AI agent sessions

https://github.com/robinovitch61/jeeves
9•lrobinovitch•1h ago•2 comments

Show HN: I rebuilt a 2000s browser strategy game on Cloudflare's edge

https://kampfinsel.com/
11•parzivalt•4d ago•5 comments

Show HN: Libretto – Making AI browser automations deterministic

https://github.com/saffron-health/libretto
57•muchael•4h ago•17 comments

How do Wake-On-LAN works

https://blog.xaner.dev/post/wake-on-lan/
70•swq115•4d ago•24 comments

Users lose $9.5M to fake Ledger wallet app on the Apple App Store

https://www.web3isgoinggreat.com/?id=fake-ledger-app
52•CharlesW•2h ago•22 comments

Costasiella kuroshimae – Solar Powered animals, that do indirect photosynthesis

https://en.wikipedia.org/wiki/Costasiella_kuroshimae
128•vinnyglennon•3d ago•50 comments

Wacli – WhatsApp CLI

https://github.com/steipete/wacli
216•dinakars777•13h ago•144 comments

The Future of Everything Is Lies, I Guess: New Jobs

https://aphyr.com/posts/419-the-future-of-everything-is-lies-i-guess-new-jobs
223•aphyr•7h ago•147 comments

Gemini Robotics-ER 1.6

https://deepmind.google/blog/gemini-robotics-er-1-6/
184•markerbrod•6h ago•58 comments

AI-assisted cognition endangers human development?

https://heidenstedt.org/posts/2026/ai-assisted-cognition-endangers-human-development/
205•i5heu•2h ago•131 comments

Pretty Fish: A better mermaid diagram editor

https://pretty.fish/
137•pastelsky•6d ago•23 comments

Metro stop is Ancient Rome's new attraction

https://www.bbc.com/travel/article/20260408-a-150-metro-ticket-to-ancient-rome
97•Stevvo•6d ago•26 comments