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

Comments

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

I built Timeframe, our family e-paper dashboard

https://hawksley.org/2026/02/17/timeframe.html
746•saeedesmaili•8h ago•193 comments

Show HN: WARN Firehose – Every US layoff notice in one searchable database

https://warnfirehose.com
109•sendkamal•4h ago•10 comments

Loops is a federated, open-source TikTok

https://joinloops.org/
301•Gooblebrai•9h ago•172 comments

Agentic Software Engineering Book

https://agenticse-book.github.io/
19•bananaflag•1h ago•6 comments

Show HN: CIA World Factbook Archive (1990–2025), searchable and exportable

https://cia-factbook-archive.fly.dev/
181•MilkMp•7h ago•40 comments

Google restricting Google AI Pro/Ultra subscribers for using OpenClaw

https://discuss.ai.google.dev/t/account-restricted-without-warning-google-ai-ultra-oauth-via-open...
394•srigi•4h ago•311 comments

How to train your program verifier

https://risemsr.github.io/blog/2026-02-16-halleyyoung-a3/
9•matt_d•4d ago•0 comments

Aqua: A CLI message tool for AI agents

https://github.com/quailyquaily/aqua
16•lyricat•1h ago•6 comments

The JavaScript Oxidation Compiler

https://oxc.rs/
11•modinfo•1h ago•0 comments

My journey to the microwave alternate timeline

https://www.lesswrong.com/posts/8m6AM5qtPMjgTkEeD/my-journey-to-the-microwave-alternate-timeline
105•jstanley•4d ago•5 comments

Attention Media ≠ Social Networks

https://susam.net/attention-media-vs-social-networks.html
567•susam•15h ago•244 comments

Using the new bridges of FreeBSD 15

https://blog.feld.me/posts/2026/02/using-new-bridges-freebsd-15/
62•vermaden•5h ago•15 comments

Six Math Essentials

https://terrytao.wordpress.com/2026/02/16/six-math-essentials/
139•digital55•8h ago•16 comments

The Musidex: A physical music library for the streaming era

https://hannahilea.com/blog/musidex/
16•zdw•3d ago•3 comments

Man accidentally gains control of 7k robot vacuums

https://www.popsci.com/technology/robot-vacuum-army/
223•Brajeshwar•13h ago•129 comments

Fix your tools

https://ochagavia.nl/blog/fix-your-tools/
199•vinhnx•11h ago•73 comments

Linuxulator on FreeBSD Feels Like Magic

https://hayzam.com/blog/02-linuxulator-is-awesome/
86•vermaden•9h ago•29 comments

Show HN: Local-First Linux MicroVMs for macOS

https://shuru.run
135•harshdoesdev•9h ago•38 comments

Show HN: A geometric analysis of Chopin's Prelude No. 4 using 3D topology

https://github.com/jimishol/cholidean-harmony-structure/blob/main/docs/03-case-study-chopin-prelu...
25•jimishol•2d ago•7 comments

$30B for laptops yielded a generation less cognitively capable than parents

https://www.yahoo.com/news/articles/u-spent-30-billion-ditch-110200869.html
107•walterbell•2h ago•94 comments

Hello Worg, the Org-Mode Community

https://orgmode.org/worg/
94•dargscisyhp•10h ago•27 comments

Emulated Windows 3.11 in the Browser

https://pieter.com/
84•jalev•10h ago•39 comments

What is a database transaction?

https://planetscale.com/blog/database-transactions
219•0x54MUR41•15h ago•56 comments

Keybee: A Keyboard Designed for Smartphones

https://keybeekeyboard.com/
60•surprisetalk•3d ago•52 comments

Fresh File Explorer – VS Code extension for navigating recent work

https://github.com/FreHu/vscode-fresh-file-explorer
82•frehu•9h ago•23 comments

Ask HN: Chromebook leads for K-8 school in need?

18•techteach00•8h ago•22 comments

Xweather Live – Interactive global vector weather map

https://live.xweather.com/
143•unstyledcontent•12h ago•34 comments

NanoClaw moved from Apple Containers to Docker

https://twitter.com/Gavriel_Cohen/status/2025603982769410356
121•simplesort•8h ago•93 comments

Git's Magic Files

https://nesbitt.io/2026/02/05/git-magic-files.html
122•chmaynard•13h ago•34 comments

Spain has blocked access to freedom.gov

https://twitter.com/Pirat_Nation/status/2025643188321714642
152•akyuu•7h ago•136 comments