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/
992•happosai•6h ago•435 comments

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

https://fulghum.io/self-hosting
342•websku•6h ago•222 comments

Code is cheap now, but software isn't

https://www.chrisgregori.dev/opinion/code-is-cheap-now-software-isnt
29•fs_software•51m ago•3 comments

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

https://iczelia.net/posts/snake-polyglot/
110•snoofydude•5h ago•36 comments

Which programming languages are most token-efficient?

https://martinalderson.com/posts/which-programming-languages-are-most-token-efficient/
32•tehnub•2h ago•11 comments

iCloud Photos Downloader

https://github.com/icloud-photos-downloader/icloud_photos_downloader
336•reconnecting•8h ago•163 comments

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

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

Don't fall into the anti-AI hype

https://antirez.com/news/158
668•todsacerdoti•17h ago•850 comments

Sampling at negative temperature

https://cavendishlabs.org/blog/negative-temperature/
121•ag8•7h ago•41 comments

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

https://jakobemmerling.de/posts/fuse-is-all-you-need/
81•jakobem•6h ago•41 comments

Gadget Exposed a Spy Camera [video]

https://www.youtube.com/watch?v=1reman2waLs
7•rib3ye•3h ago•3 comments

Powell has highest approval rating of political leaders among US adults (2025)

https://news.gallup.com/poll/700241/americans-end-year-gloomy-mood.aspx
13•throw0101c•11m ago•0 comments

I'd tell you a UDP joke…

https://www.codepuns.com/post/805294580859879424/i-would-tell-you-a-udp-joke-but-you-might-not-get
106•redmattred•5h ago•32 comments

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

https://elo-lang.org/
58•ravenical•4d ago•8 comments

Ping: The Secrets of Successful Virtual Communication

https://www.penguin.co.uk/books/468218/ping-by-brodsky-andrew/9780241746363
6•teleforce•4d ago•0 comments

Gentoo Linux 2025 Review

https://www.gentoo.org/news/2026/01/05/new-year.html
300•akhuettel•16h ago•153 comments

Perfectly Replicating Coca Cola [video]

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

Moving Scratch generation to Python on browser

https://kushaldas.in/posts/introducing-ektupy.html
16•kushaldas•2d ago•2 comments

Insights into Claude Opus 4.5 from Pokémon

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

I Cannot SSH into My Server Anymore (and That's Fine)

https://soap.coffee/~lthms/posts/i-cannot-ssh-into-my-server-anymore.html
85•TheWiggles•4d ago•61 comments

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

153•david927•10h ago•508 comments

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

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

Rare Iron Age war trumpet and boar standard found

https://www.bbc.com/news/articles/cr7jvj8d39eo
19•breve•4d ago•4 comments

Garbage collection is contrarian

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

Show HN: Engineering Schizophrenia: Trusting yourself through Byzantine faults

44•rescrv•5h ago•9 comments

Poison Fountain

https://rnsaffn.com/poison3/
175•atomic128•10h ago•109 comments

Elephants Don't Play Chess (1990) [pdf]

https://people.csail.mit.edu/brooks/papers/elephants.pdf
6•gregsadetsky•2d ago•2 comments

Show HN: What if AI agents had Zodiac personalities?

https://github.com/baturyilmaz/what-if-ai-agents-had-zodiac-personalities
17•arbayi•3h ago•9 comments

Show HN: Voice Composer – Browser-based pitch detection to MIDI/strudel/tidal

https://dioptre.github.io/tidal/
5•dioptre•4h ago•1 comments

“Food JPEGs” in Super Smash Bros. and Kirby Air Riders

https://sethmlarson.dev/food-jpegs-in-super-smash-bros-and-kirby-air-riders
266•SethMLarson•5d ago•67 comments