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.

Anatomy of an AI Kill Chain

https://ai-killchain.airwars.org
116•tastyface•2h ago•56 comments

NSA advises immediate transition to post-quantum cryptography

https://www.nsa.gov/Press-Room/Press-Releases-Statements/Press-Release-View/Article/4662430/nsa-a...
2305•intunderflow•18h ago•1122 comments

Post Quantum WireGuard, WireGuard v2, ongoing AI discoveries, and so forth

https://lists.zx2c4.com/pipermail/wireguard/2026-December/009817.html
815•cpach•13h ago•179 comments

What to Make of the NSA Advisory

https://words.filippo.io/nsa-advisory/
922•jvdheyden•15h ago•264 comments

Show HN: misa77 – Up to 3x faster decompression than zstd, with better ratios

https://github.com/welcome-to-the-sunny-side/misa77/tree/main
29•nonadhocproblem•2h ago•3 comments

Agent harnesses need their eBPF

https://ut-infraai.github.io/2026/12/01/agent-harnesses-need-their-ebpf/
163•ronyw7•6h ago•36 comments

The E-ink Computing Challenge

https://riddle.press/the-e-ink-computing-challenge/
182•wilabroard•2d ago•84 comments

The end of freelance web development

https://marcarea.com/weblog/2026/11/04/ai-and-me
516•vishnugupta•16h ago•437 comments

HTML esoterica – en-GB vs. en_GB

https://www.htmhell.dev/adventcalendar/2026/1/
72•edent•2d ago•15 comments

Nvidia partners with SpaceX to launch datacenters into space

https://www.nextplatform.com/compute/2026/12/02/nvidia-partners-with-spacex-to-launch-datacenters...
473•jonbaer•18h ago•1291 comments

Joint statement on transition to post-quantum cryptography

https://openai.com/index/joint-statement-post-quantum-cryptography/
352•thomasm6m6•6h ago•310 comments

After a year of tinkering, my factory is finally running smoothly

https://twitter.com/Steve_Yegge/status/2127977854944288923
222•flimp•12h ago•294 comments

Jiga (YC W21) Is Hiring Staff Product Manager to Make Manufacturing Great Again

https://jiga.io/about-us/
1•grmmph•3h ago

The Michigan Left is a clever highway fix for cutting left-turn crashes

https://www.jalopnik.com/2329199/highway-michigan-left-turn-crashes-median-u-turn/
231•NaOH•1d ago•268 comments

Memory Safety for Skeptics – Queue

https://queue.acm.org/doi/10.1145/3773095
14•rbanffy•2d ago•2 comments

Why the NSA Wants You to Hurry

https://unmitigatedrisk.com/2026/12/why-the-nsa-wants-you-to-hurry/
78•hasheddan•9h ago•38 comments

Optimizing Decision Models by Asking Side Questions

https://www.cmpnd.ai/blog/optimizing-decision-models-side-questions.html
7•dbreunig•1d ago•2 comments

Zig gets improved float parser/formatter

https://codeberg.org/ziglang/zig/pulls/37793
242•Retro_Dev•15h ago•57 comments

Show HN: Self-hosted Docker image registry. One container, two simple accounts

https://github.com/dellarb/registreasy
35•dellarb•5h ago•17 comments

Anthropic and OpenAI should release their secret internal models

https://www.dwarkesh.com/p/no-internal-external-gap
743•jekude•14h ago•482 comments

Laravel Go

https://github.com/laravel/go
237•adrianthedev•16h ago•180 comments

Magical tales have a longer history than previously suspected: research (2016)

https://www.smithsonianmag.com/smart-news/fairy-tales-could-be-older-ever-imagined-180957882/
22•cybermango•2d ago•23 comments

Amber Eye: a Slay the Spire engine approaching top-level play

https://8e9f.github.io/amber_eye/
234•gcmeplz•16h ago•101 comments

B.C. home suspected of hosting North Korean 'laptop farm' raided by RCMP

https://www.cbc.ca/news/canada/north-korea-remote-workers-home-raid-9.7432396
204•cf100clunk•18h ago•196 comments

Navigating Stanisław Lem

https://pankajpipada.com/posts/2026-11-30-stanislaw-lem-works/
85•ppipada•1d ago•30 comments

Ask HN: Who is hiring? (December 2026)

206•whoishiring•1d ago•220 comments

Dfdu: Fast disk usage browser for the terminal and desktop

https://github.com/jordond/dfdu
61•b--l•1d ago•17 comments

Show HN: Open-source guitar practice studio with stem extraction and NAM rigs

https://guitarist.tools
140•mgechev•13h ago•42 comments

AI adoption is an org design problem

https://cottageindustry.ai/p/ai-adoption-is-an-org-design-problem
166•kevinmannix•16h ago•143 comments

Hadwiger's Covering Conjecture in Three Dimensions

https://research.google/pubs/hadwigers-covering-conjecture-in-three-dimensions/
3•dvaplima•2d ago•1 comments