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.

Attention Costs $100k

https://tornikeo.com/your-attention-costs-100k/
185•tornikeo•1h ago•82 comments

Google Play Integrity locks out alternative operating systems

https://consumerrights.wiki/w/Google_Play_Integrity_locks_out_alternative_operating_systems
325•DeepLogin•5h ago•125 comments

California to require businesses to provide customers with human support

https://calmatters.digitaldemocracy.org/bills/b-29278
120•DeepLogin•4h ago•42 comments

My OpenAI Dot made a discovery without me asking

https://echo.ls/dots-cwc/
651•maplet•11h ago•315 comments

BetterSPICE is a free, open-source SPICE circuit simulator

https://bspicesim.com/
137•zdw•7h ago•38 comments

My second-hand 5G router came with a Tailscale backdoor named after me

https://blog.euhe.eu/posts/second-hand-router-backdoor/
65•siguiriya•1h ago•30 comments

What broke when I enabled PQC for Git and SSH

https://nordlenord.github.io/my-shared-notes/?id=f86ed9e6f4ac17225617717a5a14255f
139•tukHelix•7h ago•51 comments

Did AI rediscover a cryptographic attack NSA had known since 2015?

https://an.dywa.ng/ecc.html
918•cbeuw•20h ago•629 comments

NSA, NIST, and post-quantum cryptography

https://blog.cr.yp.to/20220805-nsa.html
114•frostbyte64•5h ago•16 comments

Making cement in seconds just needs a big microwave

https://arstechnica.com/science/2026/12/making-cement-in-seconds-just-needs-a-really-big-microwave/
40•amooe•3d ago•19 comments

Make Me a Million-Bench: a benchmark where AIs build companies in the real world

https://andonlabs.com/evals/mmm-bench
156•lukaspetersson•11h ago•102 comments

FreeHand

https://microsoft.github.io/FreeHand/
91•jhack•6h ago•45 comments

CleanYourTV: Remove Ads and Bloat from Android TV and Google TV

https://cleanyour.tv
543•kls0e•20h ago•181 comments

How to find and upgrade SSH and PGP keys using P‑256, ED25519, and Curve25519

https://sethmlarson.dev/how-to-find-and-upgrade-256-bit-curve-keys
284•lumpa•13h ago•109 comments

Dufuna canoe: world's second-oldest known boat

https://en.wikipedia.org/wiki/Dufuna_canoe
5•bookofjoe•3d ago•0 comments

Into which trinitarian heresy hath ye fallen?

https://blesswrong.com
510•rachelshu•18h ago•362 comments

OpenAI's matrix multiplication paper solved a harder problem in computer science

https://www.newscientist.com/article/2602472-openai-solved-a-huge-problem-in-computer-science-and...
202•shinryuu•14h ago•40 comments

Counting large numbers of events in small floating point registers

https://dotat.at/@/2026-12-02-approx-count.html
3•todsacerdoti•2d ago•0 comments

Tinybrowser: A browser running directly in the browser

https://tinybrowser.ericc.ch/
135•auraham•10h ago•48 comments

Intellectual Debt After Generative AI

https://www.noemamag.com/intellectual-debt-after-generative-ai/
599•theanonymousone•1d ago•407 comments

Claude still falls for old jailbreak exploits

https://spectrum.ieee.org/anthropic-ipo-security
372•speckx•18h ago•221 comments

OpenAI: Smooth four-dimensional Poincaré conjecture disproved [pdf]

https://github.com/openai/math/blob/main/preprints/Exotic-four-spheres-detected-by-Khovanov-homol...
212•xhevahir•10h ago•136 comments

Rare books destroyed in truck crash, upending Oakland man's future

https://oaklandside.org/2026/11/25/pratum-rare-books-big-rig-crash-wuum/
256•gnabgib•18h ago•74 comments

Building Z86: Lessons from Implementing an Out-of-Order x86 CPU on FPGA

https://nand2mario.github.io/posts/2026/z86/
51•wicket•2d ago•3 comments

An OS with no threads: The Actor Model

https://www.timdbg.com/posts/dbgos-actor-model/
340•ingve•1d ago•151 comments

Silence at NIST, Panic on X: Who Gets to Tell Us Our Encryption Is Broken?

https://soghoian.net/blog/silence-at-nist-panic-on-x/
5•hellcow•2h ago•1 comments

The spectrum between coding and vibe coding

https://dmitryfrank.com/articles/ai_for_coding_in_2026
212•dimonomid•19h ago•120 comments

Diving Lock 21: a submerged Victorian canal lock on the St Lawrence River

https://davidgibbins.com/journal/2016/4/8/diving-lock-21-a-submerged-victorian-canal-lock-on-the-...
5•pombo•3d ago•0 comments

Show HN: Weavon, 99.93% Pandoc in 9.3 MB of Rust, 15-50x faster, PDF without TeX

https://github.com/weavon/weavon
318•deyvium•20h ago•138 comments

I just heard from a reliable source that ECC P-256 was broken

https://www.schneier.com/blog/archives/2026/12/nsa-urging-transition-to-post-quantum-cryptography...
463•arto•14h ago•198 comments