frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Make your first edit to OpenStreetMap

https://high5apps.github.io/josm-plugin-website-wizard/
306•juliantigler•8h ago•75 comments

Real-SWE: Benchmarking AI models on private, real-world, enterprise codebases

https://withspecific.com/benchmarks/real-swe
92•theanonymousone•4h ago•57 comments

Nvidia is the central bank of AI

https://www.economist.com/interactive/briefing/2026/09/03/nvidia-is-the-central-bank-of-ai
378•tolugenius•9h ago•260 comments

Apple iPod Engraver (2019)

https://dunstanorchard.com/apple-ipod-engraver/
105•NaOH•3d ago•18 comments

Getting 50 GB/S Back from the Apple Neural Engine

https://eiln.github.io/posts/ane-dma.html
59•eiln•3d ago•11 comments

Stabilizing Rust's Never Type

https://lwn.net/SubscriberLink/1091015/d9e48318ed242b41/
123•cjd8•3d ago•26 comments

LG denies TV spying claims, says tracking and snooping concerns 'not true'

https://www.tomshardware.com/tech-industry/big-tech/lg-strongly-denies-tv-security-claims-says-tr...
419•datakan•2d ago•346 comments

IKEA made a mod for Skyrim [video]

https://www.youtube.com/watch?v=iZODN0QUgjI
555•kegenaar•2d ago•147 comments

We must pace the frontier

https://darioamodei.com/post/we-must-pace-the-frontier
525•apsec112•10h ago•733 comments

Will There Be a 7G?

https://arxiv.org/abs/2609.01877
81•Betelbuddy•7h ago•134 comments

I made a build visualizer to understand Bun's compile times

https://lalitm.com/post/buildprof/
89•lalitmaganti•10h ago•17 comments

Tree Calculus

https://olydis.medium.com/a-visual-introduction-to-tree-calculus-2f4a34ceffc2
6•MelonUsk•4d ago•1 comments

Microcode in Intel's 8087 floating-point chip: the scale instruction

https://www.righto.com/2026/09/8087-microcode-reverse-engineering-fscale.html
86•pwg•8h ago•24 comments

Linux Zoom client proactively reading everything written to X11 clipboard

https://hachyderm.io/@simontatham/117201594980991062
169•encyclopedism•5h ago•53 comments

LG Says We're Fake News [video]

https://www.youtube.com/watch?v=ToP9xfLDSME
142•HelloUsername•5h ago•47 comments

Retrospectively Reverse-Engineering Apple's Neural Engine

https://eiln.github.io/posts/ane.html
220•zdw•16h ago•31 comments

I fixed a tractor using John Deere's self-repair service. Farmers aren't sold

https://www.wired.com/story/i-fixed-a-tractor-john-deere-self-repair-service/
99•sbulaev•1d ago•105 comments

How Trail of Bits helps verify the integrity of Signal chats

https://blog.trailofbits.com/2026/08/11/how-trail-of-bits-helps-verify-the-integrity-of-your-sign...
50•dgroshev•13h ago•29 comments

Android NAT-T keepalive offload bypasses VPN lockdown

https://supuk.ch/papers/android-natt-keepalive-vpn-bypass
171•mhitza•1d ago•44 comments

A Mathematical Framework for Transformer Circuits (2021)

https://transformer-circuits.pub/2021/framework/index.html
80•Bluestein•10h ago•17 comments

Eating Fruit Skins

https://pgadey.ca/blog/eating-fruit-skins/
78•surprisetalk•3d ago•168 comments

Navier-Stokes Announcement

https://www.claymath.org/news/navier-stokes-announcement/
317•rvz•20h ago•253 comments

Killing with a car costs $1.6M, California requires drivers to carry $30K

https://maxmautner.com/2026/09/11/liability-coverage.html
41•mslate•2h ago•32 comments

Performance of WebAssembly Runtimes in 2026

https://00f.net/2026/06/23/webassembly-runtimes-2026/
87•fagnerbrack•3d ago•20 comments

A Design Space Exploration of Async/Await

https://cel.cs.brown.edu/blog/design-space-async-await/
422•wcrichton•3d ago•123 comments

The Magic Behind Cubacadabra

https://andrewarrow.dev/2026/moon/2/day/19/the-magic-behind-cubacadabra/
10•andrewfromx•2d ago•2 comments

λ Snap – An inviting programming language for kids and adults for CS study

https://snap.berkeley.edu/
176•dr_kiszonka•1d ago•112 comments

The worst spam emails: iLands AI agent hustle

https://tedium.co/2026/09/11/ilands-agents-email-spam-kaixin-tang/
101•ColinWright•13h ago•49 comments

Show HN: See Sounds on Your Webcam

https://soundmap.darebuild.com/
5•jimhi•2d ago•3 comments

LRU is harder to beat than the KV-cache papers suggest

https://github.com/gauravapiscean/agentic-kv-cache
96•gauravapiscean•2d ago•47 comments