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

Comments

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

Bucketsquatting Is (Finally) Dead

https://onecloudplease.com/blog/bucketsquatting-is-finally-dead
30•boyter•1h ago•12 comments

Willingness to look stupid

https://sharif.io/looking-stupid
310•Samin100•3d ago•110 comments

Executing programs inside transformers with exponentially faster inference

https://www.percepta.ai/blog/can-llms-be-computers
84•u1hcw9nx•1d ago•13 comments

Malus – Clean Room as a Service

https://malus.sh
1256•microflash•19h ago•455 comments

“This is not the computer for you”

https://samhenri.gold/blog/20260312-this-is-not-the-computer-for-you/
433•MBCook•7h ago•169 comments

Vite 8.0 Is Out

https://vite.dev/blog/announcing-vite8
260•kothariji•4h ago•65 comments

Prefix sums at gigabytes per second with ARM NEON

https://lemire.me/blog/2026/03/08/prefix-sums-at-tens-of-gigabytes-per-second-with-arm-neon/
37•mfiguiere•4d ago•3 comments

Hyperlinks in Terminal Emulators

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
54•nvahalik•5h ago•36 comments

Bubble Sorted Amen Break

https://parametricavocado.itch.io/amen-sorting
332•eieio•16h ago•99 comments

ATMs didn’t kill bank teller jobs, but the iPhone did

https://davidoks.blog/p/why-the-atm-didnt-kill-bank-teller
415•colinprince•18h ago•439 comments

Shall I implement it? No

https://gist.github.com/bretonium/291f4388e2de89a43b25c135b44e41f0
1257•breton•12h ago•470 comments

Reversing memory loss via gut-brain communication

https://med.stanford.edu/news/all-news/2026/03/gut-brain-cognitive-decline.html
308•mustaphah•16h ago•122 comments

Understanding the Go Runtime: The Scheduler

https://internals-for-interns.com/posts/go-runtime-scheduler/
109•valyala•3d ago•11 comments

IMG_0416 (2024)

https://ben-mini.com/2024/img-0416
88•TigerUniversity•3d ago•17 comments

The Met releases high-def 3D scans of 140 famous art objects

https://www.openculture.com/2026/03/the-met-releases-high-definition-3d-scans-of-140-famous-art-o...
282•coloneltcb•17h ago•54 comments

Document poisoning in RAG systems: How attackers corrupt AI's sources

https://aminrj.com/posts/rag-document-poisoning/
118•aminerj•19h ago•46 comments

Worldwide Sidewalk Joy: Adding whimsy to neighborhoods

https://worldwidesidewalkjoy.com
15•NaOH•3d ago•3 comments

Celebrating Interesting Flickr Technologies

https://medium.com/@brightcarvings/celebrating-flickr-technology-3c93c8ddecc2
33•steerpike•1d ago•7 comments

Never Snooze a Future

https://jacko.io/snooze.html
13•vinhnx•4d ago•2 comments

Specimen Gallery – CC0 transparent specimen PNGs organized by taxonomy

https://specimen.gallery/
4•eclectic_mind05•3d ago•1 comments

US private credit defaults hit record 9.2% in 2025, Fitch says

https://www.marketscreener.com/news/us-private-credit-defaults-hit-record-9-2-in-2025-fitch-says-...
356•JumpCrisscross•20h ago•410 comments

Grief and the AI split

https://blog.lmorchard.com/2026/03/11/grief-and-the-ai-split/
144•avernet•10h ago•222 comments

Bringing Chrome to ARM64 Linux Devices

https://blog.chromium.org/2026/03/bringing-chrome-to-arm64-linux-devices.html
106•ingve•13h ago•47 comments

Ceno, browse the web without internet access

https://ceno.app/en/index.html?
6•mohsen1•3h ago•2 comments

Can you instruct a robot to make a PBJ sandwich?

https://pbj.deliberateinc.com/
27•mooreds•6h ago•30 comments

Innocent woman jailed after being misidentified using AI facial recognition

https://www.grandforksherald.com/news/north-dakota/ai-error-jails-innocent-grandmother-for-months...
605•rectang•12h ago•309 comments

Big data on the cheapest MacBook

https://duckdb.org/2026/03/11/big-data-on-the-cheapest-macbook
352•bcye•21h ago•278 comments

WolfIP: Lightweight TCP/IP stack with no dynamic memory allocations

https://github.com/wolfssl/wolfip
128•789c789c789c•17h ago•23 comments

Are LLM merge rates not getting better?

https://entropicthoughts.com/no-swe-bench-improvement
149•4diii•21h ago•134 comments

Launch HN: IonRouter (YC W26) – High-throughput, low-cost inference

https://ionrouter.io
63•vshah1016•14h ago•25 comments