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/
1669•happosai•12h ago•683 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
78•bookofjoe•4d ago•14 comments

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

https://fulghum.io/self-hosting
524•websku•12h ago•345 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
85•fried-gluttony•2d ago•23 comments

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

https://iczelia.net/posts/snake-polyglot/
194•snoofydude•11h ago•52 comments

Himalayas bare and rocky after reduced winter snowfall, scientists warn

https://www.bbc.com/news/articles/clyndv7zd20o
108•koolhead17•6h ago•57 comments

iCloud Photos Downloader

https://github.com/icloud-photos-downloader/icloud_photos_downloader
430•reconnecting•14h ago•189 comments

Don't fall into the anti-AI hype

https://antirez.com/news/158
989•todsacerdoti•23h ago•1166 comments

Conbini Wars – map of Japanese convenience store ratios

https://conbini.kikkia.dev/
30•zdw•5d ago•8 comments

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

https://www.youtube.com/watch?v=il-TXbn5iMA
308•imagiro•3d ago•40 comments

The next two years of software engineering

https://addyosmani.com/blog/next-two-years/
135•napolux•11h ago•79 comments

Sampling at negative temperature

https://cavendishlabs.org/blog/negative-temperature/
166•ag8•13h ago•48 comments

Uncrossy

https://uncrossy.com/
65•dgacmu•8h ago•21 comments

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

https://jakobemmerling.de/posts/fuse-is-all-you-need/
129•jakobem•12h ago•50 comments

Perfectly Replicating Coca Cola [video]

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

Insights into Claude Opus 4.5 from Pokémon

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

Gadget Exposed a Spy Camera [video]

https://www.youtube.com/watch?v=1reman2waLs
50•rib3ye•9h ago•23 comments

Garbage collection is contrarian

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

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

189•david927•17h ago•605 comments

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

https://github.com/ibehnam/shellock
6•behnamoh•5d ago•1 comments

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

https://elo-lang.org/
81•ravenical•4d ago•21 comments

Xfce is great

https://rubenerd.com/xfce-is-great/
186•mikece•5h ago•131 comments

Show HN: An LLM-optimized programming language

https://github.com/ImJasonH/ImJasonH/blob/main/articles/llm-programming-language.md
33•ImJasonH•6h ago•19 comments

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

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

Poison Fountain

https://rnsaffn.com/poison3/
198•atomic128•16h ago•119 comments

Erich von Däniken has died

https://daniken.com/en/startseite-english/
83•Kaibeezy•14h ago•128 comments

Show HN: Engineering Schizophrenia: Trusting yourself through Byzantine faults

78•rescrv•11h ago•10 comments

Moving Scratch generation to Python on browser

https://kushaldas.in/posts/introducing-ektupy.html
37•kushaldas•3d ago•12 comments

Code and Let Live

https://fly.io/blog/code-and-let-live/
456•usrme•2d ago•173 comments

Quake 1 Single-Player Map Design Theories (2001)

https://www.quaddicted.com/webarchive//teamshambler.planetquake.gamespy.com/theories1.html
64•Lammy•1d ago•12 comments