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

Comments

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

Cirrus Labs to join OpenAI

https://cirruslabs.org/
108•seekdeep•2h ago•42 comments

The Future of Everything Is Lies, I Guess: Annoyances

https://aphyr.com/posts/415-the-future-of-everything-is-lies-i-guess-annoyances
31•aphyr•1h ago•2 comments

The Problem That Built an Industry

https://ajitem.com/blog/iron-core-part-1-the-problem-that-built-an-industry/
27•ShaggyHotDog•1h ago•7 comments

Filing the corners off my MacBooks

https://kentwalters.com/posts/corners/
1107•normanvalentine•17h ago•509 comments

Optimal Strategy for Connect 4

https://2swap.github.io/WeakC4/explanation/
171•marvinborner•2d ago•23 comments

South Korea introduces universal basic mobile data access

https://www.theregister.com/2026/04/10/south_korea_data_access_universal/
92•saikatsg•2h ago•25 comments

Show HN: Pardonned.com – A searchable database of US Pardons

167•vidluther•9h ago•58 comments

Starfling: A one-tap endless orbital slingshot game in a single HTML file

https://playstarfling.com
377•iceberger2001•2d ago•97 comments

Surelock: Deadlock-Free Mutexes for Rust

https://notes.brooklynzelenka.com/Blog/Surelock
7•codetheweb•2d ago•1 comments

Cooperative Vectors Introduction

https://www.evolvebenchmark.com/blog-posts/cooperative-vectors-introduction
20•JasperBekkers•1d ago•0 comments

Volunteers turn a fan's recordings of 10K concerts into an online treasure trove

https://apnews.com/article/aadam-jacobs-collection-concerts-internet-archive-chicago-b1c9c4466a2d...
222•geox•3d ago•35 comments

How Much Linear Memory Access Is Enough?

https://solidean.com/blog/2026/how-much-linear-memory-access-is-enough/
30•PhilipTrettner•3d ago•2 comments

1D Chess

https://rowan441.github.io/1dchess/chess.html
904•burnt-resistor•1d ago•154 comments

Bitcoin miners are losing on every coin produced as difficulty drops

https://www.coindesk.com/markets/2026/03/22/bitcoin-miners-are-losing-usd19-000-on-every-btc-prod...
108•PaulHoule•2h ago•97 comments

How Passive Radar Works

https://www.passiveradar.com/how-passive-radar-works/
83•surprisetalk•2d ago•29 comments

Installing every* Firefox extension

https://jack.cab/blog/every-firefox-extension
520•RohanAdwankar•17h ago•68 comments

Chimpanzees in Uganda locked in eight-year 'civil war', say researchers

https://www.bbc.com/news/articles/cr71lkzv49po
380•neversaydie•20h ago•226 comments

Previously unknown verses by Empedocles found on papyrus

https://www.thehistoryblog.com/archives/75792
15•danielam•2d ago•2 comments

Artemis II safely splashes down

https://www.cbsnews.com/live-updates/artemis-ii-splashdown-return/
1089•areoform•15h ago•347 comments

AI assistance when contributing to the Linux kernel

https://github.com/torvalds/linux/blob/master/Documentation/process/coding-assistants.rst
416•hmokiguess•21h ago•302 comments

France's government is ditching Windows for Linux, says US tech a strategic risk

https://www.xda-developers.com/frances-government-ditching-windows-for-linux/
236•pabs3•7h ago•136 comments

Borges' cartographers and the tacit skill of reading LM output

https://galsapir.github.io/sparse-thoughts/2026/04/11/map-and-territory/
7•galsapir•2h ago•0 comments

WireGuard makes new Windows release following Microsoft signing resolution

https://lists.zx2c4.com/pipermail/wireguard/2026-April/009561.html
513•zx2c4•1d ago•149 comments

Industrial design files for Keychron keyboards and mice

https://github.com/Keychron/Keychron-Keyboards-Hardware-Design
417•stingraycharles•23h ago•128 comments

Productive Procrastination

https://www.maxvanijsselmuiden.nl/blog/productive-procrastination/
80•maxvij•10h ago•29 comments

Polymarket gamblers betting millions on war

https://www.theguardian.com/business/2026/apr/11/polymarket-gamblers-betting-iran-war-ukraine-new...
109•sandebert•3h ago•63 comments

CPU-Z and HWMonitor compromised

https://www.theregister.com/2026/04/10/cpuid_site_hijacked/
372•pashadee•1d ago•94 comments

Bevy game development tutorials and in-depth resources

https://taintedcoders.com/
118•GenericCanadian•2d ago•28 comments

Helium is hard to replace

https://www.construction-physics.com/p/helium-is-hard-to-replace
340•JumpCrisscross•1d ago•237 comments

JSON formatter Chrome plugin now closed and injecting adware

https://github.com/callumlocke/json-formatter
257•jkl5xx•21h ago•125 comments