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.

PC Gamer recommends RSS readers in a 37mb article that just keeps downloading

https://stuartbreckenridge.net/2026-03-19-pc-gamer-recommends-rss-readers-in-a-37mb-article/
523•JumpCrisscross•12h ago•253 comments

Can you get root with only a cigarette lighter? (2024)

https://www.da.vidbuchanan.co.uk/blog/dram-emfi.html
30•HeliumHydride•2d ago•3 comments

Tin Can, a 'landline' for kids

https://www.businessinsider.com/tin-can-landline-kids-cellphone-cell-alternative-how-2025-9
98•tejohnso•2d ago•74 comments

The gold standard of optimization: A look under the hood of RollerCoaster Tycoon

https://larstofus.com/2026/03/22/the-gold-standard-of-optimization-a-look-under-the-hood-of-rolle...
332•mariuz•12h ago•97 comments

The future of version control

https://bramcohen.com/p/manyana
496•c17r•16h ago•276 comments

Reports of code's death are greatly exaggerated

https://stevekrouse.com/precision
367•stevekrouse•20h ago•272 comments

The way CTRL-C in Postgres CLI cancels queries is incredibly hack-y

https://neon.com/blog/ctrl-c-in-psql-gives-me-the-heebie-jeebies
23•andrenotgiant•2d ago•0 comments

Why I love NixOS

https://www.birkey.co/2026-03-22-why-i-love-nixos.html
282•birkey•14h ago•196 comments

Project Nomad – Knowledge That Never Goes Offline

https://www.projectnomad.us
416•jensgk•18h ago•141 comments

Flash-MoE: Running a 397B Parameter Model on a Laptop

https://github.com/danveloper/flash-moe
340•mft_•19h ago•113 comments

Windows native app development is a mess

https://domenic.me/windows-native-dev/
401•domenicd•21h ago•383 comments

A Copy-Paste Bug That Broke PSpice AES-256 Encryption

https://jtsylve.blog/post/2026/03/18/PSpice-Encryption-Weakness
32•jtsylve•3d ago•8 comments

GoGoGrandparent (YC S16) is hiring Back end Engineers

https://www.ycombinator.com/companies/gogograndparent/jobs/2vbzAw8-backend-engineer
1•davidchl•3h ago

MAUI Is Coming to Linux

https://avaloniaui.net/blog/maui-avalonia-preview-1
195•DeathArrow•15h ago•99 comments

Intuitions for Tranformer Circuits

https://www.connorjdavis.com/p/intuitions-for-transformer-circuits
48•cjamsonhn•6h ago•3 comments

GrapheneOS will remain usable by anyone without requiring personal information

https://grapheneos.social/@GrapheneOS/116261301913660830
346•nothrowaways•10h ago•93 comments

Five Years of Running a Systems Reading Group at Microsoft

https://armaansood.com/posts/systems-reading-group/
151•Foe•14h ago•44 comments

What Young Workers Are Doing to AI-Proof Themselves

https://www.wsj.com/economy/jobs/ai-jobs-young-people-careers-14282284
119•wallflower•13h ago•193 comments

Migrating the American Express Payment Network, Twice

https://americanexpress.io/migrating-the-payments-network-twice/
64•madflojo•7h ago•18 comments

You are not your job

https://jry.io/writing/you-are-not-your-job/
131•jryio•15h ago•142 comments

They're Vibe-Coding Spam Now

https://tedium.co/2026/02/25/vibe-coded-email-spam/
74•raybb•9h ago•44 comments

LLMs predict my coffee

https://dynomight.net/coffee/
110•surprisetalk•4d ago•46 comments

Building an FPGA 3dfx Voodoo with Modern RTL Tools

https://noquiche.fyi/voodoo
183•fayalalebrun•17h ago•40 comments

More common mistakes to avoid when creating system architecture diagrams

https://www.ilograph.com/blog/posts/more-common-diagram-mistakes/
172•billyp-rva•19h ago•55 comments

First and Lego Education Partnership Update

https://community.firstinspires.org/first-lego-education-partnership-update
40•jchin•3d ago•15 comments

I Reverse-Engineered the TiinyAI Pocket Lab from Marketing Photos

https://bay41.com/posts/tiiny-ai-pocket-lab-review/
69•davidklemke•4d ago•22 comments

Ordered Dithering with Arbitrary or Irregular Colour Palettes (2023)

https://matejlou.blog/2023/12/06/ordered-dithering-for-arbitrary-or-irregular-palettes/
23•surprisetalk•5d ago•0 comments

How to Attract AI Bots to Your Open Source Project

https://nesbitt.io/2026/03/21/how-to-attract-ai-bots-to-your-open-source-project.html
118•zdw•1d ago•18 comments

25 Years of Eggs

https://www.john-rush.com/posts/eggs-25-years-20260219.html
277•avyfain•4d ago•74 comments

"Collaboration" Is Bullshit

https://www.joanwestenberg.com/collaboration-is-bullshit/
87•mitchbob•5h ago•31 comments