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

Canvas is down as ShinyHunters threatens to leak schools’ data

https://www.theverge.com/tech/926458/canvas-shinyhunters-breach
645•stefanpie•11h ago•387 comments

Cloudflare to cut about 20% workforce

https://www.reuters.com/business/world-at-work/cloudflare-cut-over-1100-jobs-2026-05-07/
741•PriorityLeft•13h ago•487 comments

Maybe you shouldn't install new software for a bit

https://xeiaso.net/blog/2026/abstain-from-install/
525•psxuaw•11h ago•277 comments

ClojureScript Gets Async/Await

https://clojurescript.org/news/2026-05-07-release
60•Borkdude•2h ago•15 comments

Dirtyfrag: Universal Linux LPE

https://www.openwall.com/lists/oss-security/2026/05/07/8
645•flipped•14h ago•260 comments

The map that keeps Burning Man honest

https://www.not-ship.com/burning-man-moop/
651•speckx•19h ago•318 comments

The surprisingly complex journey to text-selectable client-side generated PDFs

https://sdocs.dev/blogs/journey-to-pdf-generation
14•FailMore•1d ago•2 comments

Pinocchio is weirder than you remembered

https://storica.club/blog/pinocchio-in-italian/
148•cemsakarya•1d ago•64 comments

A polynomial autoencoder beats PCA on transformer embeddings

https://ivanpleshkov.dev/blog/polynomial-autoencoder/
43•timvisee•2d ago•14 comments

Agents need control flow, not more prompts

https://bsuh.bearblog.dev/agents-need-control-flow/
470•bsuh•17h ago•228 comments

Nintendo announces price increases for Nintendo Switch 2

https://www.nintendo.co.jp/corporate/release/en/2026/260508.html
12•razorbeamz•3h ago•7 comments

Dithering with CSS

https://ikesau.co/blog/dithering-with-css/
12•speckx•3d ago•6 comments

Floats Don't Agree with Themselves

https://docs.merca.earth/blog/floats-dont-agree-with-themselves
14•cremer•1d ago•3 comments

Blaise – A modern self-hosting zero-legacy Object Pascal compiler targeting QBE

https://github.com/graemeg/blaise
48•peter_d_sherman•5h ago•16 comments

Natural Language Autoencoders: Turning Claude's Thoughts into Text

https://www.anthropic.com/research/natural-language-autoencoders
281•instagraham•16h ago•94 comments

DeepSeek 4 Flash local inference engine for Metal

https://github.com/antirez/ds4
390•tamnd•18h ago•109 comments

AlphaEvolve: Gemini-powered coding agent scaling impact across fields

https://deepmind.google/blog/alphaevolve-impact/
294•berlianta•19h ago•123 comments

Ask HN: We just had an actual UUID v4 collision...

24•mittermayr•2h ago•25 comments

Singapore introduces caning for boys who bully others at school

https://www.theguardian.com/world/2026/may/06/singapore-caning-school-bullies
186•rustoo•2d ago•255 comments

Brazil's Pix payment system faces pressure from Visa and Mastercard

https://www.elciudadano.com/en/brazils-pix-payment-system-faces-pressure-from-visa-and-mastercard...
200•wslh•16h ago•178 comments

Plasticity and language in the anaesthetized human hippocampus

https://www.bcm.edu/news/researchers-discover-advanced-language-processing-in-the-unconscious-hum...
108•hhs•10h ago•42 comments

GNU IFUNC is the real culprit behind CVE-2024-3094

https://github.com/robertdfrench/ifuncd-up
79•foltik•10h ago•35 comments

Rumors of my death are slightly exaggerated

293•CliffStoll•1d ago•47 comments

Digging into Drama at the Document Foundation

https://lwn.net/Articles/1066418/
32•signa11•6h ago•4 comments

AI slop is killing online communities

https://rmoff.net/2026/05/06/ai-slop-is-killing-online-communities/
664•thm•15h ago•570 comments

Hardening Firefox with Claude Mythos Preview

https://hacks.mozilla.org/2026/05/behind-the-scenes-hardening-firefox/
193•HieronymusBosch•17h ago•90 comments

How to make SSE token streams resumable, cancellable, and multi-device

https://zknill.io/posts/everyone-said-sse-token-streaming-was-easy/
32•zknill•1d ago•3 comments

Two Home Affairs officials suspended after AI 'hallucinations' found

https://www.citizen.co.za/news/home-affairs-officials-suspended-ai-hallucinations/
99•jruohonen•14h ago•21 comments

Nonprofit hospitals spend billions on consultants with no clear effect

https://www.uchicagomedicine.org/forefront/research-and-discoveries-articles/nonprofit-hospitals-...
155•hhs•11h ago•53 comments

Los Alamos and the long path to detecting neutrinos

https://www.lanl.gov/media/publications/1663/from-ghost-particle-to-cosmic-messenger
32•LAsteNERD•1d ago•3 comments