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.

There Are No Instances in ATProto

https://overreacted.io/there-are-no-instances-in-atproto/
151•danabramov•3h ago•88 comments

Hyundai buys Boston Dynamics

https://startupfortune.com/hyundai-takes-full-control-of-boston-dynamics-as-softbank-exits-for-32...
233•ck2•2h ago•118 comments

Amateur may have cracked Linear A, a 120-year-old puzzle

https://aiclambake.com/clamtakes/linear-a/
197•Kosturdistan•2h ago•81 comments

Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28

https://www.jvm-weekly.com/p/project-valhalla-explained-how-a
474•philonoist•12h ago•269 comments

A new bill takes aim at government pressure to silence lawful online speech

https://www.eff.org/deeplinks/2026/06/new-bill-takes-aim-government-pressure-silence-lawful-onlin...
82•hn_acker•1h ago•33 comments

Google workspace threatening to block Firefox access

https://tales.fromprod.com/2026/169/google-workspace-threatening-to-block-firefox.html
155•birdculture•2h ago•59 comments

Is AI ruining our skills? Early results are in – and they're not good

https://www.nature.com/articles/d41586-026-01947-1
89•Michelangelo11•1h ago•73 comments

I used sound waves to make espresso. It could cut coffee‑brewing energy use by ¾

https://theconversation.com/i-used-sound-waves-to-make-espresso-it-could-cut-coffee-brewing-energ...
24•zeristor•6d ago•13 comments

Windows 11 update broke the Recycle Bin, OneDrive, and your PC's stability

https://www.techspot.com/news/112831-microsoft-confirms-weird-recycle-bin-bug-windows-11.html
39•speckx•1h ago•13 comments

This 1976 University Experiment Spun Up the U.S. Wind Industry

https://spectrum.ieee.org/william-heronemus-wind-energy
21•pseudolus•4d ago•0 comments

DuckDB Internals: Why Is DuckDB Fast? (Part 1)

https://www.greybeam.ai/blog/duckdb-internals-part-1
374•marklit•3d ago•119 comments

The Productivity J-Curve [pdf] (2018)

https://ide.mit.edu/sites/default/files/publications/jcurve.pdf
41•kioku•3d ago•10 comments

Zen and the Art of Machine Learning Research

https://blog.jxmo.io/p/zen-and-the-art-of-machine-learning
200•jxmorris12•3d ago•68 comments

Ten years of ClickHouse in open source

https://clickhouse.com/blog/open-source-10
226•saisrirampur•3d ago•65 comments

Telescope Ranchers

https://kottke.org/26/06/telescope-ranchers
45•bookofjoe•3d ago•16 comments

Show HN: Metiq: a real time 3D globe for 100 public datasets

https://metiq.space
31•rakeda•3d ago•8 comments

To study how chips work, MIT researchers built their own operating system

https://news.mit.edu/2026/to-study-how-chips-really-work-mit-researchers-built-their-own-operatin...
316•speckx•4d ago•48 comments

I found 10k GitHub repositories distributing Trojan malware

https://orchidfiles.com/github-repositories-distributing-malware/
907•theorchid•1d ago•238 comments

Gribouille 0.3.0: A Grammar of Graphics for Typst

https://mickael.canouil.fr/posts/2026-06-15-gribouille-0-3/
185•mcanouil•4d ago•68 comments

Show HN: Modeloop – From visual algorithms to microcontroller C code

https://www.modeloop.app/
31•lucamark•4d ago•22 comments

The AirPods Effect

https://www.theescapenewsletter.com/p/the-airpods-effect
324•herbertl•19h ago•576 comments

Show HN: Pagecast – Publish Markdown/HTML Reports to Cloudflare Pages

https://github.com/Amal-David/pagecast
10•amaldavid•23h ago•3 comments

Zero-Touch OAuth for MCP

https://blog.modelcontextprotocol.io/posts/enterprise-managed-auth/
247•niyikiza•21h ago•96 comments

Akse3D – open-source 3D modelling anyone can master

https://akse3d-en.skaperiet.no
116•joachimhs•4d ago•33 comments

How Japan's railways stayed one while splitting apart

https://arun.is/blog/jr-logo/
160•ddrmaxgt37•2d ago•128 comments

Giant Banana Pulled over in Montana Driver Says Cops Have Stopped Him 100s Times

https://cowboystatedaily.com/2026/06/18/giant-banana-pulled-over-in-montana-driver-says-cops-have...
11•Bender•49m ago•5 comments

Reinventing the Renaissance

https://drb.ie/article/reinventing-the-renaissance/
27•Petiver•2d ago•7 comments

.gitignore Isn't the only way to ignore files in Git

https://nelson.cloud/.gitignore-isnt-the-only-way-to-ignore-files-in-git/
534•FergusArgyll•1d ago•161 comments

Ubiquiti: Enterprise NAS, Built on ZFS

https://blog.ui.com/article/introducing-enterprise-nas
393•ksec•1d ago•330 comments

CS 6120: Advanced Compilers: The Self-Guided Online Course (2020)

https://www.cs.cornell.edu/courses/cs6120/2025fa/self-guided/
416•ibobev•1d ago•59 comments