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.

SMPTE Makes Its Standards Freely Accessible

https://www.smpte.org/blog/smpte-makes-its-standards-freely-accessible-openingstandards-library-t...
114•zdw•3h ago•41 comments

The Wholesale Plagiarism of Obscure Sorrows

https://waxy.org/2026/06/the-wholesale-plagiarism-of-obscure-sorrows/
227•ridesisapis•2h ago•85 comments

UHF X11: X11 Built for VisionOS and Apple Vision Pro

https://www.lispm.net/apps/uhf-x11/
77•zdw•3h ago•9 comments

DOS Game "F-15 Strike Eagle II" reversing project needs DOS test pilots

https://neuviemeporte.github.io/f15-se2/2026/06/20/needyou.html
120•LowLevelMahn•5h ago•31 comments

PostgresBench: A Reproducible Benchmark for Postgres Services

https://clickhouse.com/blog/postgresbench
14•saisrirampur•1h ago•2 comments

CSSQuake

https://cssquake.com/
385•msalsas•9h ago•85 comments

Bun has an open PR adding shared-memory threads to JavaScriptCore

https://github.com/oven-sh/WebKit/pull/249
64•gr4vityWall•3h ago•76 comments

Show HN: StartupWiki – A Free Alternative to Crunchbase

https://startupwiki.tech/
81•shpran•4h ago•26 comments

Show HN: We post-trained a model that pen tests instead of refusing

https://www.argusred.com/cli
39•dk189•6h ago•19 comments

Show HN: Make PDFs look scanned (CLI or in the browser via WASM)

https://github.com/overflowy/make-look-scanned
23•overflowy•2h ago•12 comments

Ember, a native iOS Hacker News reader I built around accessibility

https://github.com/DatanoiseTV/ember-hackernews
67•sylwester•3h ago•14 comments

The rise of South Korea’s weapons business

https://www.politico.com/news/magazine/2026/06/20/south-korea-weapons-dealer-trump-00959559
34•JumpCrisscross•8h ago•11 comments

Why has the pointe shoe been so resistant to change?

https://dancemagazine.com/pointe-shoe-innovation/
28•onemind•19h ago•27 comments

Temporary Cloudflare accounts for AI agents

https://blog.cloudflare.com/temporary-accounts/
104•farhadhf•9h ago•73 comments

Google display wrong flags for world cup 2026

https://swiss-cow.com/blog/google-world-cup-wrong-flags
10•jimseinta•1h ago•4 comments

Now You Don't: When Espionage Meets Magic

https://www.politicshome.com/news/article/now-dont-espionage-meets-magic
11•thinkingemote•3d ago•1 comments

Show HN: Microcrad – Micrograd Reimplemented in C

https://github.com/oraziorillo/microcrad
43•oraziorillo•3d ago•13 comments

Show HN: Tiny – An interpeted dynamic langauge with inline Go native functions

https://github.com/confh/Tiny
9•confis•1h ago•3 comments

Show HN: My Windows XP portfolio with working Game Boy and iPod

https://mitchivin.com/
18•mitchivin•1h ago•8 comments

The ability to regrow body parts is dormant in mammals, not lost

https://www.sciencedaily.com/releases/2026/06/260617032207.htm
72•nryoo•2h ago•33 comments

Vacation With An Artist – Mini-Apprenticeships with Artists in Their Studios

https://vawaa.com/
45•karakoram•5h ago•5 comments

Where to Find the Colors Your Screen Can't Show You

https://moultano.wordpress.com/2026/06/19/where-to-find-the-colors-your-screen-cant-show-you/
393•moultano•16h ago•105 comments

Bootimus – A Self-Contained PXE and HTTP Boot Server

https://bootimus.com
89•car•9h ago•33 comments

Web Browsers on PDAS

https://vale.rocks/posts/pda-browsers
35•robin_reala•5h ago•12 comments

Windows 11 New Media Player Uses 3.5x More RAM, Charges for Popular Video Codecs

https://www.extremetech.com/computing/windows-11s-new-media-player-uses-35x-more-ram-charges-for-...
178•tcp_handshaker•6h ago•95 comments

I Stored a Website in a Favicon

https://www.timwehrle.de/blog/i-stored-a-website-in-a-favicon/
276•theanonymousone•14h ago•95 comments

AMD will reinstate memory encryption on Ryzen 9000 CPUs via BIOS update in July

https://www.tomshardware.com/pc-components/cpus/amd-will-reinstate-memory-encryption-on-ryzen-900...
18•roboror•1h ago•1 comments

Mencius (2016)

https://scholarworks.iu.edu/iuswrrest/api/core/bitstreams/265d73a0-6bfa-45df-92ff-4e7d3f8be4b1/co...
20•jruohonen•2d ago•1 comments

Can you see three trees?

https://www.not-ship.com/can-you-see-three-trees/
290•Pamar•2d ago•135 comments

GPT-5.5 hallucinates 3x more than MIT-licensed GLM-5.2

https://arrowtsx.dev/bigger-models/
459•oshrimpton•1d ago•228 comments