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.

Deno Is Joining Cloudflare

https://deno.com/blog/cloudflare
571•ilreb•3h ago•311 comments

Our $445M Series D

https://oxide.computer/blog/our-445m-series-d
307•ahlCVA•3h ago•113 comments

Let your AI agents paint big arrows, boxes and text on your screen

https://github.com/franzenzenhofer/big-arrow-on-the-screen
255•franze•5h ago•104 comments

I'm in a Meeting

https://iminafleeting.com/
368•splintersio•7h ago•141 comments

Nobel Peace Prize for 2026 to Navanethem "NAVI" Pillay

https://www.nobelprize.org/prizes/peace/2026/press-release/
283•Anon84•6h ago•149 comments

Germany turning abandoned coal mines into 23 lakes, becoming artificial wetland

https://timesofindia.indiatimes.com/world/europe/germany-is-turning-abandoned-coal-mines-into-23-...
54•ohjeez•1h ago•19 comments

Python 3.15.0

https://www.python.org/downloads/release/python-3150/
115•ngoldbaum•1h ago•29 comments

US imposes sanctions on ICC hours after former judge wins Nobel Peace Prize

https://www.reuters.com/world/us-imposes-sanctions-international-criminal-court-hours-after-forme...
268•poly2it•1h ago•117 comments

Why isn't the industry freaking out about DeepSeek 4.1 Flash?

https://www.dgt.is/blog/2026-10-07-deepseek-freek-out/
955•jonotime•1d ago•873 comments

Whistle: Speech to Text in 16.9 MB

https://cactuscompute.com/blog/whistle
851•gmays•23h ago•170 comments

Man discovers his parents' coffee machine used 1TB of data in 10 days

https://www.dexerto.com/entertainment/man-discovers-his-parents-coffee-machine-used-1tb-of-data-i...
848•ck2•1d ago•521 comments

Once: Cache CLI Commands

https://github.com/alex0ptr/once
59•baquero•6h ago•24 comments

The super intelligence shit is a humiliation ritual for OpenAI

https://bsky.app/profile/opinionhaver.bsky.social/post/3mxfo2mdjqs2z
54•doener•1h ago•31 comments

MXC - a sandboxed code execution system

https://github.com/microsoft/mxc
119•nreece•10h ago•58 comments

Yandex Takes a Second Data Center Hit in 48 Hours

https://united24media.com/war-in-ukraine/yandex-takes-a-second-data-center-hit-in-48-hours-now-it...
156•ortusdux•2h ago•145 comments

Yes, and

https://htmx.org/essays/yes-and/
625•Michelangelo11•1d ago•243 comments

I hired an illustrator to draw my house. Now it's my Home Assistant dashboard

https://antonfrolov.substack.com/p/i-hired-an-illustrator-to-draw-my
804•soheilpro•2d ago•172 comments

Keyboard differences between Windows and Macs

https://unsung.aresluna.org/deeper-dive-keyboard-differences-between-windows-and-macs/
248•sohkamyung•13h ago•197 comments

Imposing Sanctions on the International Criminal Court

https://www.state.gov/releases/office-of-the-spokesman/2026/10/imposing-sanctions-on-the-internat...
112•TechTechTech•1h ago•102 comments

Theranos.world

https://www.theranos.world/
513•kbyatnal•22h ago•184 comments

OpenAI fires three safety researchers for "mishandling research information"

https://techcrunch.com/2026/10/08/fired-openai-safety-researchers-dispute-misconduct-claims-warn-...
174•trakkstar•6h ago•87 comments

Study: Exercise increases cancer survival rates

https://www.nejm.org/doi/10.1056/NEJMoa2502760
54•RickJWagner•3h ago•30 comments

Reactions to 100 Solutions

https://proofsandprompts.com/2026/10/08/100-reactions-to-100-solutions/
17•jacobedawson•4h ago•6 comments

The Hetzner Cloud network stack – history and technical overview

https://www.hetzner.com/blog/the-hetzner-cloud-network-stack-history-and-technical-overview/
65•cnkk•4h ago•21 comments

A statement on the Tor Project's relationship with Mullvad

https://blog.torproject.org/on-tor-relationship-with-mullvad/
25•runtimewire•36m ago•13 comments

Ask HN: What do you run on a $5 VPS that's worth keeping online 24/7?

333•mariocesar•2d ago•533 comments

The value of not getting to the point (2015)

https://ken.arneson.name/2015/11/the-value-of-not-getting-to-the-point/
206•NaOH•21h ago•70 comments

Iranian campaign planted fake articles in real U.S. publications using ChatGPT

https://www.washingtonpost.com/technology/2026/10/09/chatgpt-users-iran-planted-ai-generated-arti...
126•cainxinth•4h ago•119 comments

OpenAI, the Partition Principle, and Mathematics

https://karagila.org/2026/openai-pp/
172•md224•16h ago•252 comments

ETH-68: Ethernet Audio Interface for Linux

https://naturalsystems.io/eth68
197•chabad360•2d ago•122 comments