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.

AWS Acquires DuckDB

https://ducklabs.com/news/2026/08/26/ducklabs-to-join-aws
476•onderkalaci•2h ago•108 comments

GLM-5.3-Flash

https://z.ai/blog/glm-5.3-flash
214•Philpax•1h ago•70 comments

Qwen3.8-Flash-Next: A New Architecture, Towards Ultimate Cost-Efficiency

https://qwen.ai/blog?id=qwen3.8-flash-next
272•tosh•2h ago•84 comments

WebMCP: Teaching Your Website to Talk to AI Agents

https://sreenathmenon.com/blog/2026-08-04-webmcp-teaching-websites-to-talk-to-ai-agents/
9•sreenathmenon•8m ago•0 comments

RAG Is Simpler Than You Think

https://www.lighthousenewsletter.com/p/rag-is-simpler-than-you-think
276•j0selit0•6h ago•117 comments

AI Is a Harsh Mistress

https://cacm.acm.org/opinion/ai-is-a-harsh-mistress-on-anima-machina-herd-acceptance-and-the-poli...
24•fscaramuzza•1h ago•4 comments

Taylor Farms: How One Company's Reach Became a National Risk

https://farmaction.us/taylorfarmsreport/
13•speckx•49m ago•0 comments

A curmudgeon tries a language server

https://entropicthoughts.com/curmudgeon-tries-language-server
45•crescit_eundo•2h ago•23 comments

Twitter Viewer – View Twitter Without Account

https://twitterwebviewer.com/
53•motownphilly•59m ago•17 comments

Meta reaches $16.68B settlement over social media harms to children

https://www.reuters.com/world/us/meta-settles-with-us-states-over-social-media-harms-2026-08-26/
230•bhouston•1h ago•178 comments

Oldinsurancemaps.net is now a Charter Project

https://openstreetmap.us/news/2026/08/oim-charter-project/
128•altilunium•6h ago•24 comments

Proliferate (YC S25) Is Hiring

https://www.ycombinator.com/companies/proliferate/jobs/OgpCKYJ-founding-product-engineer
1•pablo24602•3h ago

Nebula Sans

https://www.nebulasans.com
4•GavinAnderegg•7m ago•0 comments

AurionMail: E2EE suite (CryptPad/Stalwart) with single-password UX

https://github.com/AurionMail/docs
4•polo46•9m ago•0 comments

Z.ai confirms Ox Alpha is a new GLM-series model and will release its weights

https://www.bloomberg.com/news/articles/2026-08-26/china-s-z-ai-made-ox-alpha-stealth-model-that-...
337•garo-pro•5h ago•123 comments

Apple introduces M6 and M5 Ultra

https://www.apple.com/newsroom/2026/08/apple-introduces-m6-and-m5-ultra-for-a-big-leap-in-perform...
1260•interpol_p•1d ago•1197 comments

Beyond Recall and the Illusion of Competence

https://var0.xyz/posts/beyond-recall-and-the-illusion-of-competence.html
59•tuxie_•5h ago•19 comments

Stalking the Wily Hacker: 40 years later – Cliff Stoll [video]

https://www.youtube.com/watch?v=656058JxTM0
190•zoenolan•4d ago•59 comments

You could have invented PageRank

https://praveshkoirala.com/2026/08/26/you-could-have-invented-pagerank/
3•pkoird•42m ago•0 comments

Value Classes Still Need Compiler Sympathy

https://johan-sjolen.github.io/post/compiler-sympathy/compiler-sympathy/
67•lichtenberger•6h ago•30 comments

Take a Tour of SLAC

https://www6.slac.stanford.edu/public-tours
3•mooreds•49m ago•0 comments

FDA authorizes first wearable device that monitors ketone and blood sugar levels

https://www.fda.gov/news-events/press-announcements/fda-authorizes-first-wearable-device-continuo...
468•sunnynagra•20h ago•216 comments

Show HN: How much of Hacker News is AI?

https://hnstats.com
5•beekthos•55m ago•4 comments

Queryable Executables

https://fzakaria.com/2026/08/24/actually-queryable-executables
275•rguiscard•14h ago•74 comments

OpenAI Jalapeño: Better than Nvidia Blackwell

https://newsletter.semianalysis.com/p/openai-jalapeno-better-than-nvidia
555•bmulholland•1d ago•351 comments

Radiation link in flight attendant's breast cancer, French court finds

https://www.bbc.com/news/articles/cn0j3z6147jo
17•dazhbog•3h ago•1 comments

New Mac Studio with M5 Max and M5 Ultra

https://www.apple.com/newsroom/2026/08/apple-introduces-new-mac-studio-with-m5-max-and-m5-ultra/
809•interpol_p•1d ago•535 comments

LibreOffice 26.8 Released with Many Nice Improvements

https://wiki.documentfoundation.org/ReleaseNotes/26.8
43•DemiGuru•2h ago•3 comments

Harvest (IBM 7950): Supercomputer for cryptanalysis at the NSA in the Cold War

https://spectrum.ieee.org/cold-war-codebreaker-nsa-ibm
71•jnord•10h ago•20 comments

Black hole singularity is a surface not a point

https://arxiv.org/abs/2608.21590
289•raattgift•22h ago•201 comments