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.

If you're an LLM, please read this – Anna's Blog

https://annas-archive.gl/blog/llms-txt.html
95•janandonly•1h ago•30 comments

Antigravity 2.0 Tops the OpenSCAD Architectural 3D LLM Benchmark

https://modelrift.com/blog/openscad-llm-benchmark/
100•jetter•2h ago•48 comments

Steve Wozniak cheered after telling students they have AI – actual intelligence

https://www.businessinsider.com/steve-wozniak-apple-ai-graduation-speech-2026-5
216•signa11•3h ago•160 comments

Chess Invariants

http://muratbuffalo.blogspot.com/2026/05/chess-invariants.html
16•ingve•1h ago•8 comments

Project Hail Mary – Stellar Navigation Chart

https://valhovey.github.io/gaia-mary/
978•speleo•20h ago•205 comments

Slumber a TUI HTTP Client

https://slumber.lucaspickering.me
107•jicea•8h ago•38 comments

Circle Medical (YC S15) Is Hiring a Mobile Engineer

https://www.ycombinator.com/companies/circle-medical/jobs/onMKAG9-mobile-engineer-android
1•jboula•42m ago

The memory shortage is causing a repricing of consumer electronics

https://davidoks.blog/p/ai-is-killing-the-cheap-smartphone
268•d0ks•14h ago•327 comments

Show HN: ShadowCat – file transfer through QR Codes in a Browser

https://github.com/unprovable/ShadowCat
21•unprovable•1h ago•9 comments

The Companies Cutting Headcount for AI Will Lose to the Ones Who Didn't

https://libertas.software/en/knowledge-hub/19/the-companies-cutting-headcount-for-ai-will-lose-to...
3•soft-research•58m ago•0 comments

Cleve Moler has died

https://www.mathworks.com/company/aboutus/founders/clevemoler.html
148•mychele•10h ago•14 comments

CODA: Rewriting Transformer Blocks as GEMM-Epilogue Programs

https://arxiv.org/abs/2605.19269
83•matt_d•7h ago•8 comments

Blog ran on Ubuntu 16.04 for 10 years. I migrated it to FreeBSD

https://crocidb.com/post/this-blog-ran-on-ubuntu-16-04-for-10-years-i-migrated-it-to-freebsd/
312•speckx•17h ago•168 comments

The surprising story behind the first British person in space

https://www.bbc.com/culture/article/20260518-helen-sharman-the-story-behind-the-first-british-per...
72•xoxxala•1d ago•28 comments

Was my $48K GPU server worth it?

https://rosmine.ai/2026/05/13/was-my-48k-gpu-worth-it/
483•apwheele•3d ago•361 comments

Uv is fantastic, but its package management UX is a mess

https://www.loopwerk.io/articles/2026/uv-ux-mess/
241•nchagnet•15h ago•116 comments

Using Kagi Search with Low Vision

https://veroniiiica.com/using-kagi-search-with-low-vision/
216•speckx•17h ago•74 comments

Indexing a year of video locally on a 2021 MacBook with Gemma4-31B (50GB swap)

https://blog.simbastack.com/indexed-a-year-of-video-locally/
410•asenna•22h ago•121 comments

The death of the brick and mortar toy store

https://brainbaking.com/post/2026/05/the-death-of-the-brick-and-mortar-toy-store/
105•speckx•2d ago•114 comments

Lost Images from the 1945 Trinity Nuclear Test Restored

https://spectrum.ieee.org/trinity-nuclear-test
371•pseudolus•1d ago•108 comments

FSFE intervenes against Apple before EUCJ for the second time

https://fsfe.org/news/2026/news-20260519-01.en.html
39•M95D•2h ago•7 comments

Mycorrhizal Fungi, Nature's Key to Plant Survival and Success

https://pacifichorticulture.org/articles/mycorrhizal-fungi-natures-key-to-plant-survival-and-succ...
106•mooreds•1d ago•15 comments

Python 3.15: features that didn't make the headlines

https://blog.changs.co.uk/python-315-features-that-didnt-make-the-headlines.html
389•rbanffy•1d ago•198 comments

The case against boolean logic

https://abuseofnotation.github.io/boolean-thinking/
37•boris_m•1h ago•40 comments

Show HN: Freenet, a peer-to-peer platform for decentralized apps

https://freenet.org/
308•sanity•22h ago•189 comments

Flipper One – we need your help

https://blog.flipper.net/flipper-one-we-need-your-help/
1184•sandebert•1d ago•454 comments

Multi-Stream LLMs: new paper on parallelizing/separating prompts, thinking, I/O

https://arxiv.org/abs/2605.12460
123•atomicthumbs•17h ago•13 comments

Launch HN: Runtime (YC P26) – Sandboxed coding agents for everyone on a team

https://www.runtm.com/
92•gustrigos•20h ago•25 comments

Waymo pauses Atlanta service as its robotaxis keep driving into floods

https://techcrunch.com/2026/05/21/waymo-pauses-atlanta-service-as-its-robotaxis-keep-driving-into...
340•mattas•20h ago•415 comments

Spotify will start reserving concert tickets for fans

https://www.hollywoodreporter.com/music/music-industry-news/spotify-will-start-reserving-concert-...
159•elffjs•20h ago•319 comments