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.

A Surveillance Treaty in Disguise: Canada Signs UN Cybercrime Convention

https://www.michaelgeist.ca/2026/07/a-surveillance-treaty-in-disguise-the-trouble-with-canadas-qu...
16•iamnothere•28m ago•1 comments

RipGrep musl binaries occasionally segfault during very-large searches

https://github.com/BurntSushi/ripgrep/issues/3494
97•throwaway2037•2h ago•52 comments

Elevators

https://john.fun/elevators
1453•Jrh0203•23h ago•359 comments

How to Spot AI Writing

https://www.economist.com/culture/2026/07/30/how-to-spot-ai-writing
12•ijidak•1h ago•16 comments

Manual: •.,:;?·

https://type.today/en/journal/dots
63•behnamoh•2d ago•10 comments

Flint: A Visualization Language for the AI Era

https://microsoft.github.io/flint-chart/
182•vinhnx•12h ago•58 comments

Linux on ESP32

https://github.com/GrieferPig/esp32-s31-linux
10•boveyking•3d ago•2 comments

Solid Queue 1.6.0 now supports fiber workers

https://github.com/rails/solid_queue/releases/tag/v1.6.0
51•earcar•7h ago•11 comments

qm – Multiplayer agent harness for work

https://github.com/yc-software/qm
608•tosh•20h ago•135 comments

A tiny holdout building in the middle of Macy’s is back in view

https://ephemeralnewyork.wordpress.com/2026/07/27/hidden-by-billboards-for-over-100-years-the-tin...
110•donohoe•3d ago•26 comments

RamenHaus

https://ramen.haus/
141•oler•5h ago•75 comments

Kontigo (YC S24) Is Hiring

https://www.ycombinator.com/companies/kontigo/jobs/xAo6tMt-founding-engineer
1•jecastillof•2h ago

How to Do Great Work (2023)

https://paulgraham.com/greatwork.html
66•tosh•6h ago•44 comments

How to Exist

https://www.raptitude.com/2026/07/how-to-exist/
280•walterbell•14h ago•164 comments

The development pipeline is a production system

https://sundry.jerryorr.com/2026/07/31/development-pipeline-is-a-production-system
119•firefoxd•11h ago•55 comments

Astro Loop

https://pubdeer.com/
9•BaseBaal•2h ago•0 comments

G'mic 4.0: Squaring the Pixel, Easier

https://gmic.eu/gmic40/
53•dtschump•3d ago•2 comments

Software for One

https://www.ajwaxman.com/writing/software-for-one
167•awaxman11•3d ago•167 comments

Run Kimi K3 using 29 GB of RAM at 0.50 tok/s

https://github.com/sqliteai/waste
287•marcobambini•1d ago•126 comments

The Absurdity of Albert Camus

https://www.historytoday.com/archive/portrait-author-historian/absurdity-albert-camus
153•apollinaire•1d ago•70 comments

The First Idempotency Key

https://hatchet.run/blog/first-idempotency-key
14•abelanger•4d ago•3 comments

Progressive Web Components

https://arielsalminen.com/2026/progressive-web-components/
175•hosteur•1d ago•40 comments

Attention Decode on AMD MI450 GPUs: A Gluon Kernel Optimization Guide

https://rocm.blogs.amd.com/software-tools-optimization/gluon-attention-decode-mi450/README.html
53•matt_d•4d ago•5 comments

Ten advances in mathematics and theoretical computer science

https://openai.com/index/ten-advances-in-mathematics/
235•milkshakes•7h ago•172 comments

Getting 25 Gbps Thunderbolt Ethernet on My Mac Studio

https://www.jeffgeerling.com/blog/2026/getting-25g-ethernet-mac-thunderbolt/
208•speckx•22h ago•106 comments

June in Servo: real world compat, media queries, SharedWorker, and more

https://servo.org/blog/2026/07/31/june-in-servo/
174•iamnothere•20h ago•52 comments

Big Food vs. the People

https://www.lighthousereports.com/investigation/big-food-vs-the-people/
250•jruohonen•22h ago•153 comments

Increasing the lifespan of a bulb makes it worse in every other way

https://maurycyz.com/misc/tungsten/
128•tonyg•1d ago•137 comments

Long Range Wi-Fi – Pushing 2.4 GHz Wi-Fi to the limits (2019)

https://www.phidgets.com/?view=articles&article=LongRangeWifi
74•rzk•4d ago•42 comments

The most official water costs $120k a gallon

https://signoregalilei.com/2026/07/26/the-most-official-water-costs-120000-a-gallon/
212•surprisetalk•23h ago•167 comments