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.

Five Qwen3.8-27B models match Fable 5 Using GVS5H Harness

https://github.com/slee-persis/GVS5H
120•rzk•2h ago•41 comments

We should be more ambitious with the software we build

https://danluu.com/ambitious/
312•ltratt•8h ago•271 comments

Cerebras Deploys Trillion-Parameter AI Models

https://www.cerebras.ai/blog/how-we-deploy-trillion-parameter-frontier-models-on-cerebras
89•gmays•5h ago•28 comments

Picasa Photo Viewer Rebuilt for Linux, Project Named Licasa

https://github.com/sanxchep/licasa
16•UncleJo7•2d ago•1 comments

The Goose Programming Language

https://aardappel.github.io/goose/
331•bobbydigitales•11h ago•224 comments

SpeedCrunch 1.1

https://www.speedcrunch.org/
118•LordNibbler•11h ago•20 comments

Small Programs and Languages

https://ratfactor.com/cards/pl-small
81•andsoitis•8h ago•5 comments

America has lost 200k of jobs in media, film and the arts. How much is AI?

https://www.apricitas.io/p/ai-and-the-fall-of-the-creative-class
293•gnabgib•7h ago•299 comments

Listen and read USA nuclear forces Emergency Action Messages, heard on 11175 kHz

https://missileer.watch
159•liotier•10h ago•105 comments

I Built a Stereo Vision Board for Hardware Hackers

https://rootkitlabs.com/2026/10/06/i-built-a-stereo-vision-board-for-hardware-hackers/
59•machinehum•4d ago•9 comments

Why Gopher in 2026?

https://gopher.muffinlabs.com/sdf.org/users/nervtoji/phlog/001.txt
56•andsoitis•7h ago•15 comments

In Rainbows

https://hitogata.neocities.org/Rainbows
19•surprisetalk•2d ago•3 comments

Pragtical v3.14 Lua-based text editor adds menus, floating views, and sessions

https://pragtical.dev/blog/pragtical-v3140-release
9•rd07•4d ago•1 comments

A story of a Figma bug that wasn't a bug at all (2021)

https://aresluna.org/this-is-a-story-of-a-figma-bug/
20•jllyhill•3d ago•1 comments

Social dynamics of toxic metal industry in medieval Europe

https://www.cambridge.org/core/journals/antiquity/article/social-dynamics-of-toxic-metal-industry...
33•XzetaU8•4d ago•1 comments

I don't understand quantum physics (2018)

https://www.southampton.ac.uk/~doug/quantum_physics/index.html
298•rramadass•20h ago•238 comments

FreeDNS

https://freedns.afraid.org/
275•esher•15h ago•69 comments

The Importance of Limitations for Creativity and Learning (2023)

https://ratfactor.com/cards/limitations
51•andsoitis•8h ago•14 comments

Meta employees say Lula’s accounts restricted in Brazil election: Report

https://www.aljazeera.com/economy/2026/10/16/meta-employees-say-lulas-accounts-restricted-in-braz...
130•nidnogg•4h ago•44 comments

Node2Shell evolves to HTTP2Shell, blast radius affects many HTTP libs and apps

https://www.aikido.dev/blog/python-packages-vulnerable-node2shell-brotli-cve-2026-111497
296•theanonymousone•22h ago•148 comments

Show HN: Steal My Bitcoin

https://stealmybitcoin.com/
452•cloudlandsdev•10h ago•276 comments

The St. Helena 5 pence coin shows Jonathan, a roughly 190 year old tortoise

https://de.numista.com/9866
110•schleck8•13h ago•32 comments

Local Wikipedia: Wikipedia, but only for things a half hour walk from you

https://edjefferson.com/localwiki/
1567•sohkamyung•2d ago•245 comments

Neural chip decodes interactions between brain regions

https://actu.epfl.ch/news/neural-chip-decodes-interactions-between-brain-r-2/
102•giuliomagnifico•14h ago•37 comments

Roku developer repositories moved from GitHub to GitLab

https://blog.roku.com/developer/gitlab-move
281•cxr•14h ago•191 comments

GPU-unlock: FP/BF16 instruction issue rate on Nvidia 3000's cards

https://github.com/Zagitta/gpu-unlock
220•fragebogen•20h ago•69 comments

Bbtree: Fastest Ordered Map

https://bbtree.xiangpeng.systems/post/
91•aoli-al•12h ago•11 comments

Physicists trap a single antimatter particle for a month

https://www.scientificamerican.com/article/physicists-trap-a-single-antimatter-particle-for-a-month/
298•mooreds•3d ago•86 comments

Reactive Optimizers: rewrite the optimizer's source code during training

https://xingjianbai.com/reactive-optimizers/
24•matt_d•3d ago•2 comments

Monoidal computer I: Basic computability by string diagrams (2012)

https://arxiv.org/abs/1208.5205
3•measurablefunc•2d ago•0 comments