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.

Since Chromium 148, Math.tanh is now fingerprintable to link underlying OS

https://scrapfly.dev/posts/browser-math-os-fingerprint/
234•joahnn_s•3h ago•112 comments

Cyberpunk Comics, Manga and Graphic Novels

https://shellzine.net/cyberpunk-comics/
31•zdw•1h ago•5 comments

Tiny Emulators

https://floooh.github.io/tiny8bit-preview/index.html
116•naves•3h ago•3 comments

So you want to learn physics (second edition, 2021)

https://www.susanrigetti.com/physics
62•azhenley•4d ago•5 comments

Designing and assembling my first PCB

https://vilkeliskis.com/b/2026/0711.html
16•tadasv•1h ago•2 comments

Ask HN: What Are You Working On? (July 2026)

43•david927•2h ago•102 comments

Migrating a production AI agent to GPT-5.6: 2.2x faster, 27% cheaper

https://ploy.ai/blog/migrating-a-production-ai-agent-to-gpt-5-6
112•brryant•7h ago•34 comments

Claude Code sends 33k tokens before reading the prompt; OpenCode sends 7k

https://systima.ai/blog/claude-code-vs-opencode-token-overhead
431•systima•5h ago•240 comments

How to Get What You Want

https://andys.blog/how-to-get-what-you-want/
9•andytratt•1h ago•0 comments

Old and new apps, via modern coding agents

https://terrytao.wordpress.com/2026/07/11/old-and-new-apps-via-modern-coding-agents/
400•subset•13h ago•114 comments

Kode Dot Programmable pocket device for makers, pentesters and geeks

https://kode.diy
31•iNic•2h ago•5 comments

Architecture Description Languages [pdf]

https://ics.uci.edu/~taylor/documents/2000-ADLs-TSE.pdf
10•ascent817•1h ago•1 comments

How we can reduce traffic congestion

https://research.google/blog/the-power-of-collaboration-how-we-can-reduce-traffic-congestion/
61•raahelb•8h ago•50 comments

I Learned to Read Again

https://substack.magazinenongrata.com/p/how-i-learned-to-read-again
81•georgex7•5h ago•38 comments

Mechanistic interpretability researchers applying causality theory to LLMs

https://cacm.acm.org/news/can-we-understand-how-large-language-models-reason/
79•adunk•6h ago•60 comments

LARP – Revenue infrastructure for serious founders

https://www.larp.website/
134•BerislavLopac•7h ago•32 comments

Why write code in 2026

https://softwaredoug.com/blog/2026/07/09/write-code
94•softwaredoug•2d ago•141 comments

A Speed Limit for Computers

https://caolan.uk/notes/2026-07-02_a_speed_limit_for_computers.cm
11•zdw•1h ago•8 comments

Profiling the "Abundance" housing bottleneck with real data

https://laxmena.com/same-capacity-less-throughput
11•laxmena•2h ago•3 comments

Irish datacenters now guzzle 23% of the country's electricity

https://www.theregister.com/on-prem/2026/07/11/irish-datacenters-now-guzzle-23-of-the-countrys-el...
194•Bender•3h ago•165 comments

Flash-MSA: Accelerating Million-Token Training with Sparse Attention Kernels

https://nanduruganesh.github.io/flash-msa/
16•rawsh•3h ago•0 comments

Automation Without Understanding

https://arxiv.org/abs/2607.06377
82•root-parent•7h ago•38 comments

Against Usefulness

https://www.motivenotes.ai/p/against-usefulness
78•supo•6h ago•21 comments

I love LLMs, I hate hype

https://geohot.github.io//blog/jekyll/update/2026/07/12/i-love-llms.html
293•therepanic•5h ago•176 comments

Deir El-Medina Strikes

https://en.wikipedia.org/wiki/Deir_el-Medina_strikes
59•mooreds•5d ago•14 comments

The One-Step Trap (In AI Research)

http://incompleteideas.net/IncIdeas/OneStepTrap.html
39•jxmorris12•5h ago•7 comments

Show HN: Agent Draw: An agent draws while you talk, built on TLDraw

https://techstackups.com/articles/tldraw-agent-draw/
42•jameswhitford•6d ago•15 comments

Nicotine pouches, tobacco's latest ploy

https://med.stanford.edu/news/insights/2026/06/nicotine-pouches-addiction-tobacco-industry-latest...
13•car•3d ago•1 comments

Lindsey Graham Dead at 71

https://www.economist.com/united-states/2026/07/12/lindsey-graham-represented-the-arc-of-his-party
6•andsoitis•1h ago•1 comments

Vint Cerf, “father of the Internet”, is retiring

https://techcrunch.com/2026/06/30/the-father-of-the-internet-is-finally-retiring/
274•compiler-guy•3d ago•160 comments