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.

Google is dead. Where do we go now?

https://www.circusscientist.com/2025/12/29/google-is-dead-where-do-we-go-now/
641•tomjuggler•9h ago•578 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/
568•haunter•13h ago•330 comments

Hacking Washing Machines [video]

https://media.ccc.de/v/39c3-hacking-washing-machines
60•clausecker•4h ago•16 comments

ManusAI Joins Meta

https://manus.im/blog/manus-joins-meta-for-next-era-of-innovation
167•gniting•7h ago•93 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/
327•coloneltcb•11h ago•353 comments

Stranger Things creator says turn off "garbage" settings

https://screenrant.com/stranger-things-creator-turn-off-settings-premiere/
94•1970-01-01•6h ago•108 comments

Show HN: Stop Claude Code from forgetting everything

https://github.com/mutable-state-inc/ensue-skill
118•austinbaggio•7h ago•151 comments

MongoDB Server Security Update, December 2025

https://www.mongodb.com/company/blog/news/mongodb-server-security-update-december-2025
61•plorkyeran•5h ago•18 comments

Show HN: A Claude Code plugin that catch destructive Git and filesystem commands

https://github.com/kenryu42/claude-code-safety-net
27•kenryu•4d ago•28 comments

Parsing Advances

https://matklad.github.io/2025/12/28/parsing-advances.html
65•birdculture•6h ago•5 comments

The future of software development is software developers

https://codemanship.wordpress.com/2025/11/25/the-future-of-software-development-is-software-devel...
108•cdrnsf•10h ago•97 comments

Incremental Backups of Gmail Takeouts

https://baecher.dev/stdout/incremental-backups-of-gmail-takeouts/
60•pbhn•4d ago•24 comments

AI is forcing us to write good code

https://bits.logic.inc/p/ai-is-forcing-us-to-write-good-code
129•sgk284•10h ago•100 comments

Streaming compression beats framed compression

https://bou.ke/blog/compressed/
9•bouk•3d ago•6 comments

When someone says they hate your product

https://www.getflack.com/p/responding-to-negative-feedback
125•jger15•10h ago•92 comments

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

https://keithburgun.net/outside-dungeon-town-integrating-the-three-places-in-videogames/
49•vector_spaces•5h ago•22 comments

Static Allocation with Zig

https://nickmonad.blog/2025/static-allocation-with-zig-kv/
179•todsacerdoti•13h ago•89 comments

Geology of the Gulf of the Farallones National Marine Sanctuary

https://pubs.usgs.gov/fs/farallones/
43•greesil•6h ago•11 comments

Show HN: Euclidle – Guess the Coordinates in N‑Dimensional Space

https://euclidle.com/
3•bills-appworks•3d ago•1 comments

Stanford Lecture: Dr. Don Knuth – Adventures with Knight's Tours [video]

https://www.youtube.com/watch?v=MKiRte-tnMY
51•vismit2000•5d ago•4 comments

Flame Graphs vs Tree Maps vs Sunburst (2017)

https://www.brendangregg.com/blog/2017-02-06/flamegraphs-vs-treemaps-vs-sunburst.html
114•gudzpoz•2d ago•30 comments

Kidnapped by Deutsche Bahn

https://www.theocharis.dev/blog/kidnapped-by-deutsche-bahn/
981•JeremyTheo•17h ago•866 comments

I migrated to an almost all-EU stack and saved 500€ per year

https://www.zeitgeistofbytes.com/p/bye-bye-big-tech-how-i-migrated-to
99•alexcos•6h ago•53 comments

Show HN: A 45x45 Connections Puzzle To Commemorate 2025=45*45

https://thomaswc.com/2025.html
45•thomaswc•6d ago•7 comments

Vitest Browser Mode Guide

https://howtotestfrontend.com/resources/vitest-browser-mode-guide-and-setup-info
40•howToTestFE•5d ago•4 comments

A production bug that made me care about undefined behavior

https://gaultier.github.io/blog/the_production_bug_that_made_me_care_about_undefined_behavior.html
127•birdculture•11h ago•74 comments

Karpathy on Programming: “I've never felt this much behind”

https://twitter.com/karpathy/status/2004607146781278521
382•rishabhaiover•3d ago•425 comments

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

https://linuxdaw.org/
216•prmoustache•17h ago•102 comments

List of domains censored by German ISPs

https://cuiiliste.de/domains
337•elcapitan•11h ago•138 comments

All Delisted Steam Games

https://delistedgames.com/all-delisted-steam-games/
230•Bondi_Blue•10h ago•100 comments