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.

DeepSeek Harness

https://www.deepseek.com/en/harness/
128•Kuyawa•3h ago•39 comments

Pi 1.0

https://earendil.com/posts/pi-1-0/
1053•sergiotapia•10h ago•330 comments

How Singapore's government-run dating service works

https://www.singapore-samizdat.com/p/how-singapores-government-run-dating-service-firstdate-works
82•danielfoster•4h ago•37 comments

Shimano Bicycle Museum Review

https://inrng.com/2026/10/shimano-bicycle-museum/
15•pietroppeter•1h ago•0 comments

Clef: Open-weight decision models, and new RL fine-tuning platform

https://blog.cloudflare.com/clef-decision-models/
480•jasondavies•14h ago•171 comments

SvelteKit 3

https://svelte.dev/blog/sveltekit-3-is-here
208•sampsn•10h ago•68 comments

Several vulnerabilities have been discovered in the Linux kernel

https://lwn.net/Articles/1097401/
224•luispa•7h ago•148 comments

Automatic Transmission – a data-privacy study of connected vehicles

https://automatictransmission.khoury.northeastern.edu/index.html
161•rafaelc•10h ago•153 comments

Pi Durable

https://earendil.com/posts/pi-durable/
316•paulsmith•11h ago•38 comments

Ask HN: Who is hiring? (October 2026)

177•whoishiring•15h ago•178 comments

Turbo Haskell

https://comonad.com/reader/2026/turbo-haskell/
59•pjmlp•16h ago•4 comments

StreetComplete on iOS is now in public beta

https://github.com/streetcomplete/StreetComplete/issues/5421
549•Snowly•19h ago•144 comments

Git 3.0's upcoming SHA-256 default will be a costly mistake

https://blog.gitbutler.com/git-3-sha-256
305•chmaynard•13h ago•300 comments

Using Opus 5.5 to discover a new eyewitness record of the dodo

https://resobscura.substack.com/p/using-opus-55-to-discover-a-new-eyewitness
114•benbreen•9h ago•28 comments

To grieve, or not to grieve?

https://xenaproject.wordpress.com/2026/10/01/to-grieve-or-not-to-grieve/
40•stabbles•20h ago•5 comments

CSS Bed: Classless CSS themes to use as starting points in web development

https://www.cssbed.com
94•sea-gold•9h ago•26 comments

RIP, vector database

https://turbopuffer.com/blog/rip-vector-database
302•razin•14h ago•82 comments

ArXiv's Updated Rate Limit Policy

https://blog.arxiv.org/2026/10/01/updated-rate-limit-policy/
102•50kIters•10h ago•39 comments

Building reliable (and fast) directory sync

https://www.firezone.dev/blog/building-reliable-directory-sync
3•jamilbk•1h ago•0 comments

Show HN: Janus – Go binary that runs GGUF models via Vulkan on AMD/Intel/Nvidia

https://github.com/Vibra-Ingenn/Janus
64•Maverick617•9h ago•9 comments

Vote on which of Hacker News' challenges for AI have been met

https://stoppels.ch/goalposts/
127•stabbles•12h ago•126 comments

Frog and Toad and the Increasingly Capable Machines

https://www.frogandtoad.ai/
109•supermdguy•8h ago•22 comments

Various Projects Find Hidden SDR Capabilities in ESP32 Microcontrollers

https://www.rtl-sdr.com/various-projects-independently-find-hidden-sdr-capabilities-in-esp32-micr...
201•nkw•15h ago•30 comments

Oxygen-deprived underwater zones may not be “dead zones” but clue to early life

https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2026AV002570
92•gumby•11h ago•6 comments

Cloudflare K2: serverless event streams

https://blog.cloudflare.com/cloudflare-k2-streams/
226•elffjs•16h ago•89 comments

Butterflies use optical illusions to dodge predators

https://www.essex.ac.uk/news/2026/09/30/butterflies-use-optical-illusions-to-dodge-predators
35•gmays•7h ago•5 comments

Context Language Models

https://arxiv.org/abs/2609.37725
137•emersonmacro•15h ago•29 comments

Bez: Generating a browser engine from specs and tests

https://tangled.org/burrito.space/bez
108•nerdypepper•12h ago•44 comments

How to speed up the Rust compiler in September 2026

https://nnethercote.github.io/2026/09/30/how-to-speed-up-the-rust-compiler-in-september-2026.html
243•trickypr•17h ago•130 comments

US tells France and Germany to release diesel stocks or face US export ban

https://www.reuters.com/business/energy/us-tells-france-germany-release-diesel-stocks-or-face-us-...
12•geox•1h ago•2 comments