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

Netflix: Open Content

https://opencontent.netflix.com/
166•tosh•2h ago•21 comments

Non-Zero-Sum Games

https://nonzerosum.games/
56•8organicbits•1h ago•3 comments

Go Away Python

https://lorentz.app/blog-item.html?id=go-shebang
109•baalimago•4h ago•48 comments

Google is dead. Where do we go now?

https://www.circusscientist.com/2025/12/29/google-is-dead-where-do-we-go-now/
893•tomjuggler•16h ago•706 comments

GOG is getting acquired by its original co-founder

https://www.gog.com/blog/gog-is-getting-acquired-by-its-original-co-founder-what-it-means-for-you/
735•haunter•20h ago•440 comments

Show HN: One clean, developer-focused page for every Unicode symbol

https://fontgenerator.design/symbols
66•yarlinghe•4d ago•32 comments

Stranger Things creator says turn off "garbage" settings

https://screenrant.com/stranger-things-creator-turn-off-settings-premiere/
232•1970-01-01•13h ago•410 comments

Crimson (YC X25) is hiring founding engineers in London

https://www.ycombinator.com/companies/crimson/jobs/kCikzj1-founding-engineer-full-stack
1•markfeldner•1h ago

Nicolas Guillou, French ICC judge sanctioned by the US and “debanked”

https://www.lemonde.fr/en/international/article/2025/11/19/nicolas-guillou-french-icc-judge-sanct...
133•lifeisstillgood•1h ago•73 comments

Hacking Washing Machines [video]

https://media.ccc.de/v/39c3-hacking-washing-machines
149•clausecker•11h ago•28 comments

ManusAI Joins Meta

https://manus.im/blog/manus-joins-meta-for-next-era-of-innovation
257•gniting•14h ago•158 comments

Tesla's 4680 battery supply chain collapses as partner writes down deal by 99%

https://electrek.co/2025/12/29/tesla-4680-battery-supply-chain-collapses-partner-writes-down-dea/
499•coloneltcb•19h ago•555 comments

UNIX Fourth Edition

http://squoze.net/UNIX/v4/README
65•dcminter•1w ago•7 comments

The future of software development is software developers

https://codemanship.wordpress.com/2025/11/25/the-future-of-software-development-is-software-devel...
254•cdrnsf•17h ago•252 comments

Graph Algorithms in Rayon

https://davidlattimore.github.io/posts/2025/11/27/graph-algorithms-in-rayon.html
16•PaulHoule•4d ago•0 comments

AI is forcing us to write good code

https://bits.logic.inc/p/ai-is-forcing-us-to-write-good-code
210•sgk284•17h ago•157 comments

Turning an old Amazon Kindle into a eInk development platform (2021)

https://blog.lidskialf.net/2021/02/08/turning-an-old-kindle-into-a-eink-development-platform/
27•fanf2•4d ago•5 comments

Charm Ruby – Glamorous Terminal Libraries for Ruby

https://charm-ruby.dev/
25•todsacerdoti•5h ago•3 comments

Easily Dealing with Any-Dimensional Planes

https://gpfault.net/posts/hyperplanes.html
3•ibobev•4d ago•0 comments

Outside, Dungeon, Town: Integrating the Three Places in Videogames (2024)

https://keithburgun.net/outside-dungeon-town-integrating-the-three-places-in-videogames/
83•vector_spaces•12h ago•38 comments

Show HN: Stop Claude Code from forgetting everything

https://github.com/mutable-state-inc/ensue-skill
162•austinbaggio•14h ago•188 comments

MongoDB Server Security Update, December 2025

https://www.mongodb.com/company/blog/news/mongodb-server-security-update-december-2025
85•plorkyeran•12h ago•37 comments

Static Allocation with Zig

https://nickmonad.blog/2025/static-allocation-with-zig-kv/
199•todsacerdoti•21h ago•92 comments

Incremental Backups of Gmail Takeouts

https://baecher.dev/stdout/incremental-backups-of-gmail-takeouts/
92•pbhn•5d ago•44 comments

Librarians Tired of Being Accused of Hiding Secret Books That Were Made Up by AI

https://gizmodo.com/librarians-arent-hiding-secret-books-from-you-that-only-ai-knows-about-200069...
68•vitalnodo•5d ago•45 comments

Kidnapped by Deutsche Bahn

https://www.theocharis.dev/blog/kidnapped-by-deutsche-bahn/
1089•JeremyTheo•1d ago•942 comments

Parsing Advances

https://matklad.github.io/2025/12/28/parsing-advances.html
87•birdculture•13h ago•10 comments

The Signature Flicker

https://steipete.me/posts/2025/signature-flicker
22•tosh•4d ago•11 comments

When someone says they hate your product

https://www.getflack.com/p/responding-to-negative-feedback
154•jger15•17h ago•113 comments

Linux DAW: Help Linux musicians to quickly and easily find the tools they need

https://linuxdaw.org/
255•prmoustache•1d ago•114 comments