frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

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•7mo ago

Comments

LegionMammal978•7mo 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•7mo 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•6mo 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.

GPT-5.2

https://openai.com/index/introducing-gpt-5-2/
900•atgctg•12h ago•738 comments

Nokia N900 Necromancy

https://yaky.dev/2025-12-11-nokia-n900-necromancy/
176•yaky•6h ago•50 comments

Rivian Unveils Custom Silicon, R2 Lidar Roadmap, and Universal Hands Free

https://riviantrackr.com/news/rivian-unveils-custom-silicon-r2-lidar-roadmap-universal-hands-free...
278•doctoboggan•11h ago•355 comments

Denial of service and source code exposure in React Server Components

https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-comp...
255•sangeeth96•9h ago•147 comments

He set out to walk around the world. After 27 years, his quest is nearly over

https://www.washingtonpost.com/lifestyle/2025/12/05/karl-bushby-walk-around-world/
16•wallflower•4d ago•2 comments

The highest quality codebase

https://gricha.dev/blog/the-highest-quality-codebase
479•Gricha•3d ago•320 comments

An SVG is all you need

https://jon.recoil.org/blog/2025/12/an-svg-is-all-you-need.html
199•sadiq•10h ago•82 comments

Programmers and software developers lost the plot on naming their tools

https://larr.net/p/namings.html
215•todsacerdoti•12h ago•321 comments

CRISPR fungus: Protein-packed, sustainable, and tastes like meat

https://www.isaaa.org/kc/cropbiotechupdate/article/default.asp?ID=21607
50•rguiscard•5h ago•15 comments

Google De-Indexed My Bear Blog and I Don't Know Why

https://journal.james-zhan.com/google-de-indexed-my-entire-bear-blog-and-i-dont-know-why/
31•nafnlj•4h ago•5 comments

Litestream VFS

https://fly.io/blog/litestream-vfs/
268•emschwartz•12h ago•77 comments

Laying out the 404 Media zine

https://tedium.co/2025/12/10/404-media-zine-linux-affinity/?
47•robenkleene•6h ago•5 comments

Cadmium Zinc Telluride: The wonder material powering a medical 'revolution'

https://www.bbc.com/news/articles/c24l223d9n7o
27•1659447091•4h ago•6 comments

Stoolap: High-performance embedded SQL database in pure Rust

https://github.com/stoolap/stoolap
40•murat3ok•5h ago•8 comments

Show HN: Sim – Apache-2.0 n8n alternative

https://github.com/simstudioai/sim
173•waleedlatif1•12h ago•38 comments

The architecture of “not bad”: Decoding the Chinese source code of the void

https://suggger.substack.com/p/the-architecture-of-not-bad-decoding
84•Suggger•15h ago•99 comments

Pdsink: USB Power Delivery Sink library for embedded devices

https://github.com/pdsink/pdsink
30•zdw•5d ago•9 comments

Craft software that makes people feel something

https://rapha.land/craft-software-that-makes-people-feel-something/
272•lukeio•16h ago•132 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
587•__rito__•1d ago•253 comments

Tile IR Specification

https://docs.nvidia.com/cuda/tile-ir/
18•my123•1w ago•2 comments

The Walt Disney Company and OpenAI Partner on Sora

https://openai.com/index/disney-sora-agreement/
192•inesranzo•16h ago•443 comments

EFF launches Age Verification Hub

https://www.eff.org/press/releases/eff-launches-age-verification-hub-resource-against-misguided-laws
289•iamnothere•1d ago•243 comments

French supermarket's Christmas advert is worldwide hit (without AI) [video]

https://www.youtube.com/watch?v=Na9VmMNJvsA
276•gbugniot•16h ago•148 comments

Almond (YC X25) Is Hiring SWEs and MechEs

https://www.ycombinator.com/companies/almond-2/jobs
1•shawnpatel•9h ago

The Invisible Cost: From Creator to Consumer

https://edwardnoaland.substack.com/p/the-invisible-cost-from-creator-to
11•edwardnoaland•1w ago•2 comments

The HTML-First Approach: Why Htmx and Lightweight Frameworks Are Revolutionizin

https://www.danieleteti.it/post/html-first-frameworks-htmx-revolution-en/#building-with-html-inst...
16•todsacerdoti•5h ago•1 comments

Powder and stone, or, why medieval rulers loved castles

https://1517.substack.com/p/powder-and-stone-or-why-medieval
39•areoform•8h ago•13 comments

Notes on Gamma

https://poniesandlight.co.uk/reflect/gamma/
11•todsacerdoti•5h ago•2 comments

My productivity app is a never-ending .txt file (2020)

https://jeffhuang.com/productivity_text_file/
202•simonebrunozzi•10h ago•136 comments

Size of Life

https://neal.fun/size-of-life/
2485•eatonphil•1d ago•276 comments