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

Comments

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

Claude Sonnet 4.6

https://www.anthropic.com/news/claude-sonnet-4-6
785•adocomplete•6h ago•681 comments

Thank HN: You helped save 33k lives

235•chaseadam17•7h ago•26 comments

Run LLMs locally in Flutter with <200ms latency

https://github.com/ramanujammv1988/edge-veda
29•rish2497•57m ago•2 comments

Show HN: AsteroidOS 2.0 – Nobody asked, we shipped anyway

https://asteroidos.org/news/2-0-release/index.html
241•moWerk•4h ago•29 comments

BarraCUDA Open-source CUDA compiler targeting AMD GPUs

https://github.com/Zaneham/BarraCUDA
105•rurban•3h ago•35 comments

I swear the UFO is coming any minute

https://www.experimental-history.com/p/i-swear-the-ufo-is-coming-any-minute
57•Ariarule•2h ago•7 comments

Gentoo on Codeberg

https://www.gentoo.org/news/2026/02/16/codeberg.html
230•todsacerdoti•6h ago•71 comments

Using go fix to modernize Go code

https://go.dev/blog/gofix
259•todsacerdoti•7h ago•53 comments

So you want to build a tunnel

https://practical.engineering/blog/2026/2/17/so-you-want-to-build-a-tunnel
146•crescit_eundo•7h ago•60 comments

Async/Await on the GPU

https://www.vectorware.com/blog/async-await-on-gpu/
141•Philpax•7h ago•44 comments

Physicists Make Electrons Flow Like Water

https://www.quantamagazine.org/physicists-make-electrons-flow-like-water-20260211/
72•rbanffy•4d ago•7 comments

GrapheneOS – Break Free from Google and Apple

https://blog.tomaszdunia.pl/grapheneos-eng/
1037•to3k•14h ago•745 comments

Structured AI (YC F25) Is Hiring

https://www.ycombinator.com/companies/structured-ai/jobs/q3cx77y-gtm-intern
1•issygreenslade•3h ago

pg_background: Make Postgres do the long work (while your session stays light)

https://vibhorkumar.wordpress.com/2026/02/16/pg_background-make-postgres-do-the-long-work-while-y...
15•tanelpoder•1h ago•1 comments

Show HN: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript

https://github.com/n-e/pg-typesafe
35•n_e•6h ago•16 comments

Assistant to the Regional Manager

https://smallpotatoes.paulbloom.net/p/assistant-to-the-regional-manager
49•NaOH•4d ago•9 comments

Show HN: I wrote a technical history book on Lisp

https://berksoft.ca/gol/
142•cdegroot•8h ago•48 comments

'My Words Are Like an Uncontrollable Dog': On Life with Nonfluent Aphasia

https://thereader.mitpress.mit.edu/my-words-are-like-an-uncontrollable-dog-on-life-with-nonfluent...
8•anarbadalov•1h ago•0 comments

I converted 2D conventional flight tracking into 3D

https://aeris.edbn.me/?city=SFO
203•kewonit•9h ago•42 comments

Is Show HN dead? No, but it's drowning

https://www.arthurcnops.blog/death-of-show-hn/
379•acnops•13h ago•326 comments

HackMyClaw

https://hackmyclaw.com/
233•hentrep•7h ago•127 comments

Show HN: Box of Rain - Auto-Layouted ASCII Diagrams

https://github.com/switz/box-of-rain
7•switz•3d ago•2 comments

Contra "Grandmaster-level chess without search" (2024)

https://cosmo.tardis.ac/files/2024-02-13-searchless.html
24•luu•1d ago•0 comments

After 800 episodes, 'The Simpsons' creators look back and ahead

https://apnews.com/article/simpsons-800-episodes-72d723e6d885b1944c9a1ec8b9a24c3a
31•1659447091•2d ago•26 comments

Discord Rival Gets Overwhelmed by Exodus of Players Fleeing Age-Verification

https://kotaku.com/discord-alternative-teamspeak-age-verification-check-rivals-2000669693
186•thunderbong•6h ago•85 comments

Show HN: I taught LLMs to play Magic: The Gathering against each other

https://mage-bench.com/
88•GregorStocks•7h ago•68 comments

Show HN: I'm launching a LPFM radio station

https://www.kpbj.fm/
46•solomonb•4h ago•32 comments

Climbing Mount Fuji visualized through milestone stamps

https://fuji.halfof8.com/
47•gessha•6h ago•8 comments

Launch HN: Sonarly (YC W26) – AI agent to triage and fix your production alerts

https://sonarly.com/
23•Dimittri•7h ago•5 comments

Chess engines do weird stuff

https://girl.surgery/chess
135•admiringly•7h ago•69 comments