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•12mo ago

Comments

LegionMammal978•12mo 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•12mo 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•12mo 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.

Googlebook

https://googlebook.google/
314•tambourine_man•2h ago•447 comments

CERT is releasing six CVEs for serious security vulnerabilities in dnsmasq

https://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2026q2/018471.html
112•chizhik-pyzhik•2h ago•29 comments

The Rise of the Bullshittery

https://xn--gckvb8fzb.com/the-rise-of-the-bullshittery/
61•dxs•56m ago•28 comments

Show HN: Needle: We Distilled Gemini Tool Calling into a 26M Model

https://github.com/cactus-compute/needle
86•HenryNdubuaku•2h ago•18 comments

Why senior developers fail to communicate their expertise

https://www.nair.sh/guides-and-opinions/communicating-your-expertise/why-senior-developers-fail-t...
193•nilirl•5h ago•88 comments

The Future of Obsidian Plugins

https://obsidian.md/blog/future-of-plugins/
189•xz18r•4h ago•70 comments

Rendering the Sky, Sunsets, and Planets

https://blog.maximeheckel.com/posts/on-rendering-the-sky-sunsets-and-planets/
335•ibobev•6h ago•30 comments

Quack: The DuckDB Client-Server Protocol

https://duckdb.org/2026/05/12/quack-remote-protocol
59•aduffy•2h ago•4 comments

Dead.Letter (CVE-2026-45185) – How XBOW found an unauthenticated RCE on Exim

https://xbow.com/blog/dead-letter-cve-2026-45185-xbow-found-rce-exim
41•fedek_•2h ago•14 comments

Bambu Lab is abusing the open source social contract

https://www.jeffgeerling.com/blog/2026/bambu-lab-abusing-open-source-social-contract/
869•rubenbe•5h ago•299 comments

Learning Software Architecture

https://matklad.github.io/2026/05/12/software-architecture.html
465•surprisetalk•10h ago•95 comments

When life gives you lemons, write better error messages

https://wix-ux.com/when-life-gives-you-lemons-write-better-error-messages-46c5223e1a2f
68•luispa•3d ago•21 comments

Show HN: Agentic interface for mainframes and COBOL

https://www.hypercubic.ai/hopper
29•sai18•3h ago•13 comments

Instructure pays ransom to Canvas hackers

https://www.insidehighered.com/news/tech-innovation/administrative-tech/2026/05/11/instructure-pa...
169•Cider9986•17h ago•152 comments

Snowflake Postgres, Lakebase, HorizonDB: Picking the Lock-In You Want

https://thebuild.com/blog/2026/05/12/snowflake-postgres-lakebase-horizondb-picking-the-lock-in-yo...
5•samaysharma•29m ago•0 comments

We accidentally recreated old Facebook

https://amrshawky.com/posts/we-accidentally-recreated-fb/
15•amr_shawky•2d ago•3 comments

Show HN: Statewright – Visual state machines that make AI agents reliable

https://github.com/statewright/statewright
27•azurewraith•5h ago•6 comments

Screenshots of Old Desktop OSes

http://www.typewritten.org/Media/
592•adunk•15h ago•308 comments

Show HN: Gigacatalyst – Extend your SaaS with an embedded AI builder

25•namanyayg•3h ago•8 comments

Postmortem: TanStack NPM supply-chain compromise

https://tanstack.com/blog/npm-supply-chain-compromise-postmortem
1041•varunsharma07•23h ago•434 comments

Canada’s Bill C-22 Is a Repackaged Version of Last Year’s Surveillance Nightmare

https://www.eff.org/deeplinks/2026/05/canadas-bill-c-22-repackaged-version-last-years-surveillanc...
103•Brajeshwar•2h ago•35 comments

Text Blaze (YC W21) Is Hiring for a No-AI Summer Internship

https://www.ycombinator.com/companies/text-blaze/jobs/P4CCN62-the-blaze-no-ai-summer-internship
1•scottfr•8h ago

Unauthorized Anthropic stock sales and investment scams

https://support.claude.com/en/articles/13704655-unauthorized-anthropic-stock-sales-and-investment...
15•Nrbelex•1h ago•2 comments

The Moth Story Map

https://themoth.org/dispatches/story-map
14•jxmorris12•3d ago•1 comments

Testing UPS Output Waveforms

https://www.lttlabs.com/articles/2026/05/12/ups-exploration
31•LabsLucas•3h ago•26 comments

Launch HN: Voker (YC S24) – Analytics for AI Agents

https://voker.ai
29•ttpost•4h ago•13 comments

SQL: Incorrect by Construction

https://chreke.com/posts/sql-incorrect-by-construction
8•ingve•2h ago•1 comments

The Real Story of Troy

https://storica.club/blog/troy-was-real/
32•cemsakarya•2d ago•16 comments

They Live (1988) inspired Adblocker

https://github.com/davmlaw/they_live_adblocker
516•tokenburner•19h ago•167 comments

The Surprisingly Long Life of the Vacuum Tube

https://www.construction-physics.com/p/the-surprisingly-long-life-of-the
50•surprisetalk•1d ago•31 comments