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.

PipePipe: NewPipe hard fork implementing SponsorBlock

https://github.com/InfinityLoop1308/PipePipe
340•Qision•1d ago•192 comments

DeepSeek Elastic Compute (DSec)

https://arxiv.org/abs/2609.22978
183•shenli3514•9h ago•57 comments

Go Concurrency Distilled

https://antonz.org/go-concurrency-distilled/
67•chmaynard•13h ago•19 comments

Show HN: Reladraw – A diagram language where you decide where to place things

https://github.com/reladraw/reladraw
213•jpwalsh234•10h ago•61 comments

Does Georgism work? Five years later

https://www.astralcodexten.com/p/does-georgism-work-five-years-later
192•silveraxe93•1d ago•125 comments

Turning GLM-5.3-Flash into a Jev-like decision model

https://www.privatemode.ai/blog/system-one-from-glm-flash
48•flxflx•12h ago•25 comments

Snap Wants to be a State Actor??–Kansas v. Snap

https://blog.ericgoldman.org/archives/2026/09/snap-wants-to-be-a-state-actor-kansas-v-snap.htm
24•hn_acker•1d ago•2 comments

Evolving programming languages in the AI era

https://dashbit.co/blog/evolving-ai-era
48•pjm331•2d ago•34 comments

We Should Be Able to Change Our Languages

http://jimmyhmiller.com/change-our-languages
13•surprisetalk•1d ago•4 comments

A searchable library of forgotten public-domain film clips from 1915 onward

https://www.movingimagearchive.com/
131•momentmaker•2d ago•26 comments

What is the size of Yemen? (2024)

https://theborys.substack.com/p/what-is-the-size-of-yemen
21•kspacewalk2•1h ago•3 comments

Reverse-engineering the Intel 8087's tangent algorithm: more than CORDIC

https://www.righto.com/2026/09/8087-tangent-cordic.html
42•pwg•10h ago•7 comments

Drawgent: Coding agent on a live Excalidraw canvas

https://tangled.org/yanndegat.tngl.sh/drawgent
122•parasitid•11h ago•33 comments

Fifteen years later, the Apple Cards origin story

https://lexontech.org/fifteen-years-later-the-apple-cards-origin-story
360•ksec•18h ago•92 comments

Biology might not be quantum, but its math is quantumlike

https://www.quantamagazine.org/biology-might-not-be-quantum-but-its-math-is-quantumlike-20260923/
33•pseudolus•2d ago•9 comments

If we do not stop to help each other, what do we become?

https://blog.codinghorror.com/if-we-do-not-stop-to-help-each-other-what-do-we-become/
13•signa11•31m ago•0 comments

Promising discoveries about the potential for life on one of Saturn’s icy moons

https://www.fu-berlin.de/en/presse/informationen/fup/2026/fup_26_116-enceladus-cassini-mikroben-s...
32•geox•1d ago•21 comments

ASML says it sold 'absolutely nothing' in Europe in 2026

https://www.tomshardware.com/tech-industry/semiconductors/asml-says-its-sells-absolutely-nothing-...
181•MC995•1d ago•500 comments

Welcome to the Medical Clinic at the Interplanetary Relay Station

https://www.lightspeedmagazine.com/fiction/welcome-to-the-medical-clinic-at-the-interplanetary-re...
57•bucket2015•7h ago•10 comments

Real-time feedback: My closing move in every interview

https://mgrebler.substack.com/p/real-time-feedback-my-closing-move
11•fagnerbrack•2h ago•2 comments

The Evolution of Vending Machines

https://www.saturdayeveningpost.com/2026/09/from-holy-water-to-frozen-meals-the-evolution-of-vend...
24•ohjeez•10h ago•7 comments

Generate fonts where every LLM token is the same width

https://ampdot.mesh.host/token-space-fonts.html
38•z-mach9•1d ago•10 comments

Modern Object Pascal Introduction for Programmers

https://castle-engine.io/modern_pascal
156•birdculture•2d ago•63 comments

How I changed teaching after AI managed to do all my homework assignments

https://thelastsoftwareengineer.substack.com/p/how-i-changed-teaching-after-ai-managed
157•azhenley•2d ago•151 comments

How to keep enjoying programming in a world of LLMs

https://discourse.haskell.org/t/how-to-keep-enjoying-programming-in-a-world-of-llms/14705
175•signa11•18h ago•226 comments

The Lost Atomic Update on Loongson CPU

https://jia.je/hardware/2026/09/24/loongson-cpu-erratum-en/
115•jiegec•2d ago•6 comments

How one Twitch chat message became code execution on a streamer’s PC

https://blog.scrt.ch/2026/09/22/how-one-twitch-chat-message-became-code-execution-on-a-streamers-pc/
35•tau255•1d ago•18 comments

LA Metro has some of the slowest escalators on Earth

https://basin.la/articles/ninety-feet-a-minute.html
87•big_toast•2d ago•71 comments

Dutch designer made DE9: Closer to the Edit into a playable web-based instrument

https://www.creativeboom.com/work/why-merijn-straathof-turned-a-landmark-techno-album-into-a-play...
12•ChrisArchitect•2d ago•2 comments

Sousveillance

https://en.wikipedia.org/wiki/Sousveillance
24•xeonmc•3h ago•5 comments