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.

Gemini 4 Neon

https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-4-neon/
465•yigitdemirag•4h ago•436 comments

Unauthenticated remote code execution in Nginx

https://www.wiz.io/blog/nginx-http2-rce-vulnerabilities
1152•speedping•10h ago•512 comments

Gemini 4 Neon looks like an Opus 5.5 competitor

https://micjm.com/blog/gemini-4-neon-looks-like-a-top-model/
77•seizethecheese•1h ago•25 comments

AI Will Not Make You Rich (2025)

https://colossus.com/article/ai-will-not-make-you-rich/
10•madars•19m ago•1 comments

Multiple vulnerabilities in Regexp and String case conversion

https://www.ruby-lang.org/en/news/2026/11/18/multiple-vulnerabilities-in-regexp-and-string/
78•runesoerensen•2h ago•16 comments

Seven new models at scalable price-performance

https://microsoft.ai/news/microsoft-ignite-2026/
453•gmays•10h ago•317 comments

LLM assisted reverse engineering

https://www.slowchronicle.com/posts/llm-assisted-reverse-engineering
66•ioma8•3h ago•14 comments

AI agents ask better questions than KPMG accountants in audit trial

https://europeanbusinessmagazine.com/ai-agents-better-questions-kpmg/
365•Betelbuddy•10h ago•163 comments

Anthropic prices initial public offering

https://www.anthropic.com/news/anthropic-prices-initial-public-offering
60•surprisetalk•2h ago•28 comments

Inside Deutsche Bank

https://www.inside-db.com/
565•gyre007•10h ago•190 comments

DNS resolvers are the wrong place to fight piracy

https://techstackups.com/articles/quad9-leaves-france-dns-blocking/
604•ritzaco•12h ago•224 comments

Previous-Token Prediction Based LLM Inversion for Prompt Reconstruction

https://arxiv.org/abs/2607.29378
7•dalmo3•43m ago•3 comments

Fable: Written, painted and directed by Claude Fable 5.2

https://claudia.gallery/fable/
33•CharlesW•1h ago•28 comments

DaisyRose-27B

https://www.radixark.com/blog/daisyrose-27b
140•de_sty•6h ago•41 comments

Dumping an AES key from a MyQ garage opener to stop rebooting when offline

https://kusha.me/blog/stop_myq_homebridge_819lmb_rebooting/
41•kusha•2d ago•16 comments

We need smart people who give a shit

https://violetpixel.com/blog/2026-11-17-we-need-smart-people-who-give-a-shit/
228•ExMachina73•2h ago•117 comments

FailTrace – Reproduce a failed GitHub Actions run locally from its URL

https://github.com/Ri4dH/failtrace
4•ri4dh•39m ago•0 comments

Advancing chip design with OpenAI models

https://openai.com/index/advancing-chip-design-with-our-models/
164•vighneshiyer•8h ago•104 comments

Genie 4 is now available

https://blog.google/innovation-and-ai/models-and-research/google-deepmind/genie-4-now-available-p...
190•leumon•7h ago•143 comments

Cuttlefish on Mac: Android's Virtual Device Framework on Apple Silicon

https://engineering.fb.com/2026/11/13/android/cuttlefish-on-mac/
43•acossta•3d ago•8 comments

The Cambridge Dictionary has named ‘human’ as the Word of the Year 2026

https://www.cam.ac.uk/news/cambridge-dictionary-reveals-word-of-the-year-2026
238•DeepLogin•11h ago•173 comments

Show HN: ExitPath – Open-source ways out of Slack, Notion and Microsoft 365

https://exitpath-ruddy.vercel.app/
167•zerocool0101•10h ago•50 comments

A Collage Showing 49 Drill Holes Made by NASA's Curiosity Mars Rover

https://science.nasa.gov/photojournal/a-collage-showing-49-drill-holes-made-by-nasas-curiosity-ma...
33•wawayanda•2d ago•2 comments

Collisions in Hash Functions

https://collisions.zksecurity.xyz/
5•baby•2d ago•0 comments

Show HN: Open-source, real-time object tracking for live video feeds

https://github.com/aryamandarda/tamserve
47•aryaman_darda•2d ago•2 comments

Show HN: Take Voyager 1 apart, down to a single memory chip

https://rshekhar.com/voyager/
155•raj-shekhar•9h ago•34 comments

Show HN: ADE Index – a sourced and ranked index of 975 agentic coding tools

https://adeindex.com
3•jonnyasmar•36m ago•2 comments

Launch HN: Maritime (YC F26) – A managed cloud for production AI agents

44•ashriv•8h ago•34 comments

Software companies are trying to kill home computing?

https://lateblt.livejournal.com/526188.html
116•sammatilda•2h ago•76 comments

Palo Alto Networks to Acquire Applied Compute for $4.5B

https://investors.paloaltonetworks.com/news-releases/news-release-details/palo-alto-networks-acqu...
11•alpb•2h ago•0 comments