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.

Keys Not Included: recovering the signing keys for US driver's license barcodes

https://ryan.science/blog/keys-not-included
109•Ryan5453•3h ago•35 comments

Nvidia announces native GPU programming in Rust

https://developer.nvidia.com/blog/introducing-cuda-rust-two-tracks-for-writing-gpu-kernels/
532•nonmaskable•19h ago•195 comments

Training a 4B model to produce 81% faster query plans than Postgres

https://rohanbansal.com/qorl
489•polyphilz•11h ago•101 comments

Comparison of Malloc() Algorithms

https://egbert.net/blog/articles/comparison-of-arena-architecture-in-malloc.html
20•egberts1•1d ago•0 comments

Xiaomi Mimo 2.6 live post-training dashboard

https://mimo.xiaomi.com/rl/
381•krackers•10h ago•93 comments

Backups Aren't Simple

https://filipovski.net/2026/09/16/backups-arent-simple.html
177•afilipovski•9h ago•90 comments

Developing provably correct Rust code with Verus

https://www.amazon.science/blog/developing-provably-correct-rust-code-with-verus
80•Betelbuddy•2d ago•10 comments

Small programming tricks

https://will-keleher.com/posts/small-programming-tricks-matter/
478•signa11•14h ago•206 comments

Breaking the 1.58-bit Barrier for Ternary LLMs

https://arxiv.org/abs/2609.16338
182•matt_d•9h ago•25 comments

A 32-year-old bug walks into a Telnet server

https://labs.watchtowr.com/a-32-year-old-bug-walks-into-a-telnet-server-gnu-inetutils-telnetd-cve...
34•paimapi•1d ago•10 comments

The Return of Sail Power: Cargo Ships Are Turning Back to the Wind

https://gcaptain.com/the-return-of-sail-power-cargo-ships-are-turning-back-to-the-wind/
64•gumby•5h ago•27 comments

The engineering behind the US Strategic Petroleum Reserve

https://johnjwang.com/post/2026/09/15/engineering-behind-us-strategic-petroleum-reserve
167•johnjwang•1d ago•69 comments

OpenSpec – A lightweight and configurable AI spec framework

https://openspec.dev/
120•etoxin•7h ago•48 comments

AWS says it can't restore some data from mideast facilities struck by Iran

https://www.wsj.com/world/middle-east/aws-says-it-cant-restore-some-data-from-mideast-facilities-...
335•berkeleyjunk•1d ago•265 comments

Performance Improvements in .NET 11

https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-11/
249•soheilpro•1d ago•43 comments

HarnessTax: How Much Does the Harness Matter for Coding Agents?

https://harnesstax.github.io/
95•matt_d•8h ago•31 comments

Show HN: An e-ink frame that hears birds and draws them as 1800s illustrations

https://github.com/arnegiacomo/fugleramme
2131•arnemunthekaas•1d ago•241 comments

PCB is brought to you by Fable 5

https://a6mzero.com/posts/this-pcb-is-brought-to-you-by-fable-5/
63•jasonpeacock•2d ago•24 comments

Reversing Factorio's RNG

https://gegell.github.io/posts/factorio-rng/
183•jheitmann•4d ago•22 comments

My temporary PHP fix from 2014 has nearly 20M installs. Today I'm deprecating it

https://jakeasmith.com/blog/http-build-url/
4•jakeasmith•1d ago•1 comments

Japan's book scene is moving from bookstores to libraries

https://untranslatedjp.substack.com/p/japans-book-scene-is-quietly-moving
158•herbertl•4d ago•67 comments

Jev Ultrafast: A browser agent with a dynamic, indexed action space

https://github.com/browser-use/jev-ultrafast
18•rahimnathwani•3h ago•1 comments

Part-human part-mouse brain developed in science breakthrough

https://www.bbc.com/news/articles/c60m3k28j81mo
22•marc__1•4h ago•18 comments

Anecdotally, programmers dislike "reduce"

https://evanhahn.com/posts/2026-09-13-programmers-dislike-reduce/
131•vinhnx•2d ago•200 comments

Reverse-engineered Jev-like model

https://github.com/vinnylarouge/jevlike
111•rochansinha•11h ago•16 comments

Cloudflare/Security-Audit-Skill

https://github.com/cloudflare/security-audit-skill
8•donk8r•1h ago•1 comments

Dream-RSI: Recursive Self-Improvement through Evolving Worlds

https://arxiv.org/abs/2609.14858
193•bananaflag•16h ago•49 comments

Monsanto's Cruel, and Dangerous, Monopolization on American Farming (2008)

https://www.vanityfair.com/news/2008/05/monsanto200805
48•kamaraju•4h ago•20 comments

Anatomy of a Texture

https://agentlien.github.io/texture/
86•Agentlien•15h ago•15 comments

DeepSeek-v4.1 Flash: Pushing the Limits of KV Cache Compression

https://zartbot.github.io/blog/model_arch/dsv41flash_arch/en.html
102•mfiguiere•4h ago•8 comments