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.

Meta blocks human rights accounts from reaching audiences in Arabia and the UAE

https://www.alqst.org/ar/posts/1190
295•giuliomagnifico•1h ago•98 comments

Qwen3.7-Max: The Agent Frontier

https://qwen.ai/blog?id=qwen3.7
207•kevinsimper•3h ago•81 comments

Map of Metal

https://mapofmetal.com/
193•robin_reala•3h ago•61 comments

Saying Goodbye to Asm.js

https://spidermonkey.dev/blog/2026/05/20/saying-goodbye-to-asmjs.html
60•eqrion•2h ago•24 comments

Goodbye Visa and Mastercard: 130M Europeans switching to sovereign payment

https://www.lesnumeriques.com/banque-en-ligne/adieu-visa-et-mastercard-130-millions-d-europeens-b...
238•healsdata•1h ago•224 comments

Google's AI is being manipulated. The search giant is quietly fighting back

https://www.bbc.com/future/article/20260519-google-tackles-attempts-to-hack-its-ai-results
56•tigerlily•3h ago•25 comments

Everything in C is undefined behavior

https://blog.habets.se/2026/05/Everything-in-C-is-undefined-behavior.html
340•lycopodiopsida•8h ago•477 comments

America's Greatest Strategic Blunder: The Imprisonment of Qian Xuesen

https://danieltan.weblog.lol/2026/05/americas-greatest-strategic-blunder-the-imprisonment-of-qian...
46•danieltanfh95•1h ago•15 comments

Gemini 3.5 Flash

https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-3-5/
877•spectraldrift•20h ago•602 comments

FiveThirtyEight articles on the Internet Archive

https://fivethirtyeightindex.com/
289•ChocMontePy•12h ago•68 comments

When Fast Fourier Transform Meets Transformer for Image Restoration (2024)

https://github.com/deng-ai-lab/SFHformer
17•teleforce•2d ago•1 comments

I’ve built a virtual museum with nearly every operating system you can think of

https://virtualosmuseum.org/
876•andreww591•22h ago•188 comments

College students drown out AI-praising commencement speeches with boos

https://www.tomshardware.com/tech-industry/artificial-intelligence/college-students-drown-out-ai-...
196•iancmceachern•2h ago•165 comments

Japan is gripped by mass allergies. A 1950s project is to blame

https://www.bbc.com/future/article/20260515-the-1950s-blunder-which-causes-mass-hay-fever-in-japan
220•ranit•12h ago•108 comments

Anna's Archive Hit with $19.5M Default Judgment and Global Domain Takedown Order

https://torrentfreak.com/annas-archive-hit-with-19-5m-default-judgment-and-global-domain-takedown...
107•iamnothere•2h ago•72 comments

Show HN: Forge – Guardrails take an 8B model from 53% to 99% on agentic tasks

https://github.com/antoinezambelli/forge
577•zambelli•1d ago•206 comments

Google changes its search box

https://blog.google/products-and-platforms/products/search/search-io-2026/
621•berkeleyjunk•19h ago•856 comments

Infomaniak transitions to a foundation model to protect user data privacy

https://news.infomaniak.com/en/infomaniak-foundation-sovereign-cloud/
123•darktoto•8h ago•34 comments

Autoregressive next token prediction and KV Cache in transformers

https://medium.com/advanced-deep-learning/autoregressive-next-token-prediction-kv-cache-in-transf...
4•coarchitect•2d ago•0 comments

Remove-AI-Watermarks – CLI and library for removing AI watermarks from images

https://github.com/wiltodelta/remove-ai-watermarks
335•janalsncm•16h ago•205 comments

Nobody understands the point of hybrid cars [video]

https://www.youtube.com/watch?v=KnUFH5GX_fI
123•CHB0403085482•2d ago•89 comments

The Invention of Buses

https://worksinprogress.co/issue/the-invention-of-buses/
31•surprisetalk•2d ago•7 comments

No way to parse integers in C (2022)

https://blog.habets.se/2022/10/No-way-to-parse-integers-in-C.html
29•konmok•4h ago•21 comments

Gemini CLI will stop working from June 18, 2026

https://developers.googleblog.com/an-important-update-transitioning-gemini-cli-to-antigravity-cli/
309•primaprashant•20h ago•161 comments

Apple unveils new accessibility features

https://www.apple.com/newsroom/2026/05/apple-unveils-new-accessibility-features-and-updates-with-...
701•interpol_p•1d ago•368 comments

Mistral AI acquires Emmi AI

https://www.emmi.ai/news/mistral-ai-acquires-emmi-ai
297•doener•19h ago•90 comments

OpenAI Adopts Google's SynthID Watermark for AI Images with Verification Tool

https://openai.com/index/advancing-content-provenance/
311•smooke•18h ago•168 comments

Learnings from 100K lines of Rust with AI (2025)

https://zfhuang99.github.io/rust/claude%20code/codex/contracts/spec-driven%20development/2025/12/...
93•pramodbiligiri•4h ago•99 comments

RISC-V and Floating-Point

https://fprox.substack.com/p/risc-v-and-floating-point
45•hasheddan•2d ago•34 comments

CopyFail: From Pod to Host

https://xint.io/blog/copy-fail-pod-to-host
42•tptacek•21h ago•6 comments