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

Comments

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

Apple is fighting for TSMC capacity as Nvidia takes center stage

https://www.culpium.com/p/exclusiveapple-is-fighting-for-tsmc
336•speckx•4h ago•231 comments

CVEs Affecting the Svelte Ecosystem

https://svelte.dev/blog/cves-affecting-the-svelte-ecosystem
57•tobr•1h ago•6 comments

Inside The Internet Archive's Infrastructure

https://hackernoon.com/the-long-now-of-the-web-inside-the-internet-archives-fight-against-forgetting
43•dvrp•1d ago•3 comments

25 Years of Wikipedia

https://wikipedia25.org
296•easton•5h ago•244 comments

Ask HN: How can we solve the loneliness epidemic?

49•publicdebates•2h ago•70 comments

Claude is good at assembling blocks, but still falls apart at creating them

https://www.approachwithalacrity.com/claude-ne/
28•bblcla•1d ago•8 comments

'Elite': The Palantir App ICE Uses to Find Neighborhoods to Raid

https://werd.io/elite-the-palantir-app-ice-uses-to-find-neighborhoods-to-raid/
8•sdoering•24m ago•0 comments

Found: Medieval Cargo Ship – Largest Vessel of Its Kind Ever

https://www.smithsonianmag.com/smart-news/archaeologists-say-theyve-unearthed-a-massive-medieval-...
56•bookofjoe•3h ago•8 comments

Show HN: TinyCity – A tiny city SIM for MicroPython (Thumby micro console)

https://github.com/chrisdiana/TinyCity
91•inflam52•4h ago•16 comments

Claude Cowork runs Linux VM via Apple virtualization framework

https://gist.github.com/simonw/35732f187edbe4fbd0bf976d013f22c8
18•jumploops•1d ago•6 comments

First impressions of Claude Cowork

https://simonw.substack.com/p/first-impressions-of-claude-cowork
40•stosssik•1d ago•7 comments

Denmark's struggle to break up with Silicon Valley

https://www.politico.eu/article/denmark-declared-war-against-big-tech-digital-sovereignty/
63•giuliomagnifico•1h ago•40 comments

The URL shortener that makes your links look as suspicious as possible

https://creepylink.com/
698•dreadsword•15h ago•131 comments

Show HN: Tabstack – Browser infrastructure for AI agents (by Mozilla)

36•MrTravisB•1d ago•3 comments

JuiceFS is a distributed POSIX file system built on top of Redis and S3

https://github.com/juicedata/juicefs
3•tosh•21m ago•0 comments

Zuck#: A programming language for connecting the world. And harvesting it

https://jayzalowitz.github.io/zucksharp/
24•kf•48m ago•16 comments

Supply Chain Vuln Compromised Core AWS GitHub Repos & Threatened the AWS Console

https://www.wiz.io/blog/wiz-research-codebreach-vulnerability-aws-codebuild
18•uvuv•1h ago•1 comments

Italy's privacy watchdog, scourge of US big tech, hit by corruption probe

https://www.reuters.com/sustainability/boards-policy-regulation/italys-privacy-watchdog-scourge-u...
32•giuliomagnifico•1h ago•9 comments

Ask HN: Anyone have a good solution for modern Mac to legacy SCSI converters?

9•stmw•1h ago•17 comments

Jiga (YC W21) Is Hiring Full Stack Engineers

https://jiga.io/about-us
1•grmmph•7h ago

OBS Studio 32.1.0 Beta 1 available

https://github.com/obsproject/obs-studio/releases/tag/32.1.0-beta1
109•Sean-Der•4h ago•27 comments

Sinclair C5

https://en.wikipedia.org/wiki/Sinclair_C5
69•jszymborski•4d ago•45 comments

Design and Implementation of Sprites

https://fly.io/blog/design-and-implementation/
67•sethev•3h ago•41 comments

Show HN: ContextFort – Visibility and controls for browser agents

https://contextfort.ai/
8•ashwinr2002•1d ago•1 comments

GitHub Incident

https://www.githubstatus.com/incidents/q987xpbqjbpl
88•aggrrrh•2h ago•69 comments

The 3D Software Rendering Technology of 1998's Thief: The Dark Project (2019)

https://nothings.org/gamedev/thief_rendering.html
105•suioir•8h ago•48 comments

Ask HN: Share your personal website

790•susam•1d ago•2124 comments

Annual Reboot: 52 Questions to Reflect and Reset

https://elacrain.com/writing/annual-review/
5•simonebrunozzi•3d ago•0 comments

Programming, Evolved: Lessons and Observations

https://github.com/kulesh/dotfiles/blob/main/dev/dev/docs/programming-evolved.md
38•dnw•5h ago•20 comments

Dutch experts warn US takeover of DigiD platform poses security risks

https://nltimes.nl/2026/01/15/dutch-experts-warn-us-takeover-digid-platform-poses-national-securi...
7•CalRobert•31m ago•0 comments