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.

Gemini 3.7 Flash

https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-3-7-fl...
626•thisisauserid•8h ago•353 comments

Bluesky Protocol Services

https://atproto.com/blog/introducing-bluesky-protocol-services
71•danabramov•1h ago•16 comments

SparrowMap – Cameras that watch government vehicles

https://sparrowmap.com/
41•paulnpace•2h ago•8 comments

Accelerating GPT-5.6 Sol Ultrafast

https://www.cerebras.ai/blog/accelerating-gpt-5-6-sol-ultrafast-with-openai
433•pr337h4m•8h ago•181 comments

DeepSeek Harness developer preview

https://deepseek.com/harness/en/
561•bjin•13h ago•246 comments

NP-overrated

https://gruhn.me/blog/2026-08-13/
154•theanonymousone•5h ago•95 comments

Understanding is the new bottleneck

https://www.geoffreylitt.com/2026/07/02/understanding-is-the-new-bottleneck
211•sebg•7h ago•117 comments

Donkey.bas is 45 Years Old – 131 line of Glory

https://donkeybas.com/
193•jkrauska•8h ago•83 comments

Mistral OCR 4.1

https://docs.mistral.ai/models/ocr-4-1
254•spelk•9h ago•102 comments

Spaghettifying DRAM

https://github.com/xoreaxeaxeax/skitter-creek-bath-salts
500•matt_d•11h ago•140 comments

Choose Boring Technology (2015)

https://mcfunley.com/choose-boring-technology
257•tosh•8h ago•137 comments

Hello, me. It's been a while

https://themech.net/2026/08/hello-me-its-been-a-while/
26•somesoftdev•7h ago•9 comments

I want extern "fil-C"

https://domenkozar.com/2026/08/13/i-want-extern-fil-c/
30•domenkozar•8h ago•6 comments

Finite State Machines in Forth (1994)

https://www.forth.org/literature/noble.html
50•ofalkaed•5d ago•1 comments

Where did the old web go? We followed 657,607 links to find out

https://0.mk/blog/link-rot
133•tdx•8h ago•117 comments

How Compaction Works in Pi

https://earendil.com/posts/compaction-in-pi/
110•tosh•8h ago•41 comments

How Organizations Use AI: Evidence from ChatGPT [pdf]

https://cdn.openai.com/pdf/how-organizations-use-chatgpt.pdf
67•malshe•6h ago•40 comments

Single log line is 49KB+ (ext4) / 110KB+ (btrfs) of systemd-journald disk writes

https://github.com/systemd/systemd/issues/40262
153•ValdikSS•7h ago•96 comments

Nine PBS sues Iron Mountain over blocked access to archival data

https://current.org/2026/08/nine-pbs-sues-iron-mountain-over-blocked-access-to-archival-data/
247•vinayakborkar•12h ago•137 comments

How a device finds encrypted DNS by itself

https://blog.dundns.eu/posts/ddr-encrypted-dns-discovery/
16•majorchord•6d ago•4 comments

Crown 0.64 – Native and cross-platform game engine

https://www.crownengine.org/news/crown-0-64/
5•dbartolini•3d ago•0 comments

How Gödel's Proof Works (2020)

https://www.quantamagazine.org/how-godels-proof-works-20200714/
72•tzury•6h ago•37 comments

An ambiguity in c89 which will never be fixed

https://sebsite.pw/w/20260810-c89ambiguity.html
33•runningmike•3d ago•7 comments

How AI text watermarking works

https://declaude.org/watermarking/
79•padolsey•2h ago•49 comments

Blog about things you don't understand yet

https://www.seangoedecke.com/blog-about-things-you-dont-understand-yet/
15•gfysfm•2h ago•3 comments

Kubernetes on Oxide: How customer needs shaped our integrations

https://oxide.computer/blog/kubernetes-on-oxide
158•stevehipwell•11h ago•70 comments

Launch HN: Bullet (YC S26) – A Faster Coding Agent

https://www.codewithbullet.com
85•adi1•17h ago•54 comments

Ordinary abundance

https://ordinaryabundance.com/
216•yen223•12h ago•118 comments

AI At Home Part 1: A Box Of Scraps

https://jdagostino.github.io/ai-pt1-box-o-scraps/index.html
92•timmmmmmay•9h ago•47 comments

Smooth Move: Taming Trajectories with Polynomials

https://nick.zoic.org/art/smooth-move-taming-trajectories-with-polynomials/
22•lioeters•3d ago•1 comments