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

Comments

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

Dav2d

https://code.videolan.org/videolan/dav2d
179•dabinat•3h ago•72 comments

Inventions for battery reuse and recycling increase seven-fold in last decade

https://www.epo.org/en/news-events/news/inventions-battery-reuse-and-recycling-increase-more-seve...
111•JeanKage•2d ago•4 comments

Do_not_track

https://donottrack.sh/
73•RubyGuy•3h ago•35 comments

NetHack 5.0.0

https://nethack.org/v500/release.html
260•rsaarelm•2h ago•57 comments

I Do Not Recommend Bitwarden

https://xn--gckvb8fzb.com/i-do-not-recommend-bitwarden/
31•maxloh•39m ago•16 comments

Flue is a TypeScript framework for building the next generation of agents

https://flueframework.com/
53•momentmaker•3h ago•19 comments

Unsigned Sizes: A Five Year Mistake

https://c3-lang.org/blog/unsigned-sizes-a-five-year-mistake/
43•lerno•2h ago•40 comments

California to begin ticketing driverless cars that violate traffic laws

https://www.bbc.com/news/articles/clypjx3rg2go
128•geox•2h ago•142 comments

Little Magazines Are Back

https://wsjfreeexpression.substack.com/p/little-magazines-are-back
23•prismatic•2d ago•2 comments

Why does it take so long to release black fan versions?

https://www.noctua.at/en/expertise/blog/how-can-it-take-so-long-to-release-black-fan-versions
649•buildbot•16h ago•271 comments

Welcome to Hell Developer

https://noahclements.com/Wahoo-Bolt-Hidden-Debug-Mode/
27•denysvitali•3h ago•4 comments

How fast is a macOS VM, and how small could it be?

https://eclecticlight.co/2026/05/02/how-fast-is-a-macos-vm-and-how-small-could-it-be/
204•moosia•11h ago•77 comments

Barman – Backup and Recovery Manager for PostgreSQL

https://github.com/EnterpriseDB/barman
117•nateb2022•3d ago•22 comments

Roblox shares plummet 18% as child safety measures weigh on bookings

https://www.cnbc.com/2026/05/01/roblox-rblx-stock-child-safety-earnings.html
118•1vuio0pswjnm7•3h ago•67 comments

Uber wants to turn its drivers into a sensor grid for self-driving companies

https://techcrunch.com/2026/05/01/uber-wants-to-turn-its-millions-of-drivers-into-a-sensor-grid-f...
97•nickvec•5h ago•111 comments

Refusal in Language Models Is Mediated by a Single Direction

https://arxiv.org/abs/2406.11717
69•fagnerbrack•7h ago•24 comments

Why IPv6 is so complicated

https://github.com/becarpenter/book6/blob/main/01.%20Introduction%20and%20Foreword/Why%20IPv6%20i...
59•speckx•3d ago•112 comments

The USB Situation

https://randsinrepose.com/archives/the-usb-situation/
58•herbertl•3d ago•66 comments

Why are there both TMP and TEMP environment variables? (2015)

https://devblogs.microsoft.com/oldnewthing/20150417-00/?p=44213
177•ankitg12•12h ago•83 comments

Open Design: Use Your Coding Agent as a Design Engine

https://github.com/nexu-io/open-design
145•steveharing1•8h ago•78 comments

Canonical Under Attack

https://status.canonical.com
26•ta988•1h ago•2 comments

Dotcl: Common Lisp Implementation on .NET

https://github.com/dotcl/dotcl
137•reikonomusha•2d ago•31 comments

Ti-84 Evo

https://education.ti.com/en/products/calculators/graphing-calculators/ti-84-evo
563•thatxliner•1d ago•454 comments

Show HN: Pollen – distributed WASM runtime, no control plane, single binary

https://github.com/sambigeara/pollen
90•sambigeara•2d ago•41 comments

America's Expanding Domestic Surveillance

https://www.wsj.com/articles/americas-expanding-domestic-surveillance-08b73187
149•Brajeshwar•5h ago•91 comments

Show HN: DAC – open-source dashboard as code tool for agents and humans

https://github.com/bruin-data/dac
85•karakanb•3d ago•29 comments

Artemis II Photo Timeline

https://artemistimeline.com/#artemis-ii-walkout-nhq202604010003
330•geerlingguy•2d ago•26 comments

DeepSeek V4—almost on the frontier

https://simonwillison.net/2026/Apr/24/deepseek-v4/
437•indigodaddy•1d ago•283 comments

New research suggests people can communicate and practice skills while dreaming

https://www.newyorker.com/culture/annals-of-inquiry/its-possible-to-learn-in-our-sleep-should-we
430•XzetaU8•1d ago•254 comments

Modern C++ Programming: Busato

https://github.com/federico-busato/Modern-CPP-Programming
12•KnuthIsGod•4h ago•0 comments