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.

Extra Big Ass Intelligence

https://www.extrabigassintelligence.com/
182•34679•4h ago•41 comments

Newgrounds.com – A community of games, music, and art

https://www.newgrounds.com/
174•azhenley•6h ago•49 comments

Court agrees with EFF: Utah's VPN law demands a technical impossibility

https://www.eff.org/deeplinks/2026/10/court-agrees-eff-utahs-vpn-law-demands-technical-impossibility
607•hn_acker•1d ago•264 comments

The Forgetful CPU (Linux on M4)

https://yuka.dev/blog-2026-10-02-linux-m4.html
193•signa11•17h ago•121 comments

Mike Tomlin spent 12 years building a Minecraft city

https://www.nytimes.com/athletic/7648198/2026/10/01/mike-tomlin-minecraft-nfl-coach/
423•CoryOndrejka•1d ago•102 comments

Cloudflare OHTTP gateway

https://blog.cloudflare.com/announcing-cloudflare-ohttp-gateway/
57•est•4h ago•12 comments

Understanding Frontier Artificial Intelligence

https://casp.ac/reports/intelligence-explosion
4•roversx•35m ago•0 comments

Make Tmux the OS

https://matduggan.com/what-does-my-dream-os-ui-look-like/
36•weaksauce•12h ago•18 comments

A 12-year sequence of telescope images of a star and four planets orbiting

https://bsky.app/profile/theplanetaryguy.com/post/3mwucf5ert22f
258•mariuz•20h ago•53 comments

An Update on Orion for Linux and Windows

https://blog.kagi.com/update-orion-linux-windows
23•pentagrama•2h ago•3 comments

Barcodes are about to go extinct

https://thehustle.co/originals/why-barcodes-are-about-to-go-extinct
19•rmason•11h ago•26 comments

Apple Pass Designer

https://developer.apple.com/pass-designer/
399•soheilpro•12h ago•244 comments

Loss of cell identity drives human aging: Two new papers

https://erictopol.substack.com/p/loss-of-cell-identity-drives-human
238•bookofjoe•1d ago•73 comments

From the creator of Redis; run LLM locally with ds4

https://dwarfstar.sh/
218•fibo•13h ago•56 comments

Muse Gadgets

https://gadgets.muse.ai
185•anant•12h ago•80 comments

With most information hidden, the game Stratego had stumped AI until now

https://arstechnica.com/science/2026/10/ai-finally-beat-the-best-stratego-player-in-history-and-d...
209•PaulHoule•17h ago•104 comments

FLUX 3 Image

https://bfl.ai/models/flux-3-image
328•minimaxir•1d ago•69 comments

Updates to Full Disk Access in macOS

https://developer.apple.com/news/?id=p6zjojqw
182•notfirstpost•12h ago•120 comments

Greg Kroah-Hartman – Security in the LLM Age [video]

https://www.youtube.com/watch?v=NnV_cWeoo5Q
230•usernomdeguerre•1d ago•66 comments

Sites in ChatGPT

https://chatgpt.com/features/sites/
260•polvi•1d ago•245 comments

Show HN: Giving Opus 5.5 a simulated paint canvas

https://stillwet.art/
268•alstonite•1d ago•88 comments

The Legend of von Neumann (1973) [pdf]

https://gwern.net/doc/math/1973-halmos.pdf
274•suopspaces•18h ago•148 comments

The Nintendo 64 Partner-N64 Development Kit

https://www.behindthecode.ca/partner-n64pc-dev-kit/
24•paulgerhardt•12h ago•2 comments

Venice’s failed war against Constantinople led to the first bond market

https://bigthink.com/books/a-fabulous-debt/
106•RickJWagner•18h ago•32 comments

OKI Develops 124-Layer PCB Technology

https://www.oki.com/global/press/2025/z25006e.html
25•luu•1d ago•13 comments

Billions of triangles redux

https://zeux.io/2026/09/30/billions-of-triangles-redux/
37•ibobev•2d ago•0 comments

One month coding with GLM 5.3 Flash

https://wagtail.org/blog/one-month-on-glm-53-flash/
148•ThibWeb•16h ago•109 comments

Show HN: Made an open-source Lego AI generator

https://github.com/anteloc/ldraw-nova
108•antelocnova•11h ago•44 comments

Nobody Is Listening on Port 8125

https://yeet.cx/blog/nobody-is-listening-on-8125
8•zasc•2d ago•2 comments

Where Is the Planet

http://whereistheplanet.com
26•andsoitis•7h ago•3 comments