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

Comments

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

Statement from Dario Amodei on our discussions with the Department of War

https://www.anthropic.com/news/statement-department-of-war
1515•qwertox•7h ago•789 comments

The Hunt for Dark Breakfast

https://moultano.wordpress.com/2026/02/22/the-hunt-for-dark-breakfast/
118•moultano•2h ago•45 comments

What Claude Code chooses

https://amplifying.ai/research/claude-code-picks
349•tin7in•12h ago•141 comments

80386 Protection

https://nand2mario.github.io/posts/2026/80386_protection/
23•nand2mario•2d ago•1 comments

Layoffs at Block

https://twitter.com/jack/status/2027129697092731343
630•mlex•9h ago•661 comments

What does " 2>&1 " mean?

https://stackoverflow.com/questions/818255/what-does-21-mean
214•alexmolas•10h ago•122 comments

AirSnitch: Demystifying and breaking client isolation in Wi-Fi networks [pdf]

https://www.ndss-symposium.org/wp-content/uploads/2026-f1282-paper.pdf
340•DamnInteresting•14h ago•162 comments

Julia: Performance Tips

https://docs.julialang.org/en/v1/manual/performance-tips/
6•tosh•3d ago•0 comments

Parakeet.cpp – Parakeet ASR inference in pure C++ with Metal GPU acceleration

https://github.com/Frikallo/parakeet.cpp
23•noahkay13•2h ago•2 comments

I rendered 1,418 confusables over 230 fonts. Most aren't confusable to the eye

https://paultendo.github.io/posts/confusable-vision-visual-similarity/
25•paultendo•1d ago•8 comments

An Introduction to the Codex Seraphinianus, the Strangest Book Ever Published

https://www.openculture.com/2026/02/an-introduction-to-the-codex-seraphinianus.html
57•vinhnx•3d ago•13 comments

Launch HN: Cardboard (YC W26) – Agentic video editor

https://www.usecardboard.com/
105•sxmawl•12h ago•54 comments

Move tests to closed source repo

https://github.com/tldraw/tldraw/issues/8082
31•nilsbunger•1d ago•19 comments

Dear Time Lords: Freeze Computers in 1993

https://graydon2.dreamwidth.org/322461.html
39•zdw•2h ago•9 comments

Smartphone market forecast to decline this year due to memory shortage

https://www.idc.com/resource-center/press-releases/wwsmartphoneforecast4q25/
212•littlexsparkee•8h ago•205 comments

I baked a pie every day for a year and it changed my life

https://www.theguardian.com/lifeandstyle/2026/feb/22/a-new-start-after-60-i-baked-a-pie-every-day...
257•NaOH•3d ago•167 comments

LiteLLM (YC W23): Founding Reliability Engineer – $200K-$270K and 0.5-1.0% equity

https://www.ycombinator.com/companies/litellm/jobs/unlCynJ-founding-reliability-performance-engineer
1•ij23•5h ago

OsmAnd's Faster Offline Navigation (2025)

https://osmand.net/blog/fast-routing/
142•todsacerdoti•12h ago•45 comments

Hydroph0bia – fixed SecureBoot bypass for UEFI firmware from Insyde H2O (2025)

https://coderush.me/hydroph0bia-part3/
49•transpute•8h ago•1 comments

Palm OS User Interface Guidelines (2003) [pdf]

https://cs.uml.edu/~fredm/courses/91.308-spr05/files/palmdocs/uiguidelines.pdf
178•spiffytech•13h ago•85 comments

Museum of Plugs and Sockets

https://plugsocketmuseum.nl/index.html
100•ohjeez•3d ago•35 comments

A Nationwide Book Ban Bill Has Been Introduced in the House of Representatives

https://bookriot.com/hr7661-book-ban-legislation/
103•LostMyLogin•3h ago•57 comments

BuildKit: Docker's Hidden Gem That Can Build Almost Anything

https://tuananh.net/2026/02/25/buildkit-docker-hidden-gem/
167•jasonpeacock•16h ago•61 comments

Show HN: Hacker Smacker – Spot great (and terrible) HN commenters at a glance

https://hackersmacker.org
107•conesus•2d ago•119 comments

Two insider cases we've recently closed

https://news.kalshi.com/p/kalshi-trading-violation-enforcement-cases
17•fortran77•4h ago•47 comments

Show HN: Deff – Side-by-side Git diff review in your terminal

https://github.com/flamestro/deff
93•flamestro•12h ago•53 comments

Show HN: Linex – A daily challenge: placing pieces on a board that fights back

https://www.playlinex.com/
58•Humanista75•2d ago•20 comments

Nano Banana 2: Google's latest AI image generation model

https://blog.google/innovation-and-ai/technology/ai/nano-banana-2/
541•davidbarker•14h ago•508 comments

Cartographic Symbologies: The Art and Design of Expression in Historic Maps

https://exhibits.stanford.edu/cartosym/browse
15•starkparker•3d ago•0 comments

This time is different

https://shkspr.mobi/blog/2026/02/this-time-is-different/
146•speckx•17h ago•236 comments