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.

Binance-hacker-1029 – $5.6B stolen from Binance

https://arkm.com/explorer/entity/21a94755-f604-45e5-9501-6542e23005e8
1421•Tiberium•13h ago•915 comments

We're releasing the weights of Mistral Large 4

https://mistral.ai/news/mistral-large-4-oss/
1514•kuberwastaken•20h ago•399 comments

How Do You Take a Picture of a Black Hole?

https://www.quantamagazine.org/how-do-you-take-a-picture-of-a-black-hole-20261029/
14•dverlaeckt80•1h ago•9 comments

Gilgamesh by Simon Armitage review – an ancient epic is brilliantly translated

https://www.theguardian.com/books/2026/oct/20/gilgamesh-by-simon-armitage-review-an-ancient-epic-...
49•benbreen•2d ago•16 comments

Cuis: The Modern Smalltalk-80

https://cuis.st/
127•theanonymousone•3d ago•16 comments

I'm so bad at billiards that I ended up in the hyperbolic plane [video]

https://www.youtube.com/watch?v=kL9BTbIGxLg
145•surprisetalk•1d ago•18 comments

Herdr has released native app

https://github.com/herdrdev/herdr-app
226•cherioo•10h ago•145 comments

elect.horse

https://elect.horse/
6•solarist•1h ago•1 comments

Astroterm: A Planetarium for Your Terminal

https://github.com/da-luce/astroterm
147•nvmdbljstm•2d ago•13 comments

We ran AI agent swarms in Minecraft and Mindustry

https://labs.ycombinator.com/projects/games/index.html
303•sandslash•13h ago•111 comments

Artificial Analysis v5 and the benchmarker's dilemma

https://www.interconnects.ai/p/artificial-analysis-v5-and-the-benchmarkers
23•6thbit•1d ago•14 comments

A tiny world model running games on a Raspberry Pi Pico 2 W

https://github.com/SheepSeb/tinyworldformer
223•airinei•14h ago•15 comments

H.264 Is Magic (2016)

https://sidbala.com/h-264-is-magic/
447•ea016•19h ago•150 comments

Wasmer (YC S19) Is Hiring OS/Hypervisor Experts in Europe

https://www.workatastartup.com/jobs/98722
1•syrusakbary•4h ago

LLM Voice

https://martinfowler.com/bliki/LLM-Voice.html
492•ibobev•20h ago•260 comments

Show HN: I Turned DOOM into a Transformer

https://github.com/mottopanikeiku/doomformer
95•falperc•11h ago•30 comments

Why a program doesn't work when run from a batch file, but works when clicked

https://devblogs.microsoft.com/oldnewthing/20261026-00/?p=112797/
29•ibobev•3d ago•4 comments

Python on My Wrist

https://tildeweb.nl/~michiel/python-on-my-wrist.html
55•roywashere•3d ago•6 comments

Launch HN: Simantic (YC F26) – Firmware Simulation for AI Agents

71•shong0504•19h ago•24 comments

Pico CSS is no longer maintained

https://github.com/picocss/pico/discussions/754
150•henrid•9h ago•69 comments

A Pig, the State, and War: Porco Rosso (Kurenai No Buta) (2014)

https://journal.animationstudies.org/article/id/66/
123•simonebrunozzi•12h ago•29 comments

Patrick Stewart has died

https://www.nytimes.com/2026/10/29/arts/television/patrick-stewart-dead.html
3037•j4mie•15h ago•645 comments

Anthropic hacked to deliver remote access trojan

https://doublepulsar.com/anthropic-hacked-to-deliver-remote-access-trojan-to-claude-developer-lap...
21•bashtoni•43m ago•2 comments

If IPv4 were land

https://iptrust.co/blog/if-ipv4-were-land
293•rokostik•22h ago•410 comments

An illustrated online book on Hewlett-Packard equipment

https://blog.adafruit.com/2026/10/27/an-illustrated-online-book-on-hewlett-packard-equipment/
21•sohkamyung•2d ago•4 comments

What we know so far about Spain train crash

https://www.bbc.com/news/articles/cm8xz7pkd0jjo
214•ZeljkoS•1d ago•379 comments

Should a medical diagnosis reshape the past? (2025)

https://chengela.substack.com/p/should-a-medical-diagnosis-reshape
47•wyndham•12h ago•9 comments

Show HN: Auto Dismiss Mac OS "Allow <app> to find devices on local networks?"

https://github.com/johncassil/dontallow
142•johncassil•15h ago•105 comments

Historical Scientific Instruments

https://nealstephenson.substack.com/p/historical-scientific-instruments
43•peteforde•2d ago•3 comments

ElementaryUI – Swift, in the Browser

https://elementary.codes
106•frizlab•14h ago•31 comments