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

Comments

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

Animated AI

https://animatedai.github.io/
146•frozenseven•4d ago•14 comments

A faster heart for F-Droid

https://f-droid.org/2025/12/30/a-faster-heart-for-f-droid.html
377•kasabali•13h ago•158 comments

Readings in Database Systems (5th Edition)

http://www.redbook.io/
85•teleforce•6h ago•7 comments

FediMeteo: A €4 FreeBSD VPS Became a Global Weather Service

https://it-notes.dragas.net/2025/02/26/fedimeteo-how-a-tiny-freebsd-vps-became-a-global-weather-s...
287•birdculture•13h ago•66 comments

Show HN: 22 GB of Hacker News in SQLite

https://hackerbook.dosaygo.com
493•keepamovin•15h ago•160 comments

Odin: Moving Towards a New "core:OS"

https://odin-lang.org/news/moving-towards-a-new-core-os/
42•ksec•5d ago•10 comments

A Vulnerability in Libsodium

https://00f.net/2025/12/30/libsodium-vulnerability/
267•raggi•15h ago•34 comments

Honey's Dieselgate: Detecting and tricking testers

https://vptdigital.com/blog/honey-detecting-testers/
201•AkshatJ27•10h ago•61 comments

Google Opal

https://opal.google/landing/
111•gmays•4h ago•59 comments

Loss32: Let's Build a Win32/Linux

https://loss32.org/
274•akka47•1d ago•353 comments

What If Heavy Files Felt Heavy?

https://www.shiveesh.com/thoughts-and-ideas/what-if-heavy-files-actually-felt-heavy
47•shiveeshfotedar•5d ago•26 comments

OpenAI's cash burn will be one of the big bubble questions of 2026

https://www.economist.com/leaders/2025/12/30/openais-cash-burn-will-be-one-of-the-big-bubble-ques...
322•1vuio0pswjnm7•10h ago•437 comments

Tixl: Open-source realtime motion graphics

https://github.com/tixl3d/tixl
8•nateb2022•4d ago•0 comments

Electrolysis can solve one of our biggest contamination problems

https://ethz.ch/en/news-and-events/eth-news/news/2025/11/electrolysis-can-solve-one-of-our-bigges...
149•PaulHoule•14h ago•43 comments

Sabotaging Bitcoin

https://blog.dshr.org/2025/12/sabotaging-bitcoin.html
138•zdw•11h ago•92 comments

Zpdf: PDF text extraction in Zig

https://github.com/Lulzx/zpdf
171•lulzx•12h ago•69 comments

Non-Zero-Sum Games

https://nonzerosum.games/
368•8organicbits•20h ago•178 comments

Toro: Deploy Applications as Unikernels

https://github.com/torokernel/torokernel
130•ignoramous•15h ago•113 comments

LLVM AI tool policy: human in the loop

https://discourse.llvm.org/t/rfc-llvm-ai-tool-policy-human-in-the-loop/89159
181•pertymcpert•5h ago•82 comments

Mitsubishi Diatone D-160 (1985)

https://audio-database.com/MITSUBISHI-DIATONE/diatonesp/d-160-e.html
42•anigbrowl•2d ago•17 comments

No strcpy either

https://daniel.haxx.se/blog/2025/12/29/no-strcpy-either/
194•firesteelrain•19h ago•108 comments

Escaping containment: A security analysis of FreeBSD jails [video]

https://media.ccc.de/v/39c3-escaping-containment-a-security-analysis-of-freebsd-jails
88•todsacerdoti•13h ago•3 comments

L1TF Reloaded

https://github.com/ThijsRay/l1tf_reloaded
25•Fnoord•5h ago•0 comments

Times New American: A Tale of Two Fonts

https://hsu.cy/2025/12/times-new-american/
251•firexcy•19h ago•144 comments

The British empire's resilient subsea telegraph network

https://subseacables.blogspot.com/2025/12/the-british-empires-resilient-subsea.html
190•giuliomagnifico•19h ago•47 comments

Git analytics that works across GitHub, GitLab, and Bitbucket

16•akhnid•1d ago•7 comments

Five Years of Tinygrad

https://geohot.github.io//blog/jekyll/update/2025/12/29/five-years-of-tinygrad.html
224•iyaja•1d ago•108 comments

Professional software developers don't vibe, they control

https://arxiv.org/abs/2512.14012
161•dpflan•12h ago•188 comments

Approachable Swift Concurrency

https://fuckingapproachableswiftconcurrency.com/en/
168•wrxd•19h ago•86 comments

What Happened to Abit Motherboards

https://dfarq.homeip.net/what-happened-to-abit-motherboards/
115•zdw•17h ago•72 comments