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

Comments

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

Personal Encyclopedias

https://whoami.wiki/blog/personal-encyclopedias
183•jrmyphlmn•14h ago•45 comments

Swift 6.3

https://www.swift.org/blog/swift-6.3-released/
51•ingve•3h ago•16 comments

Running Tesla Model 3's computer on my desk using parts from crashed cars

https://bugs.xdavidhu.me/tesla/2026/03/23/running-tesla-model-3s-computer-on-my-desk-using-parts-...
639•driesdep•13h ago•203 comments

Show HN: Relay – The open-source Claude Cowork for OpenClaw

https://github.com/SeventeenLabs/relay
3•chrislxy•7m ago•0 comments

What came after the 486?

https://dfarq.homeip.net/what-came-after-486/
32•jnord•2d ago•24 comments

Obsolete Sounds

https://citiesandmemory.com/obsolete-sounds/
21•benbreen•6h ago•3 comments

ARC-AGI-3

https://arcprize.org/arc-agi/3
402•lairv•16h ago•261 comments

The Last Contract: William T. Vollmann's Battle to Publish an Epic (2025)

https://www.metropolitanreview.org/p/the-last-contract
8•benbreen•6h ago•0 comments

The truth that haunts the Ramones: 'They sold more T-shirts than records'

https://english.elpais.com/culture/2026-03-17/the-uncomfortable-truth-that-will-always-haunt-the-...
121•c420•4d ago•63 comments

Earthquake scientists reveal how overplowing weakens soil at experimental farm

https://www.washington.edu/news/2026/03/19/earthquake-scientists-reveal-how-overplowing-weakens-s...
164•Brajeshwar•20h ago•71 comments

The Cassandra of 'The Machine'

https://www.thenewatlantis.com/publications/the-cassandra-of-the-machine
10•Hooke•6h ago•0 comments

Ashby (YC W19) Is Hiring Engineers Who Make Product Decisions

https://www.ashbyhq.com/careers?ashby_jid=c3c7125d-7883-4dff-a2bf-f5a55de4a364&utm_source=hn
1•abhikp•3h ago

Shell Tricks That Make Life Easier (and Save Your Sanity)

https://blog.hofstede.it/shell-tricks-that-actually-make-life-easier-and-save-your-sanity/
94•zdw•10h ago•42 comments

More precise elevation data for GraphHopper routing engine

https://www.graphhopper.com/blog/2026/03/23/more-precise-elevation-data-for-graphhopper/
49•karussell•2d ago•1 comments

My DIY FPGA board can run Quake II

https://blog.mikhe.ch/quake2-on-fpga/part4.html
160•sznio•3d ago•50 comments

The EU still wants to scan your private messages and photos

https://fightchatcontrol.eu/?foo=bar
1184•MrBruh•14h ago•315 comments

90% of Claude-linked output going to GitHub repos w <2 stars

https://www.claudescode.dev/?window=since_launch
293•louiereederson•16h ago•178 comments

Niche Museums

https://www.niche-museums.com/
6•bookofjoe•2d ago•1 comments

Show HN: Robust LLM Extractor for Websites in TypeScript

https://github.com/lightfeed/extractor
45•andrew_zhong•6h ago•33 comments

Supreme Court Sides with Cox in Copyright Fight over Pirated Music

https://www.nytimes.com/2026/03/25/us/politics/supreme-court-cox-music-copyright.html
350•oj2828•19h ago•270 comments

Show HN: Optio – Orchestrate AI coding agents in K8s to go from ticket to PR

https://github.com/jonwiggins/optio
54•jawiggins•17h ago•32 comments

Two studies in compiler optimisations

https://www.hmpcabral.com/2026/03/20/two-studies-in-compiler-optimisations/
82•hmpc•3d ago•7 comments

False claims in a widely-cited paper

https://statmodeling.stat.columbia.edu/2026/03/24/false-claims-in-a-published-no-corrections-no-c...
281•qsi•9h ago•110 comments

Thoughts on slowing the fuck down

https://mariozechner.at/posts/2026-03-25-thoughts-on-slowing-the-fuck-down/
869•jdkoeck•20h ago•393 comments

Maxell MXCP-P100 – wireless cassette player

https://maxell-usa.com/product/cassetteplayer/
25•ChrisArchitect•2d ago•14 comments

Quantization from the Ground Up

https://ngrok.com/blog/quantization
258•samwho•18h ago•48 comments

Government agencies buy commercial data about Americans in bulk

https://www.npr.org/2026/03/25/nx-s1-5752369/ice-surveillance-data-brokers-congress-anthropic
57•nuke-web3•4h ago•21 comments

Apple randomly closes bug reports unless you "verify" the bug remains unfixed

https://lapcatsoftware.com/articles/2026/3/11.html
409•zdw•15h ago•233 comments

Show HN: A plain-text cognitive architecture for Claude Code

https://lab.puga.com.br/cog/
101•marciopuga•11h ago•33 comments

"Disregard That" Attacks

https://calpaterson.com/disregard.html
83•leontrolski•11h ago•57 comments