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.

How Bluesky draws its logo on screenshots

https://timmarinin.net/2026/bluesky-screenshots/
392•gavide•8h ago•264 comments

GPT-5.6 Sol Pricing Cut by 50%

https://openrouter.ai/openai/gpt-5.6-sol
323•Topfi•9h ago•170 comments

Quake Shareware, a CD-ROM just a little too full

https://fabiensanglard.net/quake_shareware_cd/index.html
270•shdon•8h ago•115 comments

The Benchmarkpocalypse

https://danluu.com/benchpocalypse/
53•cyndunlop•4h ago•7 comments

Shattered skeleton is first confirmed death from trebuchet

https://www.science.org/content/article/shattered-skeleton-scottish-castle-first-confirmed-death-...
47•hermitcrab•4d ago•29 comments

A Preview of DuckDB v2.0

https://duckdb.org/2026/08/17/duckdb-20-highlights
595•ibotty•16h ago•109 comments

Fairphone 6 and PostmarketOS working main camera

https://catcrafts.net/posts/fairphone-6-postmarketos-working-main-camera
136•pizzaiolo•8h ago•30 comments

Wellington second-hand bookstore's mysterious orders

https://www.rnz.co.nz/life/books/wellington-second-hand-book-store-s-mysterious-orders
55•beanaroo•1d ago•36 comments

AI-Generated GitHub Copilot “Autofix” Allowed Compromise of Snowflake's Jira

https://www.wiz.io/blog/red-agent-snowflake-copilot-cicd-bug
351•galnagli•16h ago•137 comments

The 37signals Manager Playbook

https://basecamp.com/managers
23•tosh•4d ago•1 comments

GPU Offload in Rust: Portable, Safe, and Fast

https://arxiv.org/abs/2608.13759
189•linggen•12h ago•37 comments

Olo (Color)

https://en.wikipedia.org/wiki/Olo_(color)
388•inigyou•5d ago•74 comments

The Road to MS-DOS 2.0

https://nemanjatrifunovic.substack.com/p/the-road-to-ms-dos-2
52•whobre•5d ago•19 comments

GPT 5.6 Sol is the best "vision" model OpenAI ever released

https://blog.roboflow.com/openai-gpt-5-6/
326•plurby•18h ago•158 comments

An update on leaving Gmail for Fastmail

https://moddedbear.com/an-update-on-leaving-gmail-for-fastmail/
174•neogodless•13h ago•120 comments

AI;DR (AI; Didn't Read)

https://www.rickmanelius.com/p/aidr-ai-didnt-read
757•mooreds•10h ago•487 comments

Israel creates fake think tank in likely attempt to dupe AI chatbots

https://responsiblestatecraft.org/israel-influence-chatgpt/
326•DeepLogin•9h ago•202 comments

Judge sets framework for Nine PBS to retrieve archival data

https://current.org/2026/08/judge-sets-framework-for-nine-pbs-to-retrieve-archival-data/
154•qingcharles•14h ago•59 comments

India has paved the way for charging merchants a fee on UPI transactions

https://www.bbc.com/news/articles/c8xnwqe00v1o
130•monkey_monkey•11h ago•158 comments

Los Puesteros, solitary men who look after ranches and livestock in Patagonia

https://www.newyorker.com/culture/photo-booth/the-lonely-men-at-the-end-of-the-world
132•bookofjoe•11h ago•46 comments

Sun Clock

https://sunclock.net/
208•Gecko4072•13h ago•66 comments

How to disable or avoid intrusive AI

https://www.librarian.net/notoai/
280•ColinWright•16h ago•165 comments

Repair Cafe – Fix Your Broken Items

https://www.repaircafe.org/
80•rglover•6h ago•10 comments

Ghosts of the Past and Devils of the Present

https://thenewcuriosityshop.substack.com/p/ghosts-of-the-past-and-devils-of
4•benbreen•1d ago•0 comments

How do functions like alloca allocate memory from the stack?

https://devblogs.microsoft.com/oldnewthing/20260817-40/?p=112617
48•ingve•9h ago•21 comments

Launch HN: Speko (YC S26) – OpenRouter for Voice AI

https://speko.ai/
99•abdik•14h ago•58 comments

A digestion of the proof of Sendov's conjecture

https://terrytao.wordpress.com/2026/08/12/a-digestion-of-the-proof-of-sendovs-conjecture/
22•surprisetalk•4d ago•8 comments

A particle made of force: physicists say they've found mysterious 'glueball'

https://www.nature.com/articles/d41586-026-02498-1
119•Brajeshwar•5d ago•31 comments

Ask HN: Alternatives to GitHub

557•dhruv3006•16h ago•355 comments

scScript for Linux

https://scapplications.com/
30•OptionOfT•8h ago•10 comments