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.

Bored of eating your own dogfood? Try smelling your own farts

https://shkspr.mobi/blog/2026/03/bored-of-eating-your-own-dogfood-try-smelling-your-own-farts/
163•ColinWright•2h ago•74 comments

Flash-Moe: Running a 397B Parameter Model on a Mac with 48GB RAM

https://github.com/danveloper/flash-moe
158•mft_•4h ago•54 comments

Building an FPGA 3dfx Voodoo with Modern RTL Tools

https://noquiche.fyi/voodoo
53•fayalalebrun•2h ago•4 comments

Project Nomad – Knowledge That Never Goes Offline

https://www.projectnomad.us
87•jensgk•3h ago•11 comments

Convincing Is Not Persuading

https://blog.alaindichiappari.dev/p/convincing-is-not-persuading
26•alainrk•2h ago•16 comments

More common mistakes to avoid when creating system architecture diagrams

https://www.ilograph.com/blog/posts/more-common-diagram-mistakes/
49•billyp-rva•3h ago•18 comments

Brute-Forcing My Algorithmic Ignorance with an LLM in 7 Days

http://blog.dominikrudnik.pl/my-google-recruitment-journey-part-1
38•qikcik•3h ago•12 comments

iBook Clamshell

https://www.ibook-clamshell.com/index.php/en/
20•polishdude20•1h ago•9 comments

25 Years of Eggs

https://www.john-rush.com/posts/eggs-25-years-20260219.html
143•avyfain•3d ago•45 comments

A Review of Dice That Came with the White Castle

https://boardgamegeek.com/thread/3533812/a-review-of-dice-that-came-with-the-white-castle
41•doener•3d ago•4 comments

Apple's intentional crippling of Mobile Safari continues

https://pwa.gripe/
55•xd1936•2h ago•42 comments

$ teebot.dev – from terminal to tee in 6 seconds

https://teebot.dev
21•foxpress•3h ago•24 comments

Hormuz Minesweeper – Are you tired of winning?

https://hormuz.pythonic.ninja/
494•PythonicNinja•6h ago•331 comments

The IBM scientist who rewrote the rules of information just won a Turing Award

https://www.ibm.com/think/news/ibm-scientist-charles-bennett-turing-award
17•rbanffy•3h ago•2 comments

Node.js worker threads are problematic, but they work great for us

https://www.inngest.com/blog/node-worker-threads
36•goodoldneon•3d ago•14 comments

My first patch to the Linux kernel

https://pooladkhay.com/posts/first-kernel-patch/
160•pooladkhay•2d ago•31 comments

Monuses and Heaps

https://doisinkidney.com/posts/2026-03-03-monus-heaps.html
31•aebtebeten•3d ago•1 comments

Why Lab Coats Turned White

https://www.asimov.press/p/lab-coat
17•mailyk•3d ago•4 comments

Tinybox – A powerful computer for deep learning

https://tinygrad.org/#tinybox
542•albelfio•19h ago•316 comments

Some things just take time

https://lucumr.pocoo.org/2026/3/20/some-things-just-take-time/
776•vaylian•1d ago•249 comments

How We Synchronized Editing for Rec Room's Multiplayer Scripting System

https://www.tyleo.com/blog/how-we-synchronized-editing-for-rec-rooms-multiplayer-scripting-system
11•tyleo•3h ago•8 comments

The three pillars of JavaScript bloat

https://43081j.com/2026/03/three-pillars-of-javascript-bloat
403•onlyspaceghost•13h ago•237 comments

Professional video editing, right in the browser with WebGPU and WASM

https://tooscut.app/
317•mohebifar•18h ago•115 comments

Chest Fridge (2009)

https://mtbest.net/chest-fridge/
153•wolfi1•14h ago•80 comments

HopTab–free,open source macOS app switcher and tiler that replaces Cmd+Tab

https://www.royalbhati.com/hoptab
76•robhati•9h ago•23 comments

Floci – A free, open-source local AWS emulator

https://github.com/hectorvent/floci
241•shaicoleman•17h ago•80 comments

Turns out your coffee addiction may be doing your brain a favor

https://www.theregister.com/2026/03/21/turns_out_your_coffee_addiction/
39•Bender•2h ago•18 comments

Electronics for Kids, 2nd Edition

https://nostarch.com/electronics-for-kids-2e
233•0x54MUR41•3d ago•48 comments

'Miracle': Europe reconnects with lost spacecraft

https://phys.org/news/2026-03-miracle-europe-reconnects-lost-spacecraft.html
79•vrganj•5h ago•30 comments

Boomloom: Think with your hands

https://www.theboomloom.com
151•rasengan0•1d ago•16 comments