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.

DeepSeek V4 Pro 0813

https://openrouter.ai/deepseek/deepseek-v4-pro-0813
759•explosion-s•10h ago•287 comments

Delta

https://zed.dev/blog/introducing-delta
400•khy•7h ago•133 comments

Tailscale Traces Database Corruption to 16y/o SQLite WAL-Reset Bug

https://tailscale.com/blog/sqlite-wal-reset-bug
808•ropbear•11h ago•147 comments

Qwen3.8-2.4T

https://huggingface.co/Qwen/Qwen3.8-2.4T-A95B
503•Philpax•11h ago•110 comments

Happy 45th Birthday to the IBM PC and Model F/XT

https://sharktastica.co.uk/articles/pc-fxt-45
29•tart-lemonade•2h ago•6 comments

Principia Mathematica is modern and insightful

https://okmij.org/ftp/Computation/Impressions/PrincipiaMathematica.html
47•matt_d•2h ago•15 comments

What's New in Flutter 3.47

https://flutter.dev/blog/whats-new-in-flutter-3-47
42•gumby271•2h ago•27 comments

Build Wide, Ship Narrow

https://adapt.com/blog/build-wide-ship-narrow
29•ashumz•2h ago•0 comments

Why Target Common Lisp for Code Generation?

http://funcall.blogspot.com/2026/08/why-vibe-code-in-lisp.html
36•oumua_don17•17h ago•26 comments

2026 Eclipse Webcams

https://jonty.github.io/2026_eclipse_webcams/
459•zoenolan•14h ago•124 comments

Show HN: Ballet – Workflow automation that writes integrations against any API

https://www.ballet.dev/
17•danielkimber•2h ago•2 comments

Tim King, AmigaDOS developer, has died

https://amiga-news.de/en/news/AN-2026-08-00070-EN.html
240•doener•11h ago•29 comments

HTML over WebSockets: real-time SPAs with barely any JavaScript

https://en.andros.dev/blog/ef4968f5/html-over-websockets-real-time-spas-with-barely-any-javascript/
148•redbell•9h ago•110 comments

Grok 4.6

https://x.ai/news/grok-4-6
412•iLuddite•10h ago•401 comments

Launch HN: Discovered Materials (YC P26) – AI agents to discover new materials

https://discoveredmaterials.com/research/
115•advaith08•18h ago•22 comments

Someone is running mass vulnerability scans, spoofing AI bots like ClaudeBot

https://knownagents.com/insights
236•gavinhking•12h ago•171 comments

uBlock Origin Is Giving Up the Fight to Keep Ads Off Facebook

https://digitalescapetools.com/2026/08/ublock-origin-stops-chasing-facebook-ads.html
307•Markoff•14h ago•441 comments

Why tiny JPEGs look different in Chrome

https://guillaumetech.github.io/posts/jpg-scaling-chrome/
258•gutechh•12h ago•59 comments

Thanks to social media, canned sardines are a scarcity on the supermarket shelf

https://corneroffifth.studio/why-cant-you-find-canned-sardines-right-now/
49•carabiner•4h ago•58 comments

Pixel Watch 5

https://blog.google/products-and-platforms/devices/pixel/pixel-watch-5/
105•ortusdux•9h ago•201 comments

Waits: Arthur Samuel's Checkers

https://timereshared.com/waits-samuel-checkers/
4•abrax3141•4d ago•0 comments

A Tale of Dynamic Programming (2022)

https://iagoleal.com/posts/dynamic-programming/
72•Brajeshwar•3d ago•5 comments

Breaking the WAL

https://antithesis.com/blog/2026/wal-reset-bug/
61•wwilson•6h ago•34 comments

Reflex (YC W23) Is hiring Growth and GTM Roles

https://www.ycombinator.com/companies/reflex/jobs/71x5GFb-growth-engineer
1•apetuskey•9h ago

What is AI governance and how to operationalize it?

https://www.etherionconsulting.com/blog/what-is-ai-governance-and-how-to-operationalize-it/
3•koanvai•1h ago•0 comments

Process as a Proxy for Motivation

https://bengodfrey.dev/blog/process/
24•sudo-bendg•4h ago•4 comments

Shade Map

https://shademap.app
149•fredley•13h ago•41 comments

Lovable raises $400M Series C

https://lovable.dev/blog/series-c
96•thoughtpeddler•9h ago•95 comments

AI is removing the middle class of software engineering?

https://blog.florianherrengt.com/ai-removing-middle-class-software-engineering.html
732•florianherrengt•12h ago•663 comments

Debugging Information for Inlined Functions

https://lwn.net/Articles/1083985/
19•pykello•3d ago•0 comments