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.

GLM-Legal

https://z.ai/blog/glm-legal
208•ilreb•2h ago•132 comments

A Modern Web App in C

https://prophitt.me/writing/a-modern-web-app-in-c
132•prophittcorey•2h ago•52 comments

AI coding agents generate more code, but not more software

https://arstechnica.com/ai/2026/10/ai-coding-agents-generate-more-code-but-not-more-software/
60•gumby•1h ago•37 comments

Launch HN: Agent37 (YC F26) – Low-cost agent sandboxes for running agents

33•vishnukool•1h ago•20 comments

Citroen revives the 2CV for an electric age

https://www.bbc.com/news/articles/c620r33plgppo
136•scrlk•6h ago•155 comments

Show HN: I rewrote my website in Swift

https://sindresorhus.com/blog/swift-website
9•mofle•21m ago•0 comments

Muse Wonder

https://research.meta.ai/blog/muse-wonder
218•meetpateltech•1h ago•88 comments

The Making Of Super Mario 64 – full Giles Goddard interview (2001)

https://pixelatron.com/blog/the-making-of-super-mario-64-full-giles-goddard-interview-ngc/
164•gregsadetsky•1d ago•65 comments

Thinking will become a hobby

https://www.spinellis.gr/blog/20261008/?li261008
56•pranitha_m•1h ago•68 comments

Turn a WiFi 7 Router into a 320Msps Software Defined Radio Receiver

https://github.com/h0m3us3r/w1700k-sdr
99•djfergus•5h ago•27 comments

Kevin Kelly's 2016 AI Predictions, 10 Years Later

https://taylor.town/kk-ai-2026
45•surprisetalk•3h ago•6 comments

Secret of Orange Cats Revealed After 60-Year Search

https://www.sciencealert.com/secret-of-orange-cats-finally-revealed-after-60-year-search
163•bookofjoe•1d ago•141 comments

Hackers activate automatic defrosting accross European supermarket fridges

https://www.tomshardware.com/tech-industry/cyber-security/unprecedented-cyberattack-cripples-supe...
109•Zeekaas•6h ago•267 comments

Fingerprints are the new cookies

https://royfish.dev/fingerprints-are-the-new-cookies
648•royfish•19h ago•313 comments

Show HN: PS2 games statically recompiled to WebAssembly

https://github.com/snuri00/ps2-web-recomp
211•deadxwarrior•11h ago•112 comments

Fridges in French supermarkets hit by cyber attack

https://www.bbc.com/news/articles/crq5nzxv9q4yo
89•cataflam•3h ago•51 comments

The gap in shared understanding of LLM capability is widening

https://twitter.com/karpathy/status/2109361546505966046
630•albertzeyer•22h ago•921 comments

Type-safe HTML templating in Zig

https://lalinsky.com/2026/10/11/type-safe-html-templating-in-zig.html
207•lukaslalinsky•13h ago•77 comments

Total Annihilation, rebuilt for modern computers

https://nanolathe.gg
637•jttnr•1d ago•243 comments

I Found a $90k Remote Code Execution Vulnerability in Google

https://simonkoeck.com/writeups/google-devsite-flask-session-pickle-rce
108•soeckly•10h ago•46 comments

Calculus with Julia

https://jverzani.github.io/CalculusWithJuliaNotes.jl/
228•subset•2d ago•42 comments

Incident with Actions, Pull Requests and Issues

https://www.githubstatus.com/incidents/93njd414rpbx
133•dkpk•5h ago•122 comments

(Post-Quantum) Cryptographic Right Answers

https://words.filippo.io/right-answers/
38•gavide•5h ago•1 comments

An Unmade Film Shaped Hayao Miyazaki

https://animationobsessive.substack.com/p/an-unmade-film-shaped-hayao-miyazaki
49•vinhnx•3h ago•6 comments

Running the unmodified Linux amdgpu driver on an iPad

https://github.com/Geramy/LemonSeed-Studio
77•joshcsimmons•1d ago•19 comments

Reverse engineer anything with agents, from app behavior down to native binaries

https://github.com/morluto/rea
21•taytus•1h ago•3 comments

Choreographic Programming in Rust

https://github.com/hibanaworks/hibana
46•o8vm•1d ago•34 comments

Terence Tao: Math 2.0 [pdf]

https://teorth.github.io/tao-web/slides/math-2-0-caltech-2026.pdf
493•Anon84•1d ago•492 comments

Bag of Decisions Reranker

https://softwaredoug.com/blog/2026/10/08/bag-of-decisions.html
62•zdw•2d ago•10 comments

My Reddit AMA on the Law of Web Scraping

https://blog.ericgoldman.org/archives/2026/10/my-reddit-ama-on-the-law-of-web-scraping.htm
3•speckx•19m ago•0 comments