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.

OpenAI unveils its first custom chip, built by Broadcom

https://techcrunch.com/2026/06/24/openai-unveils-its-first-custom-chip-built-by-broadcom/
445•jamdesk•5h ago•283 comments

PostgreSQL Is Enough

https://gist.github.com/cpursley/c8fb81fe8a7e5df038158bdfe0f06dbb
28•Imustaskforhelp•43m ago•3 comments

Qualcomm to Acquire Modular

https://www.reuters.com/business/qualcomm-buy-ai-startup-modular-2026-06-24/
102•timmyd•9h ago•27 comments

RubyLLM: A Ruby framework for all major AI providers

https://rubyllm.com/
329•doener•8h ago•50 comments

Elastic lays off 7% of employees

https://www.elastic.co/blog/ceo-ash-kulkarni-announcement-to-elastic-employees
70•dakrone•1h ago•36 comments

We’re making Bunny DNS free

https://bunny.net/blog/were-making-bunny-dns-free/
824•dabinat•14h ago•251 comments

PR spam today looks like email spam in the early 2000s

https://www.greptile.com/blog/prs-on-openclaw
163•dakshgupta•8h ago•92 comments

Computer use in Gemini 3.5 Flash

https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-computer-use-...
137•swolpers•6h ago•87 comments

The Xteink X4 E-Ink Reader

https://blog.omgmog.net/post/xteink-x4-e-ink-reader/
138•felixdoerp•6h ago•100 comments

Robotics Teams Are Rebuilding the Data Stack from Scratch

https://rerun.io/blog/data-layer-tax
12•Tycho87•3d ago•1 comments

Crawling BitTorrent DHTs for Fun and Profit [pdf]

https://www.usenix.org/legacy/event/woot10/tech/full_papers/Wolchok.pdf
38•dgellow•3d ago•18 comments

45°C cooling design cuts data center water use to near zero

https://blogs.nvidia.com/blog/liquid-cooling-ai-factories/
123•nitin_flanker•9h ago•99 comments

There are a few things that I look back on as my mistakes in the early days

https://twitter.com/ID_AA_Carmack/status/2069799283369345247
464•shadowtree•7h ago•232 comments

GLM-5.2 is a step change for open agents

https://www.interconnects.ai/p/glm-52-is-the-step-change-for-open
84•vantareed•1d ago•28 comments

Show HN: Nub – A Bun-like all-in-one toolkit for Node.js

https://github.com/nubjs/nub
185•colinmcd•9h ago•52 comments

Show HN: LookAway, a Mac break reminder that knows when not to interrupt

https://lookaway.com
44•_kush•9h ago•6 comments

GitHub shouldn't be a dependency for publishing Rust on crates.io

https://infosec.exchange/@mttaggart/116806641273303255
121•speckx•3h ago•41 comments

Stealing Is a Skill

https://ben-mini.com/2026/stealing-is-a-skill
197•bewal416•10h ago•120 comments

Krea 2: SOTA open-weights 12B image model

https://www.krea.ai/blog/krea-2-technical-report
311•mattnewton•1d ago•35 comments

How the Fifth Lateran Council unlocked financial theory

https://sebastiangarren.com/2026/06/17/lending-is-meritorious-and-should-be-praised-how-the-fifth...
42•momentmaker•4d ago•4 comments

I can haz smoller NixOS ISOs?

https://natkr.com/2026-06-19-nixos-but-smol/
64•logickkk1•5d ago•20 comments

A Practical Guide to SSH Tunnels: Local and Remote Port Forwarding

https://labs.iximiuz.com/tutorials/ssh-tunnels
248•signa11•4d ago•53 comments

Pondering routing more of my traffic via nodes outside the UK

https://neilzone.co.uk/2026/06/pondering-routing-more-of-my-traffic-via-nodes-outside-the-uk-beca...
44•ColinWright•3d ago•31 comments

Running Windows Games on a Hobby OS with Wine

https://astral-os.org/posts/2026/04/03/wine-on-astral.html
93•avaliosdev•8h ago•30 comments

Show HN: Monolisa v3 – a typeface for developers and creatives

https://www.monolisa.dev/
148•bebraw•2d ago•49 comments

Exploiting vulnerabilities in Johnson and Johnson web apps

https://eaton-works.com/2026/06/24/jnj-webapp-hacks/
51•EatonZ•6h ago•2 comments

Thomann takes legal action against Fender

https://www.thomann.de/blog/en/inside/thomann-takes-legal-action-against-fender/
167•Audiophilip•4h ago•102 comments

Big AI labs are hiring philosophers

https://www.economist.com/science-and-technology/2026/06/24/why-big-ai-labs-are-hiring-so-many-ph...
103•Brajeshwar•6h ago•93 comments

I taught a bucket to speak Git

https://www.tigrisdata.com/blog/objgit/
72•xena•7h ago•16 comments

NSA lost access to Mythos amid Anthropic dispute

https://www.nytimes.com/2026/06/23/us/politics/nsa-lost-access-anthropic-tool.html
204•thm•11h ago•186 comments