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

Comments

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

The EU still wants to scan your private messages and photos

https://fightchatcontrol.eu/?foo=bar
377•MrBruh•1h ago•126 comments

ARC-AGI-3

https://arcprize.org/arc-agi/3
144•lairv•3h ago•105 comments

Earthquake scientists reveal how overplowing weakens soil at experimental farm

https://www.washington.edu/news/2026/03/19/earthquake-scientists-reveal-how-overplowing-weakens-s...
42•Brajeshwar•7h ago•14 comments

Running Tesla Model 3's Computer on My Desk Using Parts from Crashed Cars

https://bugs.xdavidhu.me/tesla/2026/03/23/running-tesla-model-3s-computer-on-my-desk-using-parts-...
29•driesdep•53m ago•1 comments

90% of Claude-linked output going to GitHub repos w <2 stars

https://www.claudescode.dev/?window=since_launch
73•louiereederson•3h ago•47 comments

My astrophotography in the movie Project Hail Mary

https://rpastro.square.site/s/stories/phm
625•wallflower•3d ago•169 comments

Apple randomly closes bug reports unless you "verify" the bug remains unfixed

https://lapcatsoftware.com/articles/2026/3/11.html
165•zdw•2h ago•77 comments

Supreme Court Sides with Cox in Copyright Fight over Pirated Music

https://www.nytimes.com/2026/03/25/us/politics/supreme-court-cox-music-copyright.html
212•oj2828•7h ago•202 comments

China is mass-producing hypersonic missiles for $99,000

https://kdwalmsley.substack.com/p/on-sale-now-china-is-mass-producing
86•zdw•1h ago•35 comments

Quantization from the Ground Up

https://ngrok.com/blog/quantization
137•samwho•5h ago•28 comments

Ensu – Ente’s Local LLM app

https://ente.com/blog/ensu/
311•matthiaswh•9h ago•140 comments

Updates to GitHub Copilot interaction data usage policy

https://github.blog/news-insights/company-news/updates-to-github-copilot-interaction-data-usage-p...
155•prefork•2h ago•76 comments

TurboQuant: Redefining AI efficiency with extreme compression

https://research.google/blog/turboquant-redefining-ai-efficiency-with-extreme-compression/
456•ray__•17h ago•127 comments

Thoughts on slowing the fuck down

https://mariozechner.at/posts/2026-03-25-thoughts-on-slowing-the-fuck-down/
540•jdkoeck•7h ago•287 comments

FreeCAD v1.1

https://blog.freecad.org/2026/03/25/freecad-version-1-1-released/
82•sho_hn•2h ago•19 comments

Sodium-ion EV battery breakthrough delivers 11-min charging and 450 km range

https://electrek.co/2026/03/25/sodium-ion-ev-battery-delivers-11-min-charging-450-km-range/
47•breve•1h ago•13 comments

Goodbye to Sora

https://twitter.com/soraofficialapp/status/2036532795984715896
1062•mikeocool•1d ago•783 comments

Health NZ staff told to stop using ChatGPT to write clinical notes

https://www.rnz.co.nz/news/national/590645/health-nz-staff-told-to-stop-using-chatgpt-to-write-cl...
28•billybuckwheat•1h ago•3 comments

Ball Pit

https://codepen.io/mrdoob_/full/NPRwLZd
95•memalign•2h ago•24 comments

Tired of Ghost Positions in Companies?

https://ghostjobs.net
5•ghostjobsdotnet•1h ago•2 comments

Meta and YouTube found negligent in landmark social media addiction case

https://www.nytimes.com/2026/03/25/technology/social-media-trial-verdict.html
342•mrjaeger•4h ago•164 comments

Antimatter has been transported for the first time

https://www.nature.com/articles/d41586-026-00950-w
295•leephillips•7h ago•145 comments

VitruvianOS – Desktop Linux Inspired by the BeOS

https://v-os.dev
314•felixding•18h ago•194 comments

Miscellanea: The War in Iran

https://acoup.blog/2026/03/25/miscellanea-the-war-in-iran/
328•decimalenough•17h ago•467 comments

Tracy Kidder has died

https://www.nytimes.com/2026/03/25/books/tracy-kidder-dead.html
172•ghc•5h ago•50 comments

Slovenian officials blame Israeli firm Black Cube for trying to manipulate vote

https://www.wsj.com/world/europe/spies-lies-and-fake-investors-in-disguise-how-plotters-tried-to-...
475•cramsession•5h ago•207 comments

Looking at Unity made me understand the point of C++ coroutines

https://mropert.github.io/2026/03/20/unity_cpp_coroutines/
144•ingve•3d ago•122 comments

Flighty Airports

https://flighty.com/airports
513•skogstokig•21h ago•171 comments

Jury finds Meta liable in case over child sexual exploitation on its platforms

https://www.cnn.com/2026/03/24/tech/meta-new-mexico-trial-jury-deliberation
252•billfor•1d ago•421 comments

Show HN: I took back Video.js after 16 years and we rewrote it to be 88% smaller

https://videojs.org/blog/videojs-v10-beta-hello-world-again
604•Heff•1d ago•129 comments