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.

Google DeepMind Releases AlphaGenome Atlas

https://blog.google/innovation-and-ai/models-and-research/google-deepmind/alphagenome-atlas/
456•utiiiD•7h ago•108 comments

Large Language Models Develop Novel Social Biases Through Adaptive Exploration

https://openreview.net/challenge?redirect=%2Fforum%3Fid%3Dpc7fqaOcAH
26•paimapi•57m ago•4 comments

Navier-Stokes – Tristan Buckmaster [pdf]

https://cims.nyu.edu/~tristanb/statement.pdf
1019•procedurecall•17h ago•445 comments

Kimi K3 (2.8T) at 1 token/s on a MacBook Pro, streamed from four SSDs

https://github.com/argonautlabsai/deltafin
180•Argonautlabs•2h ago•77 comments

On the Navier–Stokes Millennium Prize Problem

https://openai.com/index/navier-stokes-solution/
997•tedsanders•5h ago•808 comments

DaVinci Resolve 21.1

https://www.blackmagicdesign.com/media/release/20260908-03
325•tosh•9h ago•143 comments

Benchmarking Qwen3.8 27B quantizations: 4-bit holds up, 1-bit collapses

https://quesma.com/blog/qwen38-27b-quantizations-benchmarked/
195•stared•7h ago•97 comments

Mercury 2.5

https://www.inceptionlabs.ai/blog/introducing-mercury-2-5
85•Topfi•2h ago•9 comments

Animation in Bevy: The Big Picture

https://glocq.com/en/blog/20260827/
28•ibobev•2h ago•1 comments

How to Build a Printer

https://nishantjosh.dev/blogs/how-to-build-a-fking-printer/
11•cat-whisperer•1h ago•1 comments

I-have-ADHD: A skill to stop coding agents from burying the answer

https://github.com/ayghri/i-have-adhd
262•domhudson•8h ago•204 comments

Muse: Meta's personal AI agent, features and capabilities

https://ai.meta.com/muse/
202•yks•3h ago•195 comments

Implementation of GCC's Nested Functions (vs. C++ Lambdas)

https://uecker.codeberg.page/2026-09-05.html
45•uecker•3d ago•5 comments

Show HN: LLM Attention Visualization

https://ishamf.dev/p/llm-attention-visualizer/
99•ifz•5h ago•19 comments

Tracing np.add, all the way down

https://blog.veitheller.de/numpy.html
22•luu•4d ago•1 comments

Replacing a Rust Enum with a 64-Bit Word Made My Interpreter 17% Faster

https://pointersgonewild.com/2026-08-25-replacing-a-rust-enum-with-a-64-bit-word/
64•metrofun•3d ago•27 comments

The Helicopter with Radioactive Blades

https://hackaday.com/2026/09/07/the-helicopter-with-radioactive-blades/
138•zdw•1d ago•34 comments

Show HN: Copperhead – Hardware as Fast as Software

https://copperhead.sh/
191•animeshchouhan•9h ago•76 comments

The 92-Year-Old Mathematician and the Teenage Apprentice

https://www.nytimes.com/2026/09/06/science/92-year-old-mathematician-apprentice.html
118•robinhouston•2d ago•10 comments

C*: Unifying Programming and Verification in C

https://arxiv.org/abs/2504.02246
65•rramadass•6h ago•38 comments

The two Christian saints who are the Buddha

https://signoregalilei.com/2026/08/30/the-two-christian-saints-who-are-secretly-the-buddha/
195•surprisetalk•8h ago•136 comments

Reverse Engineering an ASIC

https://kjartanvandriel.github.io/asic/
7•burekqueen•1d ago•0 comments

Trey Parker and Matt Stone Are Changing the Name of South Park to South America

https://twitter.com/SouthPark/status/2097364141237539116
117•HelloUsername•2h ago•56 comments

Connecting the Machines

https://herdr.dev/blog/connecting-the-machines/
68•collinmanderson•6h ago•24 comments

ZX Spectrum: Experimenting with 1-Bit Sound

https://bumbershootsoft.wordpress.com/2026/09/05/zx-spectrum-experimenting-with-1-bit-sound/
89•ibobev•7h ago•26 comments

AlphaGenome Atlas predictive map of every DNA letter change in the human genome

https://deepmind.google/blog/alphagenome-atlas-a-predictive-map-of-every-possible-dna-letter-chan...
73•fady0•8h ago•9 comments

Function Arguments Are Not Function Colors

https://jerf.org/iri/post/2026/func_args_are_not_colors/
25•ingve•3h ago•9 comments

FreeBSD 14.5-Release

https://www.freebsd.org/releases/14.5R/announce/
104•joshcsimmons•10h ago•18 comments

Getting your hands dirty is good for you

https://www.bbc.com/future/article/20260904-how-getting-your-hands-dirty-boosts-your-health-withi...
205•HatchedLake721•12h ago•172 comments

Paramount Caught Using 'Astroturf' Group to Drum Up Fake Support for Merger

https://www.techdirt.com/2026/09/08/paramount-caught-using-astroturf-group-to-drum-up-fake-suppor...
313•hn_acker•8h ago•105 comments