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.

Click

https://clickclickclick.click/
114•andrewzeno•1h ago•24 comments

Anthropic co-founder to present AI encyclical alongside Pope Leo XIV

https://www.vaticannews.va/en/pope/news/2026-05/pope-leo-xiv-first-encyclical-magnifica-humanitas...
38•cucho•1h ago•6 comments

Anthropic acquires Stainless

https://www.anthropic.com/news/anthropic-acquires-stainless
346•tomeraberbach•7h ago•238 comments

Hyperpolyglot Lisp: Common Lisp, Racket, Clojure, Emacs Lisp

https://hyperpolyglot.org/lisp
119•veqq•4h ago•24 comments

We stopped AI bot spam in our GitHub repo using Git's –author flag

https://archestra.ai/blog/only-responsible-ai
391•ildari•9h ago•186 comments

We let AIs run radio stations

https://andonlabs.com/blog/andon-fm
135•lukaspetersson•6h ago•146 comments

The Quiet Renovation at Bitwarden

https://blog.ppb1701.com/the-quiet-renovation-at-bitwarden
497•DaSHacka•2d ago•236 comments

Show HN: Files.md – Open-source alternative to Obsidian

https://github.com/zakirullin/files.md
525•zakirullin•10h ago•273 comments

The Futility of Lava Lamps: What Random Means

https://loup-vaillant.fr/articles/lava-lamps-and-randomness
37•birdculture•2d ago•20 comments

Elon Musk has lost his lawsuit against Sam Altman and OpenAI

https://techcrunch.com/2026/05/18/elon-musk-has-lost-his-lawsuit-against-sam-altman-and-openai/
741•nycdatasci•6h ago•377 comments

Agora-1: The Multi-Agent World Model

https://odyssey.ml/introducing-agora-1
73•olivercameron•5h ago•15 comments

Designing an FPGA Calculator from Scratch

https://baltazarstudios.com/calculator/
40•zdw•23h ago•2 comments

The FBI Wants to Buy Nationwide Access to License Plate Readers

https://www.404media.co/the-fbi-wants-to-buy-nationwide-access-to-license-plate-readers/
186•cdrnsf•4h ago•78 comments

Understanding Singleflight in Go

https://www.codingexplorations.com/blog/understanding-singleflight-in-golang-a-solution-for-elimi...
46•ghostbit•2d ago•6 comments

The Fil-C Optimized Calling Convention

https://fil-c.org/calling_convention
102•pizlonator•2d ago•17 comments

Two computers, one monitor, zero fiddling (2025)

https://alexplescan.com/posts/2025/08/16/kvm/
157•ankitg12•2d ago•88 comments

Earth's Radio Bubble: Every signal we've ever sent into space

https://www.thescientificdrop.com/2026/05/earths-radio-bubble-every-signal-weve.html
10•jonbaer•15h ago•4 comments

Coding on Paper

https://wickstrom.tech/2026-05-16-coding-on-paper.html
29•owickstrom•1d ago•1 comments

Show HN: Number Gacha, a gacha game distilled to its essence

https://isabisabel.com/gacha/
10•babel16•5d ago•2 comments

Cutting inference cold starts by 40x with LP, FUSE, C/R, and CUDA-checkpoint

https://modal.com/blog/truly-serverless-gpus
66•charles_irl•6h ago•15 comments

Loopmaster – Livecoding Music IDE

https://loopmaster.xyz/
51•stagas•5h ago•17 comments

Show HN: InsForge – Open-source Heroku for coding agents

https://github.com/InsForge/InsForge
28•mrcoldbrew•8h ago•6 comments

Iran starts Bitcoin-backed ship insurance for Hormuz strait

https://www.bloomberg.com/news/articles/2026-05-18/iran-starts-bitcoin-backed-shipping-insurance-...
246•srameshc•6h ago•365 comments

Shutterstock to pay $35M over hard-to-cancel subscriptions

https://www.ftc.gov/news-events/news/press-releases/2026/05/shutterstock-pay-35-million-settle-ft...
111•Lihh27•4h ago•47 comments

Project Glasswing: what Mythos showed us

https://blog.cloudflare.com/cyber-frontier-models/
268•Fysi•10h ago•101 comments

What Is Date:Italy?

http://aesthetikx.info/blog/date_italy.html
123•jollyjerry•2d ago•51 comments

Heirs and Spares in Early Modern France

https://www.historytoday.com/archive/feature/heirs-and-spares-early-modern-france
5•pepys•3d ago•0 comments

Haiku OS runs on M1 Macs now

https://discuss.haiku-os.org/t/my-haiku-arm64-progress/19044?page=2
266•tekkertje•5h ago•85 comments

Alignment pretraining: AI discourse creates self-fulfilling (mis)alignment

https://arxiv.org/abs/2601.10160
17•anigbrowl•2h ago•10 comments

Stratum: System-Hardware Co-Design with 3D-Stackable DRAM for Efficient Moe

https://dl.acm.org/doi/10.1145/3725843.3756043
17•rbanffy•3d ago•4 comments