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

Comments

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

The struggle of resizing windows on macOS Tahoe

https://noheger.at/blog/2026/01/11/the-struggle-of-resizing-windows-on-macos-tahoe/
1877•happosai•15h ago•785 comments

Lightpanda migrate DOM implementation to Zig

https://lightpanda.io/blog/posts/migrating-our-dom-to-zig
58•gearnode•2h ago•12 comments

Fossil versus Git

https://fossil-scm.org/home/doc/trunk/www/fossil-v-git.wiki
26•vednig•1h ago•15 comments

JRR Tolkien reads from The Hobbit for 30 Minutes (1952)

https://www.openculture.com/2026/01/j-r-r-tolkien-reads-from-the-hobbit-for-30-minutes-1952.html
137•bookofjoe•4d ago•34 comments

CLI agents make self-hosting on a home server easier and fun

https://fulghum.io/self-hosting
589•websku•14h ago•387 comments

Ai, Japanese chimpanzee who counted and painted dies at 49

https://www.bbc.com/news/articles/cj9r3zl2ywyo
28•reconnecting•2h ago•15 comments

39c3: In-house electronics manufacturing from scratch: How hard can it be? [video]

https://media.ccc.de/v/39c3-in-house-electronics-manufacturing-from-scratch-how-hard-can-it-be
139•fried-gluttony•2d ago•56 comments

This game is a single 13 KiB file that runs on Windows, Linux and in the Browser

https://iczelia.net/posts/snake-polyglot/
227•snoofydude•13h ago•58 comments

Show HN: DevicePrint – device fingerprinting without cookies

7•silverrump•5d ago•11 comments

iCloud Photos Downloader

https://github.com/icloud-photos-downloader/icloud_photos_downloader
485•reconnecting•16h ago•203 comments

Conbini Wars – Map of Japanese convenience store ratios

https://conbini.kikkia.dev/
67•zdw•5d ago•25 comments

XMPP and Metadata

https://blog.mathieui.net/xmpp-and-metadata.html
24•todsacerdoti•5d ago•1 comments

I'm making a game engine based on dynamic signed distance fields (SDFs) [video]

https://www.youtube.com/watch?v=il-TXbn5iMA
343•imagiro•4d ago•48 comments

The next two years of software engineering

https://addyosmani.com/blog/next-two-years/
173•napolux•14h ago•160 comments

FUSE is All You Need – Giving agents access to anything via filesystems

https://jakobemmerling.de/posts/fuse-is-all-you-need/
154•jakobem•14h ago•53 comments

Uncrossy

https://uncrossy.com/
91•dgacmu•10h ago•27 comments

Sampling at negative temperature

https://cavendishlabs.org/blog/negative-temperature/
176•ag8•16h ago•52 comments

Perfectly Replicating Coca Cola [video]

https://www.youtube.com/watch?v=TDkH3EbWTYc
240•HansVanEijsden•3d ago•156 comments

Insights into Claude Opus 4.5 from Pokémon

https://www.lesswrong.com/posts/u6Lacc7wx4yYkBQ3r/insights-into-claude-opus-4-5-from-pokemon
95•surprisetalk•5d ago•18 comments

Ask HN: What are you working on? (January 2026)

206•david927•19h ago•656 comments

Don't fall into the anti-AI hype

https://antirez.com/news/158
1051•todsacerdoti•1d ago•1269 comments

Elo – A data expression language which compiles to JavaScript, Ruby, and SQL

https://elo-lang.org/
91•ravenical•5d ago•27 comments

Gadget Exposed a Spy Camera [video]

https://www.youtube.com/watch?v=1reman2waLs
60•rib3ye•11h ago•29 comments

Garbage collection is contrarian

https://trynova.dev/blog/garbage-collection-is-contrarian
51•aapoalas•2d ago•7 comments

Himalayas bare and rocky after reduced winter snowfall, scientists warn

https://www.bbc.com/news/articles/clyndv7zd20o
126•koolhead17•9h ago•102 comments

Show HN: Shellock, a real-time CLI flag explainer for fish shell

https://github.com/ibehnam/shellock
13•behnamoh•5d ago•4 comments

A set of Idiomatic prod-grade katas for experienced devs transitioning to Go

https://github.com/MedUnes/go-kata
132•medunes•4d ago•24 comments

Poison Fountain

https://rnsaffn.com/poison3/
210•atomic128•19h ago•128 comments

Erich von Däniken has died

https://daniken.com/en/startseite-english/
97•Kaibeezy•16h ago•170 comments

Xfce is great

https://rubenerd.com/xfce-is-great/
234•mikece•7h ago•162 comments