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•11mo ago

Comments

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

The Whistleblower Who Uncovered the NSA's 'Big Brother Machine'

https://thereader.mitpress.mit.edu/the-whistleblower-who-uncovered-the-nsas-big-brother-machine/
88•the-mitr•1h ago•8 comments

Shai-Hulud Themed Malware Found in the PyTorch Lightning AI Training Library

https://semgrep.dev/blog/2026/malicious-dependency-in-pytorch-lightning-used-for-ai-training/
82•j12y•1h ago•13 comments

Belgium stops decommissioning nuclear power plants

https://dpa-international.com/general-news/urn:newsml:dpa.com:20090101:260430-930-14717/
550•mpweiher•5h ago•441 comments

Claude Code refuses requests or charges extra if your commits mention "OpenClaw"

https://twitter.com/theo/status/2049645973350363168
371•elmean•3h ago•255 comments

How an Oil Refinery Works

https://www.construction-physics.com/p/how-an-oil-refinery-works
164•chmaynard•3h ago•35 comments

Durable queues, streams, pub/sub, and a cron scheduler – inside your SQLite file

https://honker.dev/
61•ferriswil•3h ago•7 comments

I built a Game Boy emulator in F#

https://nickkossolapov.github.io/fame-boy/building-a-game-boy-emulator-in-fsharp/
13•elvis70•33m ago•2 comments

Spain's parliament will act against massive IP blockages by LaLiga

https://www.democrata.es/en/politics/congress-and-senate/congress-will-act-against-massive-ip-blo...
210•akyuu•2h ago•70 comments

You can beat the binary search

https://lemire.me/blog/2026/04/27/you-can-beat-the-binary-search/
127•vok•2d ago•60 comments

I aggregated 28 US Government auction sites into one search

https://bidprowl.com
163•scarsam•5h ago•48 comments

SatoshiGuesser – Roll for Bitcoin

https://github.com/Pathos0925/SatoshiGuesser
33•ilarum•1h ago•29 comments

A 1960s art school experiment that redefined creativity

https://thereader.mitpress.mit.edu/the-1960s-art-school-experiment-that-redefined-creativity/
30•pseudolus•2h ago•3 comments

Mozilla's opposition to Chrome's Prompt API

https://github.com/mozilla/standards-positions/issues/1213
425•jaffathecake•10h ago•171 comments

10Gb/s Ethernet: what I did to get it working in my home

https://www.gilesthomas.com/2026/04/10g-ethernet-what-i-did
30•gpjt•1d ago•2 comments

I scraped 1.94M Airbnb photos for opium dens, pet cameos, and messy kitchens

https://burla-cloud.github.io/examples/airbnb-burla-demo/
31•jmp1062•3h ago•4 comments

The Zig project's rationale for their anti-AI contribution policy

https://simonwillison.net/2026/Apr/30/zig-anti-ai/
569•lumpa•15h ago•342 comments

Granite 4.1: IBM's 8B Model Matching 32B MoE

https://firethering.com/granite-4-1-ibm-open-source-model-family/
231•steveharing1•7h ago•144 comments

Noctua releases official 3D CAD models for its cooling fans

https://www.noctua.at/en/3d-cad-models
435•embedding-shape•2d ago•97 comments

Where the goblins came from

https://openai.com/index/where-the-goblins-came-from/
951•ilreb•14h ago•572 comments

The Science Behind Honey's Eternal Shelf Life (2013)

https://www.smithsonianmag.com/science-nature/the-science-behind-honeys-eternal-shelf-life-1218690/
41•downbad_•4h ago•22 comments

Show HN: TRiP – a complete transformer engine in C built from scratch just by me

https://github.com/carlovalenti/TRiP
7•carlovalenti•59m ago•1 comments

CopyFail Was Not Disclosed to Distros

https://www.openwall.com/lists/oss-security/2026/04/30/10
8•ori_b•1h ago•0 comments

A Primer on Bézier Curves – So What Makes a Bézier Curve?

https://pomax.github.io/bezierinfo/
87•mostlyk•2d ago•19 comments

My Stratum-0 Atomic Clock

https://coverclock.blogspot.com/2017/05/my-stratum-0-atomic-clock_9.html
54•g0xA52A2A•2d ago•14 comments

Craig Venter has died

https://www.jcvi.org/media-center/j-craig-venter-genomics-pioneer-and-founder-jcvi-and-diploid-ge...
313•rdl•16h ago•74 comments

Because It Doesn't Have To

https://blog.computationalcomplexity.org/2026/04/because-it-doesnt-have-to.html
20•zdw•1d ago•5 comments

What can we gain by losing infinity?

https://www.quantamagazine.org/what-can-we-gain-by-losing-infinity-20260429/
69•Tomte•1d ago•78 comments

Kubereboot/Kured: Kubernetes Reboot Daemon

https://github.com/kubereboot/kured
3•ankitg12•53m ago•0 comments

GCC 16 has been released

https://gcc.gnu.org/gcc-16/changes.html
248•HeliumHydride•6h ago•40 comments

Meta in row after workers who saw smart glasses users having sex lose jobs

https://www.bbc.com/news/articles/c5y7yvgy0w6o
429•gorbachev•4h ago•316 comments