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.

On Being a Human Being in the Time of Collapse (2022) [pdf]

https://web.cs.ucdavis.edu/~rogaway/papers/crisis/crisis.pdf
91•barishnamazov•1h ago•50 comments

OpenBSD-current now runs as guest under Apple Hypervisor

https://www.undeadly.org/cgi?action=article;sid=20260115203619
280•gpi•8h ago•27 comments

List of individual trees

https://en.wikipedia.org/wiki/List_of_individual_trees
148•wilson090•11h ago•49 comments

The spectrum of isolation: From bare metal to WebAssembly

https://buildsoftwaresystems.com/post/guide-to-execution-environments/
27•ThierryBuilds•2h ago•12 comments

Apple is fighting for TSMC capacity as Nvidia takes center stage

https://www.culpium.com/p/exclusiveapple-is-fighting-for-tsmc
698•speckx•20h ago•421 comments

Pocket TTS: A high quality TTS that gives your CPU a voice

https://kyutai.org/blog/2026-01-13-pocket-tts
461•pain_perdu•1d ago•106 comments

Interactive eBPF

https://ebpf.party/
37•samuel246•3h ago•1 comments

Briar keeps Iran connected via Bluetooth and Wi-Fi when the internet goes dark

https://briarproject.org/manual/fa/
390•us321•16h ago•210 comments

Cue Does It All, but Can It Literate?

https://xlii.space/cue/cue-does-it-all-but-can-it-literate/
16•xlii•3d ago•2 comments

pf: Make af-to less magical

https://undeadly.org/cgi?action=article;sid=20260116085115
13•defrost•2h ago•1 comments

Inside The Internet Archive's Infrastructure

https://hackernoon.com/the-long-now-of-the-web-inside-the-internet-archives-fight-against-forgetting
360•dvrp•2d ago•90 comments

Linux boxes via SSH: suspended when disconected

https://shellbox.dev/
225•messh•15h ago•129 comments

Bringing the Predators to Life in MAME

https://lysiwyg.mataroa.blog/blog/bringing-the-predators-to-life-in-mame/
23•msephton•2d ago•3 comments

Ask HN: How can we solve the loneliness epidemic?

612•publicdebates•19h ago•956 comments

Primecoin and Cunningham Prime Chains

https://www.johndcook.com/blog/2026/01/10/prime-chains/
21•ibobev•4d ago•6 comments

My Gripes with Prolog

https://buttondown.com/hillelwayne/archive/my-gripes-with-prolog/
106•azhenley•11h ago•53 comments

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

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

Show HN: BGP Scout – BGP Network Browser

https://bgpscout.io/
20•hivedc•11h ago•6 comments

All 23-Bit Still Lifes Are Glider Constructible

https://mvr.github.io/posts/xs23.html
98•HeliumHydride•11h ago•9 comments

Data is the only moat

https://frontierai.substack.com/p/data-is-your-only-moat
160•cgwu•17h ago•32 comments

Show HN: OpenWork – An open-source alternative to Claude Cowork

https://github.com/different-ai/openwork
193•ben_talent•2d ago•39 comments

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

https://github.com/juicedata/juicefs
153•tosh•17h ago•91 comments

Go-legacy-winxp: Compile Golang 1.24 code for Windows XP

https://github.com/syncguy/go-legacy-winxp/tree/winxp-compat
117•Oxodao•3d ago•56 comments

I Built a 1 Petabyte Server from Scratch [video]

https://www.youtube.com/watch?v=vVI7atoAeoo
83•zdw•5d ago•28 comments

Show HN: pgwire-replication - pure rust client for Postgres CDC

https://github.com/vnvo/pgwire-replication
4•sacs0ni•5d ago•3 comments

First impressions of Claude Cowork

https://simonw.substack.com/p/first-impressions-of-claude-cowork
200•stosssik•2d ago•113 comments

Building a better Bugbot

https://cursor.com/blog/building-bugbot
31•onurkanbkrc•5h ago•8 comments

Boeing knew of flaw in part linked to UPS plane crash, NTSB report says

https://www.bbc.com/news/articles/cly56w0p9e1o
182•1659447091•7h ago•81 comments

Tldraw pauses external contributions due to AI slop

https://github.com/tldraw/tldraw/issues/7695
135•pranav_rajs•12h ago•68 comments

CVEs affecting the Svelte ecosystem

https://svelte.dev/blog/cves-affecting-the-svelte-ecosystem
162•tobr•18h ago•28 comments