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

Comments

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

Hardware Attestation as Monopoly Enabler

https://grapheneos.social/@GrapheneOS/116550899908879585
1353•ChuckMcM•13h ago•451 comments

Local AI needs to be the norm

https://unix.foo/posts/local-ai-needs-to-be-norm/
981•cylo•14h ago•424 comments

The Greatest Shot in Television: James Burke Had One Chance to Nail This Scene (2024)

https://www.openculture.com/2024/10/the-greatest-shot-in-television.html
125•susam•4h ago•41 comments

Running local models on an M4 with 24GB memory

https://jola.dev/posts/running-local-models-on-m4
262•shintoist•8h ago•81 comments

I'm going back to writing code by hand

https://blog.k10s.dev/im-going-back-to-writing-code-by-hand/
279•dropbox_miner•6h ago•111 comments

7 lines of code, 3 minutes: Implement a programming language (2010)

https://matt.might.net/articles/implementing-a-programming-language/
39•azhenley•3h ago•8 comments

Obsidian plugin was abused to deploy a remote access trojan

https://cyber.netsecops.io/articles/obsidian-plugin-abused-in-campaign-to-deploy-phantom-pulse-rat/
178•cmbailey•9h ago•85 comments

An AI coding agent, used to write code, needs to reduce your maintenance costs

https://www.jamesshore.com/v2/blog/2026/you-need-ai-that-reduces-your-maintenance-costs
132•cratermoon•7h ago•34 comments

Incident Report: CVE-2024-YIKES

https://nesbitt.io/2026/02/03/incident-report-cve-2024-yikes.html
494•miniBill•13h ago•126 comments

Show HN: adamsreview – better multi-agent PR reviews for Claude Code

https://github.com/adamjgmiller/adamsreview
24•adamthegoalie•5h ago•6 comments

Seeing Birdsong

https://www.lucioarese.net/seeing-birdsong/
17•carabiner•3d ago•1 comments

How Fast Does Claude, Acting as a User Space IP Stack, Respond to Pings?

https://dunkels.com/adam/claude-user-space-ip-stack-ping/
64•adunk•8h ago•16 comments

Ask HN: What are you working on? (May 2026)

174•david927•14h ago•620 comments

dBase: 1979-2026

https://delphinightmares.substack.com/p/dbase-1979-2026
64•deeaceofbase•3d ago•17 comments

First tunnel element of the Fehmarnbelt Tunnel immersed

https://www.arup.com/en-us/news/first-fehmarnbelt-tunnel-element-lowered/
84•robin_reala•3d ago•19 comments

Mythos Finds a Curl Vulnerability

https://daniel.haxx.se/blog/2026/05/11/mythos-finds-a-curl-vulnerability/
23•TangerineDream•56m ago•4 comments

Guy Goma's Accidental BBC Interview Lives on After 20 Years

https://www.nytimes.com/2026/05/06/business/media/bbc-guy-goma-interview.html
100•nxobject•2d ago•21 comments

Traces Of Humanity

https://tracesofhumanity.org/hello-world/
153•alex77456•14h ago•21 comments

I returned to AWS and was reminded why I left

http://fourlightyears.blogspot.com/2026/05/i-returned-to-aws-and-was-reminded-hard.html
743•andrewstuart•1d ago•524 comments

The people preserving the scientific practice of bird banding

https://thenarwhal.ca/bird-banding-ontario/
51•bookofjoe•3d ago•0 comments

Stop MitM on the first SSH connection, on any VPS or cloud provider

https://www.joachimschipper.nl/Stop%20MITM%20on%20the%20first%20SSH%20connection,%20on%20any%20VP...
109•JoachimSchipper•2d ago•61 comments

Ice Cream Blending (1965) [pdf]

https://bitsavers.org/pdf/ibm/generalInfo/E20-0156-0_Linear_Programming_-_Ice_Cream_Blending.pdf
5•ok123456•2d ago•1 comments

Eight More '8-Bit Era' Microprocessors

https://thechipletter.substack.com/p/eight-more-8-bit-era-microprocessors
69•klelatti•2d ago•22 comments

The locals don't know

https://www.quarter--mile.com/The-Locals-Dont-Know
145•herbertl•15h ago•105 comments

Shelf Source: Tom MacWright

https://roadlessread.com/views/ss-macwright
13•tobr•1d ago•0 comments

Gode Cookery – Authentic Medieval Recipes

http://www.godecookery.com/godeboke/godeboke.htm
12•Mr_Minderbinder•3d ago•1 comments

Maryland citizens hit with $2B power grid upgrade for out-of-state AI

https://www.tomshardware.com/tech-industry/artificial-intelligence/maryland-citizens-slapped-with...
227•lemonberry•10h ago•126 comments

Idempotency is easy until the second request is different

https://blog.dochia.dev/blog/idempotency/
302•ludovicianul•3d ago•181 comments

Walking slower? Your ears, not your knees, might be the problem

https://www.wsj.com/health/wellness/hearing-loss-walking-speed-iphone-study-c53c482a
113•marc__1•1d ago•71 comments

Task Paralysis and AI

https://g5t.de/articles/20260510-task-paralysis-and-ai/index.html
229•MrGilbert•1d ago•113 comments