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

Project Hail Mary – Stellar Navigation Chart

https://valhovey.github.io/gaia-mary/
422•speleo•6h ago•111 comments

Flipper One – we need your help

https://blog.flipper.net/flipper-one-we-need-your-help/
992•sandebert•11h ago•402 comments

Blog ran on Ubuntu 16.04 for 10 years. I migrated it to FreeBSD

https://crocidb.com/post/this-blog-ran-on-ubuntu-16-04-for-10-years-i-migrated-it-to-freebsd/
107•speckx•4h ago•68 comments

Using Kagi Search with Low Vision

https://veroniiiica.com/using-kagi-search-with-low-vision/
74•speckx•3h ago•6 comments

Show HN: Freenet, a peer-to-peer platform for decentralized apps

https://freenet.org/
144•sanity•8h ago•66 comments

We're testing new ad formats in Search and expanding our Direct Offers pilot

https://blog.google/products/ads-commerce/google-marketing-live-search-ads/
539•sofumel•13h ago•474 comments

Was my $48K GPU server worth it?

https://rosmine.ai/2026/05/13/was-my-48k-gpu-worth-it/
209•apwheele•3d ago•162 comments

Indexing a year of video locally on a 2021 MacBook with Gemma4-31B (50GB swap)

https://blog.simbastack.com/indexed-a-year-of-video-locally/
250•asenna•8h ago•88 comments

Spotify will start reserving concert tickets for fans

https://www.hollywoodreporter.com/music/music-industry-news/spotify-will-start-reserving-concert-...
76•elffjs•6h ago•149 comments

Seattle Shield, an intelligence-sharing network operated by the Seattle police

https://prismreports.org/2026/05/20/seattle-shield-private-companies-surveillance/
378•root-parent•5h ago•155 comments

Launch HN: Runtime (YC P26) – Sandboxed coding agents for everyone on a team

https://www.runtm.com/
49•gustrigos•6h ago•19 comments

Waymo pauses Atlanta service as its robotaxis keep driving into floods

https://techcrunch.com/2026/05/21/waymo-pauses-atlanta-service-as-its-robotaxis-keep-driving-into...
206•mattas•6h ago•257 comments

Python 3.15: features that didn't make the headlines

https://blog.changs.co.uk/python-315-features-that-didnt-make-the-headlines.html
314•rbanffy•11h ago•146 comments

BBEdit 16

https://www.barebones.com/products/bbedit/bbedit16.html
235•qaz_plm•4h ago•70 comments

Triangle Tessellation with Clamped Parallelograms

https://filmicworlds.com/blog/compute-tessellation-with-clamped-parallelograms/
9•ibobev•2d ago•0 comments

Lost Images from the 1945 Trinity Nuclear Test Restored

https://spectrum.ieee.org/trinity-nuclear-test
264•pseudolus•11h ago•85 comments

Show HN: Agent.email – sign up via curl, claim with a human OTP

44•adisingh13•6h ago•47 comments

ParadeDB (YC S23) Is Hiring Distributed Systems/Platform Engineers

1•philippemnoel•5h ago

News outlets are limiting the Internet Archive’s access to their journalism

https://www.niemanlab.org/2026/05/more-than-340-local-news-outlets-are-limiting-the-internet-arch...
187•jaredwiener•5h ago•65 comments

Where are all the UK red telephone kiosks?

https://www.thek6project.co.uk/
61•Kaibeezy•4h ago•37 comments

Mounting git commits as folders with NFS (2023)

https://jvns.ca/blog/2023/12/04/mounting-git-commits-as-folders-with-nfs/
86•pvtmert•2d ago•44 comments

Google's Antigravity bait and switch

https://www.0xsid.com/blog/antigravity-bait-n-switch
476•ssiddharth•9h ago•248 comments

Multi-Stream LLMs: new paper on parallelizing/separating prompts, thinking, I/O

https://arxiv.org/abs/2605.12460
35•atomicthumbs•3h ago•2 comments

Museum of Pocket Calculating Devices

https://www.calculators.de/
61•ohjeez•7h ago•13 comments

Throwing AI-generated walls of text into conversations

https://noslopgrenade.com/
451•napolux•13h ago•270 comments

Vivaldi 8.0

https://vivaldi.com/blog/vivaldi-on-desktop-8-0/
328•OuterVale•15h ago•222 comments

Shira: Anti Phishing Training Platform

https://shira.app/
5•carohadad•1h ago•1 comments

Thoughts on People and Blogs

https://afranca.com.br/thoughts-on-people-and-blogs/
20•meysamazad•2d ago•4 comments

Show HN: Open-source .docx editor library for building document apps

https://github.com/eigenpal/docx-editor
10•thisisjedr•2h ago•0 comments

Chewing gum restores dad's taste and smell years after Covid

https://discover.swns.com/2026/05/chewing-gum-restores-dads-taste-and-smell-years-after-covid/
130•speckx•5h ago•68 comments