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•10mo 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•10mo 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•10mo 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.

LittleSnitch for Linux

https://obdev.at/products/littlesnitch-linux/index.html
246•pluc•3h ago•88 comments

I ported Mac OS X to the Nintendo Wii

https://bryankeller.github.io/2026/04/08/porting-mac-os-x-nintendo-wii.html
1325•blkhp19•11h ago•222 comments

USB for Software Developers: An introduction to writing userspace USB drivers

https://werwolv.net/posts/usb_for_sw_devs/
209•WerWolv•8h ago•29 comments

Understanding the Kalman filter with a simple radar example

https://kalmanfilter.net
255•alex_be•10h ago•34 comments

The Importance of Being Idle

https://theamericanscholar.org/the-importance-of-being-idle/
21•Caiero•2d ago•3 comments

They're made out of meat (1991)

http://www.terrybisson.com/theyre-made-out-of-meat-2/
430•surprisetalk•16h ago•129 comments

Six (and a half) intuitions for KL divergence

https://www.perfectlynormal.co.uk/blog-kl-divergence
22•jxmorris12•1d ago•0 comments

Muse Spark: Scaling towards personal superintelligence

https://ai.meta.com/blog/introducing-muse-spark-msl/?_fb_noscript=1
288•chabons•11h ago•304 comments

ML promises to be profoundly weird

https://aphyr.com/posts/411-the-future-of-everything-is-lies-i-guess
410•pabs3•14h ago•438 comments

Git commands I run before reading any code

https://piechowski.io/post/git-commands-before-reading-code/
1853•grepsedawk•18h ago•391 comments

Expanding Swift's IDE Support

https://swift.org/blog/expanding-swift-ide-support/
87•frizlab•8h ago•39 comments

Who is Satoshi Nakamoto? My quest to unmask Bitcoin's creator

https://www.nytimes.com/2026/04/08/business/bitcoin-satoshi-nakamoto-identity-adam-back.html
338•jfirebaugh•22h ago•274 comments

MegaTrain: Full Precision Training of 100B+ Parameter LLMs on a Single GPU

https://arxiv.org/abs/2604.05091
265•chrsw•15h ago•49 comments

I imported the full Linux kernel git history into pgit

https://oseifert.ch/blog/linux-kernel-pgit
79•ImGajeed76•3d ago•11 comments

Understanding Traceroute

https://tech.stonecharioteer.com/posts/2026/traceroute/
98•stonecharioteer•2d ago•13 comments

What does it mean to “write like you talk”?

https://arjunpanickssery.substack.com/p/what-does-it-mean-to-write-like-you
48•surprisetalk•2d ago•49 comments

John Deere to pay $99M in right-to-repair settlement

https://www.thedrive.com/news/john-deere-to-pay-99-million-in-monumental-right-to-repair-settlement
207•CharlesW•6h ago•56 comments

Newly created Polymarket accounts win big on well-timed Iran ceasefire bets

https://www.theguardian.com/business/2026/apr/08/polymarket-trump-us-iran-ceasefire
48•mitchbob•2h ago•20 comments

Ask HN: Any interesting niche hobbies?

280•e-topy•3d ago•416 comments

Show HN: Is Hormuz open yet?

https://www.ishormuzopenyet.com/
290•anonfunction•5h ago•129 comments

Show HN: A (marginally) useful x86-64 ELF executable in 301 bytes

https://github.com/meribold/btry
4•meribold•2d ago•1 comments

We moved Railway's frontend off Next.js. Builds went from 10+ mins to under 2

https://blog.railway.com/p/moving-railways-frontend-off-nextjs
188•bundie•21h ago•174 comments

Show HN: Orange Juice – Small UX improvements that make HN easier to read

http://oj-hn.com/
94•latchkey•9h ago•121 comments

I've been waiting over a month for Anthropic to respond to my billing issue

https://nickvecchioni.github.io/thoughts/2026/04/08/anthropic-support-doesnt-exist/
299•nickvec•9h ago•145 comments

US cities are axing Flock Safety surveillance technology

https://www.cnet.com/home/security/when-flock-comes-to-town-why-cities-are-axing-the-controversia...
649•giuliomagnifico•15h ago•385 comments

Audio Reactive LED Strips Are Diabolically Hard

https://scottlawsonbc.com/post/audio-led
204•surprisetalk•1d ago•57 comments

Teardown of unreleased LG Rollable shows why rollable phones aren't a thing

https://arstechnica.com/gadgets/2026/04/teardown-of-unreleased-lg-rollable-shows-why-rollable-pho...
85•DamnInteresting•1d ago•37 comments

Show HN: Skrun – Deploy any agent skill as an API

https://github.com/skrun-dev/skrun
48•frizull•14h ago•9 comments

Microsoft terminates VeraCrypt account, halting Windows updates

https://www.404media.co/microsoft-abruptly-terminates-veracrypt-account-halting-windows-updates/
490•donohoe•12h ago•186 comments

Veracrypt project update

https://sourceforge.net/p/veracrypt/discussion/general/thread/9620d7a4b3/
1162•super256•20h ago•428 comments