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

The intracies of modern camera lens repair (2024)

https://salvagedcircuitry.com/sigma-45mm.html
75•transistor-man•2h ago•16 comments

How LLMs Work

https://www.0xkato.xyz/how-llms-actually-work/
19•0xkato•2d ago•2 comments

pg_durable: Microsoft open sources in-database durable execution

https://github.com/microsoft/pg_durable
343•coffeemug•11h ago•80 comments

Astronauts told to return to ISS after sheltering over air leak repairs

https://www.bbc.com/news/live/c4g44ew3g1kt
365•janpot•12h ago•238 comments

New method turns ocean water into drinking water, without waste

https://www.rochester.edu/newscenter/what-is-desalination-definition-ocean-water-704732/
281•speckx•12h ago•122 comments

Gemma 4 QAT models: Optimizing compression for mobile and laptop efficiency

https://blog.google/innovation-and-ai/technology/developers-tools/quantization-aware-training-gem...
287•theanonymousone•10h ago•89 comments

Show HN: ABC Classic 100 Rankings visualised

https://classic100.gotski.workers.dev/
17•gotski•1h ago•11 comments

Mouseless – keyboard-driven control of macOS/Linux/Windows

https://mouseless.click
473•riddley•2d ago•199 comments

Did Claude increase bugs in rsync?

https://alexispurslane.github.io/rsync-analysis/
331•logicprog•14h ago•338 comments

Europe's largest Copper Age tomb: children's bones show ancient health crisis

https://phys.org/news/2026-05-europe-largest-copper-age-tomb.html
17•gmays•1d ago•4 comments

My Agent Skill for Test-Driven Development

https://www.saturnci.com/my-agent-skill-for-test-driven-development.html
141•laxmena•1d ago•57 comments

Nordstjernen Web Browser 1.0.0 released

https://github.com/nordstjernen-web/nordstjernen/releases/tag/1.0.0
17•andreasrosdal•3h ago•10 comments

The Quiet Numbers Station: Decoding Nineteen Years of GPS Cryptography

https://www.benthamsgaze.org/2026/06/02/the-quiet-numbers-station-decoding-nineteen-years-of-gps-...
70•lordgilman•14h ago•67 comments

Gov.uk has replaced Stripe with Dutch provider Adyen

https://www.theregister.com/public-sector/2026/06/04/govuk-goes-dutch-on-payments-as-it-dumps-str...
370•toomuchtodo•10h ago•131 comments

Ask HN: What was your "oh shit" moment with GenAI?

193•andrehacker•1d ago•426 comments

Conventional Commits encourages focus on the wrong things

https://sumnerevans.com/posts/software-engineering/stop-using-conventional-commits/
274•jsve•11h ago•213 comments

Transformers are inherently succinct

https://openreview.net/pdf?id=Yxz92UuPLQ
99•brandonb•8h ago•31 comments

Launch HN: General Instinct (YC P26) – Frontier models on edge devices

46•guanming0717•10h ago•14 comments

India's surprise baby bust

https://www.economist.com/leaders/2026/06/04/indias-surprise-baby-bust-is-a-warning-to-the-world
143•hakonbogen•12h ago•630 comments

Cooldown Support for Ruby Bundler

https://blog.rubygems.org/2026/06/03/cooldown-let-new-gems-be-vetted.html
147•calyhre•2d ago•41 comments

I tested every IP KVM in my Homelab

https://www.jeffgeerling.com/blog/2026/i-tested-every-ip-kvm/
250•vquemener•12h ago•69 comments

Aging and Eye Problems

https://ldstephens.net/posts/aging-and-eye-problems/
63•speckx•8h ago•28 comments

"Maybe later" was a feature

https://arnorhs.dev/posts/2026-06-04/maybe-later-was-a-feature/
79•arnorhs•1d ago•28 comments

Tracing a powerful GNSS interference source over Europe

https://arxiv.org/abs/2606.03673
366•mimorigasaka•18h ago•200 comments

C++: The Documentary

https://herbsutter.com/2026/06/04/c-the-documentary-released-today/
383•ingve•22h ago•276 comments

Inside FAISS: Billion-Scale Similarity Search

https://fremaconsulting.ch/blog/faiss
51•tohms•1d ago•4 comments

The perils of UUID primary keys in SQLite

https://andersmurphy.com/2026/06/05/the-perils-of-uuid-primary-keys-in-sqlite.html
26•emschwartz•4h ago•18 comments

South Korean forums will need to scan every images with AI censorship tools

https://discuss.privacyguides.net/t/south-korean-online-communities-will-need-to-scan-every-image...
233•Cider9986•1d ago•139 comments

Redis 8.8: New array data structure, rate limiter, performance improvements

https://redis.io/blog/announcing-redis-8-8/
205•ksec•2d ago•92 comments

Mantine-datatable (and others) compromised – owner account suspended

https://github.com/icflorescu/mantine-datatable/discussions/813
63•justsomehuman•10h ago•24 comments