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•1y ago

Comments

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

Removing the modem and GPS from my 2024 RAV4 hybrid

https://arkadiyt.com/2026/05/13/removing-the-modem-and-gps-from-my-rav4/
457•arkadiyt•5h ago•261 comments

Amazonbot is finally respecting robots.txt

https://xeiaso.net/notes/2026/amazonbot-respecting-robots-txt/
69•xena•2h ago•11 comments

First public macOS kernel memory corruption exploit on Apple M5

https://blog.calif.io/p/first-public-kernel-memory-corruption
152•quadrige•3h ago•23 comments

RTX 5090 and M4 MacBook Air: Can It Game?

https://scottjg.com/posts/2026-05-05-egpu-mac-gaming/
430•allenleee•6h ago•113 comments

Tesla Wall Connector bootloader bypasses the firmware downgrade ratchet

https://www.synacktiv.com/en/publications/exploiting-the-tesla-wall-connector-from-its-charge-por...
29•p_stuart82•1h ago•0 comments

New Nginx Exploit

https://github.com/DepthFirstDisclosures/Nginx-Rift
235•hetsaraiya•5h ago•55 comments

Claude for Legal

https://github.com/anthropics/claude-for-legal
38•Einenlum•1h ago•23 comments

Work with Codex from Anywhere

https://openai.com/index/work-with-codex-from-anywhere/
62•mikeevans•2h ago•16 comments

Infracost (YC W21) Is Hiring Sr Dev Advocate to make agents cloud cost-aware

https://www.ycombinator.com/companies/infracost/jobs/NzwUQ7c-senior-developer-advocate
1•akh•1h ago

RISC-V Router

https://router.start9.com/
36•janandonly•2h ago•18 comments

OVMS: Open source electric vehicle remote monitoring, diagnosis and control

https://www.openvehicles.com/home
7•BHSPitMonkey•34m ago•1 comments

Porting 3D Movie Maker to Linux

https://benstoneonline.com/posts/porting-3d-movie-maker-to-linux/
41•speckx•3d ago•9 comments

HDD Firmware Hacking

https://icode4.coffee/?p=1465
99•jsploit•6h ago•9 comments

The Biochemical Beauty of Retatrutide: How GLP-1s Work

https://acesounderglass.com/2025/10/13/the-biochemical-beauty-of-retatrutide-how-glp-1s-actually-...
21•surprisetalk•3d ago•12 comments

The Power of a Free Popsicle (2018)

https://www.gsb.stanford.edu/insights/power-free-popsicle
51•NaOH•3h ago•20 comments

New arXiv policy: 1-year ban for hallucinated references

https://twitter.com/tdietterich/status/2055000956144935055
106•gjuggler•1h ago•9 comments

Computer Hobby Movement in Canada

https://museum.eecs.yorku.ca/exhibits/show/hobby_canada/hobby_canada
169•rbanffy•9h ago•54 comments

Int a = 5; a = a++ + ++a; a =? (2011)

https://gynvael.coldwind.pl/?id=372
70•e-topy•2d ago•125 comments

A message from President Kornbluth about funding and the talent pipeline

https://president.mit.edu/writing-speeches/video-transcript-message-president-kornbluth-about-fun...
551•dmayo•7h ago•611 comments

WinUI 3 Performance: A Leap Forward

https://github.com/microsoft/microsoft-ui-xaml/discussions/11096
72•whatever3•3h ago•54 comments

Understanding the Linux Kernel: The Linux Kernel Startup

https://internals-for-interns.com/posts/linux-kernel-startup/
68•valyala•3h ago•10 comments

What's in a GGUF, besides the weights – and what's still missing?

https://nobodywho.ooo/posts/whats-in-a-gguf/
62•bashbjorn•5h ago•26 comments

Wrap Go binaries in Python wheels

https://github.com/simonw/go-to-wheel
5•ankitg12•2d ago•0 comments

You Don't Align an AI, You Align with It

https://danieltan.weblog.lol/2026/05/you-dont-align-an-ai-you-align-with-it
73•danieltanfh95•4h ago•37 comments

AI is making me dumb

https://jpain.io/god-damn-ai-is-making-me-dumb/
344•Eighth•4h ago•217 comments

Rewrite Bun in Rust has been merged

https://github.com/oven-sh/bun/pull/30412
422•Chaoses•14h ago•504 comments

DIY open-source ultrasound hardware on the rp2040/rp2350

http://un0rick.cc/pic0rick
32•kelu124•4h ago•2 comments

Show HN: I built a Web-Scraper API that is 6-7x more efficient than current ones

https://scrapewithruno.com/
13•polaritymaking•1h ago•7 comments

Fossils show millipede and centipede ancestors evolved legs underwater

https://phys.org/news/2026-05-ancient-sea-fossils-millipede-centipede.html
65•gmays•3d ago•2 comments

London's Smallest Public Sculptures

https://lookup.london/londons-smallest-public-sculptures/
28•susam•3d ago•3 comments