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.

Telnyx package compromised on PyPI

https://www.aikido.dev/blog/telnyx-pypi-compromised-teampcp-canisterworm
75•overflowy•1h ago•32 comments

Anatomy of the .claude/ folder

https://blog.dailydoseofds.com/p/anatomy-of-the-claude-folder
257•freedomben•5h ago•128 comments

Make macOS consistently bad (unironically)

https://lr0.org/blog/p/macos/
27•speckx•28m ago•1 comments

Vibe-Coded Ext4 for OpenBSD

https://lwn.net/SubscriberLink/1064541/1a399d572a046fb9/
22•corbet•52m ago•21 comments

Installing a Let's Encrypt TLS certificate on a Brother printer with Certbot

https://owltec.ca/Other/Installing+a+Let%27s+Encrypt+TLS+certificate+on+a+Brother+printer+automat...
146•8organicbits•5h ago•43 comments

Explore the Hidden World of Sand

https://magnifiedsand.com/
106•RAAx707•4d ago•24 comments

Desk for people who work at home with a cat

https://soranews24.com/2026/03/27/japan-now-has-a-special-desk-for-people-who-work-at-home-with-a...
228•zdw•4h ago•89 comments

Building FireStriker: Making Civic Tech Free

https://firestriker.org/blog/building-firestriker-why-im-making-civic-tech-free
33•noleary•1d ago•7 comments

Telnyx Python SDK: Supply Chain Security Notice

https://telnyx.com/resources/telnyx-python-sdk-supply-chain-security-notice-march-2026
12•KomoD•1h ago•4 comments

Nashville library launches Memory Lab for digitizing home movies

https://www.axios.com/local/nashville/2026/03/16/nashville-library-digitize-home-movies
9•toomuchtodo•3d ago•1 comments

Meow.camera

https://meow.camera/#4258783365322591678
81•surprisetalk•5h ago•20 comments

Hold on to Your Hardware

https://xn--gckvb8fzb.com/hold-on-to-your-hardware/
492•LucidLynx•9h ago•404 comments

People inside Microsoft are fighting to drop mandatory Microsoft Account

https://www.windowscentral.com/microsoft/windows-11/people-inside-microsoft-are-fighting-to-drop-...
306•breve•5h ago•274 comments

Embracing Bayesian methods in clinical trials

https://jamanetwork.com/journals/jama/fullarticle/2847011
28•nextos•3d ago•1 comments

A Faster Alternative to Jq

https://micahkepe.com/blog/jsongrep/
335•pistolario•12h ago•207 comments

‘Energy independence feels practical’: Europeans building mini solar farms

https://www.euronews.com/2026/03/26/suddenly-energy-independence-feels-practical-europeans-are-bu...
114•vrganj•10h ago•113 comments

Ask HN: Founders of estonian e-businesses – is it worth it?

24•udl•3d ago•8 comments

Apple discontinues the Mac Pro

https://9to5mac.com/2026/03/26/apple-discontinues-the-mac-pro/
608•bentocorp•22h ago•570 comments

Can It Resolve DOOM? Game Engine in 2k DNS Records

https://core-jmp.org/2026/03/can-it-resolve-doom-game-engine-in-2000-dns-records/
13•Einenlum•3d ago•0 comments

Schedule tasks on the web

https://code.claude.com/docs/en/web-scheduled-tasks
259•iBelieve•14h ago•215 comments

Gzip decompression in 250 lines of Rust

https://iev.ee/blog/gzip-decompression-in-250-lines-of-rust/
80•vismit2000•3d ago•30 comments

21,864 Yugoslavian .yu domains

https://jacobfilipp.com/yu/
41•freediver•1d ago•58 comments

AI got the blame for the Iran school bombing. The truth is more worrying

https://www.theguardian.com/news/2026/mar/26/ai-got-the-blame-for-the-iran-school-bombing-the-tru...
203•cptroot•3h ago•143 comments

The 'paperwork flood': How I drowned a bureaucrat before dinner

https://sightlessscribbles.com/posts/the-paperwork-flood/
468•robin_reala•6h ago•386 comments

EMachines never obsolete PCs: More than a meme

https://dfarq.homeip.net/emachines-never-obsolete-pcs-more-than-a-meme/
47•zdw•3d ago•25 comments

Iran-linked hackers have breached FBI director's personal emails

https://www.cnn.com/2026/03/27/politics/iran-linked-hackers-fbi-director-patel
147•vrganj•3h ago•66 comments

Should QA exist?

https://www.rubick.com/should-qa-exist/
58•PretzelFisch•9h ago•89 comments

Everything old is new again: memory optimization

https://nibblestew.blogspot.com/2026/03/everything-old-is-new-again-memory.html
143•ibobev•4d ago•105 comments

Browser-based SFX synthesizer using WASM/Zig

https://knell.medieval.software/studio
10•galsjel•2h ago•1 comments

Apple says no one using Lockdown Mode has been hacked with spyware

https://techcrunch.com/2026/03/27/apple-says-no-one-using-lockdown-mode-has-been-hacked-with-spyw...
80•jbegley•3h ago•54 comments