frontpage.
newsnewestaskshowjobs

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.

StreetComplete: Fixing OpenStreetMap, one tiny quest at a time

https://streetcomplete.app/
474•kls0e•6h ago•112 comments

Amazon without the knockoffs

https://knockoff.shopping/
190•plurby•3h ago•126 comments

30papers.com – Ilya's 30 essential ML papers, in a beginner friendly format

https://30papers.com/
121•notmcrowley•2h ago•22 comments

A better way to tie gym shorts (or any drawstring) [video]

https://www.youtube.com/watch?v=3R0Lp86GEBk
338•surprisetalk•6h ago•127 comments

Astro 7.0

https://astro.build/blog/astro-7/
9•saikatsg•23m ago•1 comments

Chat Control 1.0 and 2.0 Explained

https://fightchatcontrol.eu/chat-control-overview
125•gasull•4h ago•16 comments

Jim's TrueType QR Code Font

https://github.com/jimparis/qr-font
45•arantius•2h ago•3 comments

Why we built yet another Postgres connection pooler

https://pgdog.dev/blog/why-yet-another-connection-pooler
45•levkk•3h ago•7 comments

MacSurf 1.68 – NetSurf on OS 9 Released

https://github.com/mplsllc/macsurf/releases/tag/v1.86
36•mplsllc•2h ago•3 comments

Chat Control passed first round in EU Parliament

https://www.heise.de/en/news/Showdown-in-Strasbourg-The-unexpected-return-of-Chat-Control-1-0-113...
355•miroljub•3h ago•153 comments

A new runtime for k and q: l

https://lv1.sh/
12•skruger•44m ago•0 comments

Microsoft fire idTech team at Id software

https://gamefromscratch.com/microsoft-fire-idtech-team-at-id-software/
330•bauc•3h ago•318 comments

9 Mothers (YC P26) Is Hiring in Austin, TX

https://9mothers.com/careers
1•ukd1•6h ago

Computational Balloon Twisting: The Theory of Balloon Polyhedra [pdf]

https://cccg.ca/proceedings/2008/paper34full.pdf
10•luu•5d ago•0 comments

The revenge of the philosophy majors

https://www.nytimes.com/2026/07/05/business/philosophy-majors-ai-jobs.html
83•benbreen•4h ago•116 comments

Show HN: Docx-CLI: agents read/edit Word docs using 1/2 the time and tokens

https://github.com/kklimuk/docx-cli
5•kirillklimuk•34m ago•1 comments

Mapping homes you can buy from the US government for <$100k

https://govauctions.app/research/cheapest-homes-in-america
72•player_piano•2h ago•63 comments

Automating AI Away

https://replicated.live/blog/away
38•gritzko•3h ago•21 comments

China sentences official to death for taking $325M in bribes

https://www.bbc.com/news/articles/c33y0n1v1xjo
103•randycupertino•2h ago•125 comments

Show HN: PostgreSQL performance and cost across 23 EC2 instance types

https://postgres.saneengineer.com
70•anivan_•6h ago•12 comments

Local, CPU-Friendly, High-Quality TTS (Text-to-Speech) with Kokoro

https://ariya.io/2026/03/local-cpu-friendly-high-quality-tts-text-to-speech-with-kokoro/
3•speckx•29m ago•0 comments

98% isn't much

https://whynothugo.nl/journal/2026/07/03/98-isnt-very-much/
378•speckx•6h ago•256 comments

Reducing Doom Loops with Final Token Preference Optimization

https://www.liquid.ai/blog/antidoom
14•dataminer•2h ago•3 comments

Why skilled workers come to Germany and then leave again

https://www.dw.com/en/germany-migrants-skilled-workers-integration-labor-market-bureaucracy-langu...
61•theanonymousone•8h ago•109 comments

Notes on Software Quality

https://anthonyhobday.com/blog/20260410
3•speckx•38m ago•0 comments

The family keeping watch over a 52-year-old pot of soup

https://www.wsj.com/arts-culture/food-cooking/the-family-keeping-watch-over-a-52-year-old-pot-of-...
64•petethomas•6d ago•51 comments

GitHub Freno: cooperative, highly available throttler service

https://github.com/github/freno
18•nateb2022•1d ago•0 comments

Software Bonkers

https://craigmod.com/essays/software_bonkers/
19•razin•3h ago•12 comments

C++ Details of Asymmetric Fences

https://nekrozqliphort.github.io/posts/membarrier/
51•anon_farmer•4d ago•4 comments

Europe's company websites are mostly served by US vendors

https://ciphercue.com/blog/european-web-hosting-vendor-share-2026
226•adulion•6h ago•158 comments