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.

Qwen 3.8 27B is excellent, but it defaults to overthinking things

https://simonwillison.net/2026/Aug/16/qwen-38-27b/
205•bilsbie•5h ago•86 comments

The Life and Death of Direct File [pdf]

https://www.ischool.berkeley.edu/sites/default/files/vinton_report_5.pdf
130•ronbenton•4h ago•54 comments

AGI-64 Brings Sierra Adventures to the Commodore 64

https://meanhamster.com/news/agi-64-brings-sierra-adventures-to-the-commodore-64
37•erickhill•3h ago•4 comments

Gmail might partially be to blame for receiving emails from other Sean Conners

https://boston.conman.org/2026/08/11.1
19•dmarto•1h ago•15 comments

A 3rd World Embedded Engineer Responds to "RISC-V They Should Have Known Better"

https://rvembedded.com/blog_post/12/
415•Narishma•11h ago•227 comments

Claude: System Prompts

https://platform.claude.com/docs/en/release-notes/system-prompts
587•tosh•16h ago•241 comments

Rhombus 1.1 is now available

https://blog.racket-lang.org/2026/08/rhombus-v1.1.html
38•spdegabrielle•4h ago•13 comments

Reticulum – Decentralized Mesh Network

https://reticulum.network/
46•sudo_cowsay•4h ago•11 comments

Low-Tech Ceramic Water Filter

https://wiki.lowtechlab.org/wiki/Filtre_%C3%A0_eau_c%C3%A9ramique/en
132•Bluestein•5d ago•34 comments

Interview with Amit Patel, Creator of "Solar Realms Elite"

https://breakintochat.com/blog/2013/02/18/amit-patel-creator-of-solar-realms-elite/
32•bananaboy•1w ago•6 comments

Dancing with friends and enemies: boids' swarm intelligence

https://community.wolfram.com/groups/-/m/t/122095
34•surprisetalk•5d ago•1 comments

SIMD in the 90s: Programming Intel's Pentium MMX

https://pikuma.com/blog/programming-intel-pentium-mmx-simd
88•ibobev•3d ago•40 comments

Applying a photosynthetic process to treat "dry eye"

https://www.science.org/content/blog-post/taking-tip-plants-eyes
17•gumby•4h ago•0 comments

How do I permanently disable Google Photos pop-up prompt to backup my photos?

https://support.google.com/photos/thread/256212140/how-do-i-permanently-disable-google-photos-pop...
40•dt3ft•3d ago•13 comments

Protobuf has LSP support. You're welcome

https://buf.build/blog/protobuf-lsp
132•theanonymousone•10h ago•85 comments

Prolly: A content-addressed ordered map built on prolly trees

https://github.com/crabbuild/prolly
15•forhappy•3h ago•0 comments

The AI Credit Resale Economy

https://vectoral.com/blog/who-are-the-token-brokers
251•mlenhard•14h ago•100 comments

MathCode, Mathematical Coding Agent

https://math-ai-org.github.io/mathcode/
76•homarp•10h ago•25 comments

Plastic mechanical computer from 1963: The Digi-Comp 1 [video]

https://www.youtube.com/watch?v=-y8bGBE71yw
60•tobr•1d ago•16 comments

Nvidia dramatically reduces amount of OpenAI infra financing it may guarantee

https://www.reuters.com/business/nvidia-scales-back-250-billion-openai-data-center-guarantee-wsj-...
160•root-parent•7h ago•64 comments

A quick look at zero-knowledge proofs

https://bernsteinbear.com/blog/zkp/
66•evakhoury•2d ago•35 comments

Red queen hypothesis – a new way forward for self-improving AI

https://www.cst.cam.ac.uk/news/red-queen-hypothesis-new-way-forward-self-improving-ai
29•hardlianotion•8h ago•2 comments

Clamiga: Common Lisp for the Amiga

https://nnamgreb.de/blog/Clamiga+-+Common+Lisp+for+the+Amiga
98•emptybits•4d ago•12 comments

Anton Chekhov played at love most of his life

https://commonreader.wustl.edu/winning-and-losing-at-the-great-game-of-intimacy/
78•lermontov•2d ago•19 comments

Firefox for iOS now has a native adblocker

https://support.mozilla.org/en-US/kb/block-ads-firefox-ios
587•pentagrama•15h ago•241 comments

The federal keyword lists that canceled billions in research funding

https://www.highereddive.com/news/inside-the-federal-keyword-lists-that-canceled-billions-in-rese...
167•walrus01•4h ago•60 comments

Tell HN: Cloudflare silently injects its analytics when you switch nameservers

353•stagas•11h ago•94 comments

Stripe Clinches over $7B Deal to Buy AI Firm OpenRouter

https://www.bloomberg.com/news/articles/2026-08-16/stripe-nears-deal-to-buy-ai-firm-openrouter-fo...
246•zacharyozer•8h ago•175 comments

A True Telnet BBS on a Casio Calculator

https://ei3lh.eu/2026/08/16/a-true-telnet-bbs-on-a-casio-calculator/
94•austinallegro•16h ago•9 comments

St Lucie Nuclear Reactor Unit 1 manually shutdown, 3 control rods drop into core

https://www.wptv.com/news/treasure-coast/region-st-lucie-county/saint-lucie-nuclear-power-plant-u...
167•toomuchtodo•13h ago•130 comments