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•1y ago

Comments

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

Setting up a free *.city.state.us locality domain (2025)

https://fredchan.org/blog/locality-domains-guide/
416•speckx•6h ago•132 comments

Linux gaming is faster because Windows APIs are becoming Linux kernel features

https://www.xda-developers.com/linux-gaming-is-getting-faster-because-windows-apis-are-becoming-l...
274•haunter•3d ago•203 comments

Rars: a Rust RAR implementation, mostly written by LLMs

https://bitplane.net/log/2026/05/rars/
58•davidsong•1h ago•35 comments

In-person examinations at Princeton will be proctored starting July 1

https://www.dailyprincetonian.com/article/2026/05/princeton-news-adpol-proctoring-in-person-exami...
139•bookofjoe•1h ago•158 comments

MacBook Neo Deep Dive: Benchmarks, Wafer Economics, and the 8GB Gamble

https://www.jdhodges.com/blog/macbook-neo-benchmarks-analysis/
90•tosh•3h ago•40 comments

A History of IDEs at Google

https://laurent.le-brun.eu/blog/a-history-of-ides-at-google
183•laurentlb•4d ago•153 comments

Chess puzzle I found in my dad's old book

https://ardoedo.it/kempelen/
25•Eswo•2d ago•4 comments

Xs of Y – roguelike that names itself every run. Written in 4kLoC

https://github.com/nooga/xsofy
130•andsoitis•3d ago•56 comments

The Emacsification of Software

https://sockpuppet.org/blog/2026/05/12/emacsification/
127•rdslw•14h ago•81 comments

Composer leaks contents of tokens configured as GitHub OAuth tokens

https://github.com/composer/composer/security/advisories/GHSA-f9f8-rm49-7jv2
52•damienwebdev•10h ago•20 comments

S-100 Virtual Workbench

https://grantmestrength.github.io/S100/
80•rbanffy•5h ago•18 comments

ReactOS

https://reactos.org/
64•DeathArrow•3h ago•20 comments

Launch HN: Ardent (YC P26) – Postgres sandboxes in seconds with zero migration

https://www.tryardent.com/
50•vc289•4h ago•20 comments

The great memory panic of 2026 – Asymco

https://asymco.com/2026/05/11/the-great-memory-panic-of-2026/
44•tambourine_man•2d ago•16 comments

The US is winning the AI race where it matters most: commercialization

https://avkcode.github.io/blog/us-winning-ai-race.html
128•akrylov•7h ago•352 comments

Making the news available at no cost is a victory

https://www.sltrib.com/opinion/commentary/2026/05/12/just-days-tribune-reporting/
81•danso•2h ago•88 comments

Reverting the incremental GC in Python 3.14 and 3.15

https://discuss.python.org/t/reverting-the-incremental-gc-in-python-3-14-and-3-15/107014
176•curiousgal•4d ago•60 comments

"Not Medically Necessary": Helping America's Health Insurers Deny Coverage

https://www.propublica.org/article/evicore-health-insurance-denials-cigna-unitedhealthcare-aetna-...
93•ceejayoz•2h ago•42 comments

Twin brothers wipe 96 government databases minutes after being fired

https://arstechnica.com/tech-policy/2026/05/drop-database-what-not-to-do-after-losing-an-it-job/
202•jnord•23h ago•140 comments

A sentimental tour of late 1990s and early 2000s hacking tools

https://andreafortuna.org/2026/05/13/amarcord/
25•speckx•3h ago•9 comments

New stainless steel can survive conditions for hydrogen production in seawater

https://www.sciencedaily.com/releases/2026/05/260510030950.htm
271•HardwareLust•2d ago•128 comments

Leaving GitHub for Forgejo

https://jorijn.com/en/blog/leaving-github-for-forgejo/
485•jorijn•8h ago•258 comments

An idiot's guide to lead optimisation for proteins

https://magnusross.github.io/posts/protein-lead-optimisation-1/
124•magni121•2d ago•10 comments

Exploring 8 Shaft Weaving

https://algorithmicpattern.org/2026/03/11/exploring-8-shaft-weaving/
12•surprisetalk•2d ago•0 comments

Substrate (YC S24) Is Hiring a Technical Success Manager

https://www.ycombinator.com/companies/substrate/jobs/T2fMBhD-technical-success-manager
1•kunle•9h ago

Meta won't let you block its AI account on Threads

https://www.theverge.com/tech/929091/meta-ai-threads-account-block
32•logickkk1•1h ago•9 comments

Preserving Fisher-Price Pixter

https://dmitry.gr/?r=05.Projects&proj=37.%20Pixter
194•dmitrygr•2d ago•39 comments

I moved my digital stack to Europe

https://monokai.com/articles/how-i-moved-my-digital-stack-to-europe/
824•monokai_nl•9h ago•512 comments

Show HN: Needle: We Distilled Gemini Tool Calling into a 26M Model

https://github.com/cactus-compute/needle
621•HenryNdubuaku•1d ago•179 comments

Open Source Resistance: keep OSS alive on company time

https://ossresistance.com/
224•mikemcquaid•6h ago•71 comments