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•12mo 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 reCAPTCHA for de-googled Android users

https://reclaimthenet.org/google-broke-recaptcha-for-de-googled-android-users
666•anonymousiam•7h ago•236 comments

OpenAI's WebRTC problem

https://moq.dev/blog/webrtc-is-the-problem/
137•atgctg•1d ago•31 comments

People Hate AI Art

https://mccue.dev/pages/5-8-26-ai-art
49•3dedb728-3f77•2h ago•24 comments

The React2Shell Story

https://lachlan.nz/blog/the-react2shell-story/
56•mufeedvh•10h ago•5 comments

AI is breaking two vulnerability cultures

https://www.jefftk.com/p/ai-is-breaking-two-vulnerability-cultures
257•speckx•8h ago•110 comments

Wi is Fi: Understanding Wi-Fi 4/5/6/6E/7/8 (802.11 n/AC/ax/be/bn)

https://www.wiisfi.com/
100•homebrewer•2d ago•40 comments

AWS North Virginia data center outage – recovery to take hours

https://www.cnbc.com/2026/05/08/aws-outage-data-center-fanduel-coinbase.html
145•christhecaribou•23h ago•92 comments

Cartoon Network Flash Games

https://www.webdesignmuseum.org/flash-game-exhibitions/cartoon-network-flash-games
289•willmeyers•10h ago•98 comments

David Attenborough's 100th Birthday

https://www.bbc.com/news/articles/cp3pww9g0p5o
464•defrost•14h ago•94 comments

Light without electricity? Glowing algae could make it possible

https://www.colorado.edu/today/2026/05/06/light-without-electricity-glowing-algae-could-make-it-p...
24•geox•2d ago•8 comments

You gave me a u32. I gave you root. (io_uring ZCRX freelist LPE)

https://ze3tar.github.io/post-zcrx.html
145•MrBruh•7h ago•88 comments

Bitter Lessons from the ISSpresso

https://mceglowski.substack.com/p/bitter-lessons-from-the-isspresso
18•zdw•2d ago•3 comments

Can LLMs model real-world systems in TLA+?

https://www.sigops.org/2026/can-llms-model-real-world-systems-in-tla/
34•mad•10h ago•3 comments

When is your birthday? The math behind hash collisions

https://0xkrt26.github.io/math_behind_security/2026/05/08/birthday-problem.html
21•denismenace•6h ago•2 comments

Serving a website on a Raspberry Pi Zero running in RAM

https://btxx.org/posts/memory/
195•xngbuilds•11h ago•82 comments

An Introduction to Meshtastic

https://meshtastic.org/docs/introduction/
376•ColinWright•15h ago•151 comments

Mux (YC W16) Is Hiring

https://www.mux.com/jobs
1•mmcclure•5h ago

Teaching Claude Why

https://www.anthropic.com/research/teaching-claude-why
99•pretext•8h ago•30 comments

Looking at the data behind prediction markets

https://asteriskmag.com/issues/14/are-prediction-markets-good-for-anything
59•kqr•1d ago•29 comments

Meta Shuts Down End-to-End Encryption for Instagram Messaging

https://www.pcmag.com/news/meta-shuts-down-end-to-end-encryption-for-instagram-dms-messaging
163•tcp_handshaker•4h ago•114 comments

Rumors of my death are slightly exaggerated

1552•CliffStoll•2d ago•239 comments

Tesla Model Y Passes NHTSA's New 'Advanced Driver Assistance System' Tests

https://www.nhtsa.gov/press-releases/tesla-model-y-first-vehicle-pass-nhtsa-new-advanced-driver-a...
47•amanaplanacanal•3h ago•37 comments

Mojo 1.0 Beta

https://mojolang.org/
295•sbt567•23h ago•184 comments

Human typing habits and token counts

https://pankajpipada.com/posts/2026-05-08-human-habits-tokens/
11•ppipada•13h ago•2 comments

US Government releases first batch of UAP documents and videos

https://www.war.gov/UFO/
240•david-gpu•14h ago•365 comments

Non-determinism is an issue with patching CVEs

https://flox.dev/blog/achieving-rapid-cve-remediation-in-an-era-of-escalating-vulnerabilities/
38•mathewpregasen•5h ago•12 comments

Hosting a site on a Raspberry Pi

https://m4rt.nl/blog/hosting-on-a-pi
16•swiftdust•1d ago•3 comments

Poland is now among the 20 largest economies

https://apnews.com/article/poland-economy-growth-g20-gdp-26fe06e120398410f8d773ba5661e7aa
907•surprisetalk•14h ago•737 comments

How do I deal with memory leaks? (2022)

https://www.stroustrup.com/bs_faq2.html#memory-leaks
76•theanonymousone•9h ago•64 comments

PC Engine CPU

https://jsgroth.dev/blog/posts/pc-engine-cpu/
126•ibobev•12h ago•56 comments