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.

Potential session/cache leakage between workspace instances or consumer accounts

https://github.com/anthropics/claude-code/issues/74066
17•chatmasta•33m ago•6 comments

Explanation of everything you can see in htop/top on Linux

https://peteris.rocks/blog/htop/
59•theanonymousone•2h ago•11 comments

Astrophysicists Puzzle over Webb’s New Universe

https://www.quantamagazine.org/astrophysicists-puzzle-over-webbs-new-universe-20260702/
104•jnord•5h ago•51 comments

Maybe you should learn something

https://www.marginalia.nu/log/a_135_learn/
234•tylerdane•11h ago•114 comments

Postgres data stored in Parquet on S3: LTAP architecture explained

https://www.databricks.com/blog/lakebase-ltap-rethinking-database-storage
85•andrenotgiant•3d ago•24 comments

The Vespa at 80: Why the Italian scooter remains the coolest thing on 2 wheels

https://www.cbc.ca/news/world/vespa-italy-postwar-design-9.7252641
62•cf100clunk•3d ago•56 comments

The bottleneck might be the air in the room

https://blog.mikebowler.ca/2026/07/03/co2-and-decision-making/
512•gslin•8h ago•312 comments

Performance per dollar is getting faster and cheaper

https://www.wafer.ai/blog/glm52-amd
298•latchkey•16h ago•112 comments

Leanstral 1.5: Proof abundance for all

https://mistral.ai/news/leanstral-1-5/
297•programLyrique•16h ago•86 comments

Costco is the anti-Amazon

https://phenomenalworld.org/analysis/the-anti-amazon/
467•bookofjoe•23h ago•426 comments

Mir Books – Books from the Soviet Era

https://mirtitles.org
123•clmul•3d ago•52 comments

Giant trees have no trouble pumping water to top branches: new research

https://news.exeter.ac.uk/faculty-of-environment-science-and-economy/giant-trees-have-no-trouble-...
233•hhs•15h ago•104 comments

Night Witches – all-female Soviet aviator regiment WW2

https://en.wikipedia.org/wiki/Night_Witches
34•gverrilla•3d ago•11 comments

Steam Controller Auto-Charge – pilot to magnetic charging puck using CV

https://github.com/FossPrime/Steam-Controller-Auto-Charge
168•zdw•15h ago•36 comments

Agentic coding notes from Galapagos Island

https://danluu.com/ai-coding/#appendix-agentic-loops-and-writing-this-post
135•gm678•10h ago•63 comments

FreeBSD ate my RAM

https://crocidb.com/post/freebsd-ate-my-ram/
168•theanonymousone•19h ago•68 comments

Jamesob's guide to running SOTA LLMs locally

https://github.com/jamesob/local-llm
375•livestyle•23h ago•168 comments

MSI Center – How to gain SYSTEM privileges in seconds

https://mrbruh.com/msicenter/
116•MrBruh•13h ago•48 comments

Synthesis is harder than analysis

https://surfingcomplexity.blog/2026/07/03/synthesis-is-harder-than-analysis/
117•azhenley•11h ago•30 comments

SearXNG: A free internet metasearch engine

https://github.com/searxng/searxng
246•theanonymousone•18h ago•66 comments

Breaking the Bird Barrier: Scientist Decodes Zebra Finch Language

https://www.freepressjournal.in/education/breaking-the-bird-barrier-scientist-decodes-zebra-finch...
7•yyyk•3d ago•0 comments

The firefighting system of the Van der Heyden brothers in 17th century Amsterdam

https://worksinprogress.co/issue/how-amsterdam-invented-the-fire-department/
113•zdw•15h ago•21 comments

2026 Unslop AI-Written Fiction Contest Results

https://www.hyperstitionai.com/unslop-results
35•networked•8h ago•99 comments

Odin, Wikipedia and engagement farming

https://katamari64.se/posts/2026/odin-wikipedia/
198•stock_toaster•15h ago•271 comments

New serious vulnerabilities spiked around release of Claude Mythos Preview

https://epoch.ai/data-insights/cve-severity-spike
132•cubefox•17h ago•57 comments

Ship traces journey Spanish Armada sailors made in 1588

https://www.irishtimes.com/ireland/2026/06/30/it-is-a-huge-honour-ship-traces-journey-spanish-arm...
17•austinallegro•3d ago•8 comments

How working memory could give rise to consciousness

https://www.scientificamerican.com/article/how-working-memory-could-give-rise-to-consciousness/
6•bookofjoe•34m ago•9 comments

The Scanline Sweeper: A Glyph Rendering Algorithm [pdf]

https://rookandpossum.com/papers/scanline_sweeper_preprint.pdf
25•kouosi•3d ago•2 comments

Gone but Not Forgotten: Recovering the Dead Web

https://blog.archive.org/2026/04/23/gone-but-not-forgotten-recovering-the-dead-web/
89•wslh•3d ago•33 comments

Soatok's Informal Guide to Threat Models

https://soatok.blog/2026/06/30/soatoks-informal-guide-to-threat-models/
113•zdw•14h ago•27 comments