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

Comments

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

AI and the ironies of automation – Part 2

https://www.ufried.com/blog/ironies_of_ai_2/
114•BinaryIgor•4h ago•35 comments

Apple Maps claims it's 29,905 miles away

https://mathstodon.xyz/@dpiponi/115651419771418748
105•ColinWright•3h ago•69 comments

Europeans' health data sold to US firm run by ex-Israeli spies

https://www.ftm.eu/articles/europe-health-data-us-firm-israel-spies
419•Fnoord•5h ago•210 comments

Illuminating the processor core with LLVM-mca

https://abseil.io/fast/99
25•ckennelly•2h ago•2 comments

Vacuum Is a Lie: About Your Indexes

https://boringsql.com/posts/vacuum-is-lie/
30•birdculture•4h ago•9 comments

Shai-Hulud compromised a dev machine and raided GitHub org access: a post-mortem

https://trigger.dev/blog/shai-hulud-postmortem
72•nkko•7h ago•48 comments

AI was not invented, it arrived

https://andrewarrow.dev/2025/12/ai-was-not-invented-it-arrived/
7•fcpguru•1h ago•5 comments

Update Now: iOS 26.2 Fixes 20 Security Vulnerabilities, 2 Actively Exploited

https://www.macrumors.com/2025/12/12/ios-26-2-security-vulnerabilities/
31•akyuu•1h ago•18 comments

Linux Sandboxes and Fil-C

https://fil-c.org/seccomp
299•pizlonator•18h ago•103 comments

Kimi K2 1T model runs on 2 512GB M3 Ultras

https://twitter.com/awnihannun/status/1943723599971443134
102•jeudesprits•4h ago•52 comments

Compiler Engineering in Practice

https://chisophugis.github.io/2025/12/08/compiler-engineering-in-practice-part-1-what-is-a-compil...
65•dhruv3006•9h ago•7 comments

Efficient Basic Coding for the ZX Spectrum

https://blog.jafma.net/2020/02/24/efficient-basic-coding-for-the-zx-spectrum/
26•rcarmo•5h ago•5 comments

Science Communications on YouTube

https://blogs.memphis.edu/awindsor/2025/02/25/science-communication-on-youtube/
4•azhenley•1w ago•0 comments

Using e-ink tablet as monitor for Linux

https://alavi.me/blog/e-ink-tablet-as-monitor-linux/
213•yolkedgeek•5d ago•81 comments

Show HN: Cargo-rail: graph-aware monorepo tooling for Rust; 11 deps

https://github.com/loadingalias/cargo-rail
29•LoadingALIAS•3d ago•2 comments

I fed 24 years of my blog posts to a Markov model

https://susam.net/fed-24-years-of-posts-to-markov-model.html
256•zdw•21h ago•101 comments

Recovering Anthony Bourdain's Li.st's

https://sandyuraz.com/blogs/bourdain/
264•thecsw•20h ago•122 comments

Getting into Public Speaking

https://james.brooks.page/blog/getting-into-public-speaking
45•jbrooksuk•4d ago•20 comments

Cat Gap

https://en.wikipedia.org/wiki/Cat_gap
164•Petiver•4d ago•39 comments

I tried Gleam for Advent of Code

https://blog.tymscar.com/posts/gleamaoc2025/
319•tymscar•1d ago•186 comments

Building a Modern C64 Assembly AI Toolchain

https://medium.com/@gianlucabailo/building-a-modern-c64-assembly-ai-toolchain-using-google-gemini...
26•094459•5d ago•5 comments

Lean theorem prover mathlib

https://github.com/leanprover-community/mathlib4
71•downboots•15h ago•3 comments

Baumol's Cost Disease

https://en.wikipedia.org/wiki/Baumol_effect
40•drra•4h ago•39 comments

An Implementation of J (1992)

https://www.jsoftware.com/ioj/ioj.htm
75•ofalkaed•16h ago•28 comments

An off-grid, flat-packable washing machine

https://www.positive.news/society/flat-pack-washing-machine-spins-a-fairer-future/
167•ohjeez•18h ago•92 comments

Mystery Science Theater 3000: The Definitive Oral History of a TV Masterpiece

https://www.wired.com/2014/04/mst3k-oral-history/
87•indigodaddy•6d ago•26 comments

Closures as Win32 Window Procedures

https://nullprogram.com/blog/2025/12/12/
86•ibobev•17h ago•19 comments

Willison on Merchant's "Copywriters reveal how AI has decimated their industry"

https://simonwillison.net/2025/Dec/14/copywriters-reveal-how-ai-has-decimated-their-industry/
57•planckscnst•7h ago•44 comments

Useful patterns for building HTML tools

https://simonwillison.net/2025/Dec/10/html-tools/
327•simonw•3d ago•93 comments

Dagger: Define software delivery workflows and dev environments

https://dagger.io/
61•ahamez•5d ago•48 comments