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

Comments

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

Specsmaxxing – On overcoming AI psychosis, and why I write specs in YAML

https://acai.sh/blog/specsmaxxing
66•brendanmc6•1h ago•42 comments

A Couple Million Lines of Haskell: Production Engineering at Mercury

https://blog.haskell.org/a-couple-million-lines-of-haskell/
181•unignorant•8h ago•67 comments

This Month in Ladybird - April 2026

https://ladybird.org/newsletter/2026-04-30/
302•richardboegli•11h ago•57 comments

The IBM Granite 4.1 family of models

https://research.ibm.com/blog/granite-4-1-ai-foundation-models
75•wglb•2d ago•10 comments

Dav2d

https://code.videolan.org/videolan/dav2d
457•dabinat•14h ago•123 comments

Six Years Perfecting Maps on WatchOS

https://www.david-smith.org/blog/2026/04/29/maps-on-watchos/
273•valzevul•11h ago•60 comments

Neanderthals ran 'fat factories' 125,000 years ago (2025)

https://www.universiteitleiden.nl/en/news/2025/07/neanderthals-ran-fat-factories-125000-years-ago
179•andsoitis•11h ago•71 comments

Do_not_track

https://donottrack.sh/
301•RubyGuy•14h ago•97 comments

Inventions for battery reuse and recycling increase seven-fold in last decade

https://www.epo.org/en/news-events/news/inventions-battery-reuse-and-recycling-increase-more-seve...
195•JeanKage•2d ago•13 comments

VS Code inserting 'Co-Authored-by Copilot' into commits regardless of usage

https://github.com/microsoft/vscode/pull/310226
1129•indrora•12h ago•564 comments

Care homes and hotels in Japan shut as expansion strategy unravels

https://www.newsonjapan.com/article/149075.php
34•mikhael•6h ago•8 comments

Clojurists Together – Q2 2026 Open Source Funding Announcement

https://www.clojuriststogether.org/news/q2-2026-funding-announcement/
100•dragandj•10h ago•10 comments

A more efficient implementation of Shor's algorithm

https://lwn.net/Articles/1066156/
75•signa11•2d ago•13 comments

Show HN: State of the Art of Coding Models, According to Hacker News Commenters

https://hnup.date/hn-sota
100•yunusabd•11h ago•50 comments

Maryland to ban A.I.-driven price increases in grocery stores

https://www.nytimes.com/2026/05/01/business/surveillance-pricing-groceries-maryland.html
144•doener•7h ago•88 comments

The agent harness belongs outside the sandbox

https://www.mendral.com/blog/agent-harness-belongs-outside-sandbox
99•shad42•11h ago•75 comments

San Francisco streets with confusingly similar names

https://j-nelson.net/san-francisco-streets-with-similar-names/
24•SeenNotHeard•2d ago•31 comments

Because It Doesn't Have To

https://blog.computationalcomplexity.org/2026/04/because-it-doesnt-have-to.html
46•zdw•3d ago•12 comments

Simple and correct snapshot isolation

https://remy.wang/blog/si.html
22•remywang•2d ago•1 comments

Kimi K2.6 just beat Claude, GPT-5.5, and Gemini in a coding challenge

https://thinkpol.ca/2026/04/30/an-open-weights-chinese-model-just-beat-claude-gpt-5-5-and-gemini-...
252•bazlightyear•4h ago•111 comments

Forging ZK proofs to mint arbitrary DUSK tokens

https://osec.io/blog/2026-04-30-unverified-evaluations-dusk-plonk/
3•deut-erium•2d ago•0 comments

A physics engine with incremental rollback for multiplayer games

https://easel.games/blog/2026-rollback-physics
83•BSTRhino•1d ago•26 comments

How fast is a macOS VM, and how small could it be?

https://eclecticlight.co/2026/05/02/how-fast-is-a-macos-vm-and-how-small-could-it-be/
246•moosia•23h ago•86 comments

AI, Intimacy, and the Data You Never Meant to Share

https://fshot.org/techzone/the-algorithm-knows.php
21•victorkulla•5h ago•1 comments

When Dawkins met Claude – Could this AI be conscious?

https://unherd.com/2026/04/is-ai-the-next-phase-of-evolution/
28•pentestercrab•1d ago•146 comments

NetHack 5.0.0

https://nethack.org/v500/release.html
444•rsaarelm•14h ago•136 comments

The USB Situation

https://randsinrepose.com/archives/the-usb-situation/
124•herbertl•3d ago•142 comments

Barman – Backup and Recovery Manager for PostgreSQL

https://github.com/EnterpriseDB/barman
156•nateb2022•3d ago•23 comments

Little magazines are back

https://wsjfreeexpression.substack.com/p/little-magazines-are-back
89•prismatic•2d ago•33 comments

Open source does not imply open community

https://blog.feld.me/posts/2026/04/open-source-does-not-imply-open-community/
150•RohanAdwankar•5h ago•42 comments