frontpage.
newsnewestaskshowjobs

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

Serbia just elected the world's brainiest parliament

https://www.science.org/content/article/serbia-just-elected-world-s-brainiest-parliament
128•input_sh•1h ago•78 comments

Switch Lowering in GCC

https://xoranth.net/gcc-switch/
70•signa11•3h ago•7 comments

Digital Minimalism

https://vitalik.eth.limo/general/2026/10/31/digital_minimalism.html
70•wilbertliu•5h ago•40 comments

Molly(Signal fork) has not been updated since 3 months and is vulnerable

https://piefed.world/post/1503394
5•DeepLogin•57m ago•1 comments

Show HN: Marelleo, an open-source story box I built for my kids using ESP32

https://zebra.rodeo/en/blog/marelleo/
74•foOg•3d ago•27 comments

My favourite PowerMac is a Nintendo Wii

https://virtuallyfun.com/2026/10/29/my-favourite-powermac-is-a-nintendo-wii/
313•DHowett•17h ago•90 comments

Cloudflare Turnstile solver library (no headless browser required)

https://github.com/chris124567/cfsolve
224•costco•2d ago•65 comments

The $6.3B Binance hack was pulled off in just 20 minutes

https://www.wired.com/story/the-dollar63-billion-binance-hack-was-pulled-off-in-just-20-minutes/
467•domhudson•22h ago•320 comments

Northflank Breached

https://status.northflank.com
443•js4ever•20h ago•316 comments

Tell HN: Scribd Breached

234•x______________•8h ago•94 comments

AI, Lean, and the Future of Formal Verification, with Lean Creator Leo de Moura

https://thedataexchange.media/leo-de-moura-lean-aws/
43•datascientist•1d ago•5 comments

Breaking the open web won't stop the bad bots

https://www.techpolicy.press/breaking-the-open-web-wont-stop-the-bad-bots/
270•raybb•3d ago•117 comments

The oldest ice disappears and the Stone Age emerges from it

https://www.sciencenorway.no/archaeology-climate-culture/the-oldest-ice-is-disappearing-the-stone...
156•dxs•15h ago•60 comments

Show HN: A working Nintendo in ~1GB of Qwen weights

https://github.com/dbreunig/nesformer
256•dbreunig•18h ago•122 comments

Florilegium: Procedural Flowers in LaTeX

https://github.com/kevinraymond/florilegium
292•nanna•19h ago•47 comments

Longitudinal Changes InWearable-Captured PhysiologyBefore Sudden Cardiac Death

https://www.jacc.org/doi/epdf/10.1016/j.jaccas.2026.110397
38•brandonb•2d ago•20 comments

Backdoor in Claude Code for VS Code extension on the Cursor Marketplace

https://phorion.io/blog/offical-claude-code-vsx-compromise/
908•_chall•1d ago•533 comments

Sneezecount (2018)

https://sneezecount.joyfeed.com
6•NaOH•3d ago•0 comments

Infinite Mac: BeOS

https://blog.persistent.info/2026/10/infinite-mac-beos.html
163•ecliptik•15h ago•81 comments

Cisco gives engineer unlimited AI tokens to rewrite legacy code

https://fortune.com/2026/10/30/cisco-president-jeetu-patel-gen-z-27-year-old-unlimited-ai-tokens-...
204•taubek•21h ago•237 comments

Show HN: To Honor Sir Patrick Stewart, Enjoy the TNG Episode Guessing Game

https://tng.episodle.com/
195•francisofascii•11h ago•55 comments

The federated code forge

https://tangled.org/blog/forge/
294•zlliang•19h ago•85 comments

Jules Verne's Lost Novel

https://blue-continuum.com/verne-paris
119•dnetesn•15h ago•27 comments

Azure's Weakest Link – Five Full Cross-Tenant Compromises

https://www.binarysecurity.no/posts/2026/10/one-root-case
313•swq115•1d ago•58 comments

Brief History of PDP Computers

https://entropicthoughts.com/history-of-pdp-computers
32•ibobev•1d ago•14 comments

Sanstun: A sans-IO, parallel-friendly WireGuard implementation in Rust

https://www.firezone.dev/blog/introducing-sanstun
137•wh33zle•13h ago•27 comments

Double Buffering with Cloudflare Queues

https://bellone.com/technical/double-buffering-with-cloudflare-queues
43•b_llc•2d ago•5 comments

How long do you need to hold down the power button to turn off a PC?

https://www.osnews.com/story/146273/how-long-do-you-need-to-hold-down-the-power-button-to-turn-of...
24•Arodex•2h ago•2 comments

Trapped in the Technologist Factory

https://ideolalia.com/essays/trapped-in-the-technologist-factory.html
44•luu•2d ago•14 comments

Building an AI-native engineering org

https://twitter.com/sgondala2/status/2115832070274723875
160•sgondala_ycapp•1d ago•182 comments