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.

Microsoft and OpenAI end their exclusive and revenue-sharing deal

https://www.bloomberg.com/news/articles/2026-04-27/microsoft-to-stop-sharing-revenue-with-main-ai...
568•helsinkiandrew•6h ago•500 comments

Easyduino: Open Source PCB Devboards for KiCad

https://github.com/Hanqaqa/Easyduino
100•Hanqaqa•2h ago•9 comments

“Why not just use Lean?”

https://lawrencecpaulson.github.io//2026/04/23/Why_not_Lean.html
209•ibobev•5h ago•124 comments

Networking changes coming in macOS 27

https://eclecticlight.co/2026/04/23/networking-changes-coming-in-macos-27/
141•pvtmert•4h ago•117 comments

China blocks Meta's acquisition of AI startup Manus

https://www.cnbc.com/2026/04/27/meta-manus-china-blocks-acquisition-ai-startup.html
126•yakkomajuri•8h ago•60 comments

Super ZSNES – GPU Powered SNES Emulator

https://zsnes.com/
116•haunter•2h ago•24 comments

The woes of sanitizing SVGs

https://muffin.ink/blog/scratch-svg-sanitization/
127•varun_ch•4h ago•50 comments

The Quiet Resurgence of RF Engineering

https://atempleton.bearblog.dev/quiet-resurgence-of-rf-engineering/
36•merlinq•2d ago•14 comments

4TB of voice samples just stolen from 40k AI contractors at Mercor

https://app.oravys.com/blog/mercor-breach-2026
359•Oravys•10h ago•133 comments

United Wizards of the Coast

https://unitedwizardsofthecoast.com/news/announcing-united-wizards-coast-cwa
145•d4mi3n•1h ago•99 comments

Magic by Return of Post: How Mail Order Delivered the Occult

https://publicdomainreview.org/essay/magic-by-return-of-post/
17•Vigier•1d ago•2 comments

GitHub Copilot is moving to usage-based billing

https://github.blog/news-insights/company-news/github-copilot-is-moving-to-usage-based-billing/
390•frizlab•4h ago•305 comments

Men who stare at walls

https://www.alexselimov.com/posts/men_who_stare_at_walls/
328•aselimov3•9h ago•167 comments

Spanish archaeologists discover trove of ancient shipwrecks in Bay of Gibraltar

https://www.theguardian.com/science/2026/apr/15/hidden-treasures-spanish-archaeologists-discover-...
14•1659447091•1d ago•0 comments

Show HN: OSS Agent I built topped the TerminalBench on Gemini-3-flash-preview

https://github.com/dirac-run/dirac
263•GodelNumbering•7h ago•99 comments

Adding a team was the wrong strategic decision

https://learnings.aleixmorgadas.dev/p/adding-a-team-was-the-wrong-strategic
52•milkglass•2d ago•15 comments

Pgbackrest is no longer being maintained

https://github.com/pgbackrest/pgbackrest
366•c0l0•9h ago•190 comments

Decoupled DiLoCo: Resilient, Distributed AI Training at Scale

https://deepmind.google/blog/decoupled-diloco/
31•metadat•3h ago•3 comments

US Supreme Court reviews police use of cell location data

https://www.nytimes.com/2026/04/27/us/politics/supreme-court-cell-data-geofence.html
157•unethical_ban•4h ago•106 comments

Fully Featured Audio DSP Firmware for the Raspberry Pi Pico

https://github.com/WeebLabs/DSPi
221•BoingBoomTschak•2d ago•58 comments

Our principles

https://openai.com/index/our-principles/
33•tosh•1h ago•43 comments

FDA approves first gene therapy for treatment of genetic hearing loss

https://www.fda.gov/news-events/press-announcements/fda-approves-first-ever-gene-therapy-treatmen...
171•JeanKage•10h ago•69 comments

U.S. companies back Sam Altman's World ID even as much of the world pushes back

https://restofworld.org/2026/sam-altman-worldcoin-zoom-tinder-partnerships/
23•kelnos•46m ago•8 comments

Flipdiscs

https://flipdisc.io
509•skogstokig•4d ago•85 comments

Supreme Court to hear arguments in landmark Roundup weedkiller case

https://www.nytimes.com/2026/04/26/climate/supreme-court-bayer-monsanto-roundup-glyphosate.html
74•mikhael•4h ago•73 comments

Show HN: Utilyze – an open source GPU monitoring tool more accurate than nvtop

https://www.systalyze.com/utilyze
51•ManyaGhobadi•6h ago•11 comments

Quarkdown – Markdown with Superpowers

https://quarkdown.com/
204•amai•11h ago•59 comments

Den stora Älgvandringen – The great moose migration (live)

https://www.svtplay.se/video/jXv3A5G/den-stora-algvandringen/idag-00-00
74•donjoe•3d ago•7 comments

GitHub is having issues now

https://www.githubstatus.com
235•SenHeng•2h ago•85 comments

Managing the Unmanaged Switch

https://watchmysys.com/blog/2026/03/managing-the-unmanaged-switch/
52•luu•2d ago•24 comments