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.

Job: Head of Stonehenge

https://www.english-heritage.org.uk/about/our-people/careers-with-us/job-search/default-job-page/...
53•mooreds•1h ago•26 comments

Apple reveals new AI architecture built around Google Gemini models

https://www.macrumors.com/2026/06/08/apple-reveals-new-ai-architecture/
430•unclefuzzy•9h ago•357 comments

Siri AI

https://www.apple.com/apple-intelligence/
477•0xedb•10h ago•409 comments

Show HN: Performative-UI – A react component library of design tropes

https://vorpus.github.io/performativeUI/
851•lizhang•14h ago•162 comments

xAI is looking more like a datacentre REIT than a frontier lab

https://martinalderson.com/posts/xais-new-rental-business/
467•martinald•13h ago•359 comments

Old'aVista – The most powerful guide to the old Internet

https://oldavista.com/
21•abnercoimbre•12h ago•2 comments

MiMo-v2.5-Pro-UltraSpeed: 1T model with 1000 tokens per second

https://mimo.xiaomi.com/blog/mimo-tilert-1000tps
518•gainsurier•12h ago•375 comments

GoGoGrandparent (YC S16) is hiring Back end Engineers

https://www.ycombinator.com/companies/gogograndparent/jobs/2vbzAw8-backend-engineer
1•davidchl•47m ago

Anti-social: It's fads, not friends, which now dominate social media feeds

https://www.bbc.com/worklife/article/20260520-how-social-media-ceased-to-be-social
590•1vuio0pswjnm7•16h ago•423 comments

Apple Core AI Framework

https://developer.apple.com/documentation/coreai/
236•hmokiguess•9h ago•50 comments

EU-banned pesticides found in rice, tea and spices

https://www.foodwatch.org/en/eu-banned-pesticides-found-in-rice-tea-and-spices
277•john-titor•12h ago•103 comments

Looking Forward to Postgres 19: Query Hints

https://www.pgedge.com/blog/looking-forward-to-postgres-19-query-hints
89•jjgreen•3d ago•13 comments

Show HN: Gitdot – a better GitHub. Open-source, written in Rust

https://gitdot.io/
186•baepaul•11h ago•147 comments

Passing DBs through continuations

https://remy.wang/blog/cps.html
12•remywang•2d ago•0 comments

Why are cells small?

https://burrito.bio/essays/what-limits-a-cells-size
123•mailyk•9h ago•54 comments

Ask HN: What are tools you have made for yourself since the advent of AI?

192•aryamaan•9h ago•331 comments

Surveillance is not safety: A statement on the UK's latest threat to privacy [pdf]

https://signal.org/blog/pdfs/2026-06-08-uk-surveillance-is-not-safety.pdf
458•g0xA52A2A•8h ago•176 comments

How much do amd64 microarchitecture levels help in Go?

https://lemire.me/blog/2026/06/06/how-much-do-amd64-microarchitecture-levels-help-in-go/
15•zdw•1d ago•1 comments

FrontierCode

https://cognition.ai/blog/frontier-code
125•streamer45•7h ago•23 comments

Ask HN: Why hasn't there been a real competitor to Ticketmaster yet?

110•mdni007•10h ago•94 comments

I'm building a parallel internet, and it's called The Thinnernet

https://inavoyage.blogspot.com/2026/06/im-building-parallel-internet-and-its.html
59•initramfs•8h ago•58 comments

A Survey of Inlining Heuristics

https://bernsteinbear.com/blog/inlining-heuristics/
12•ibobev•4d ago•0 comments

Confidential submission of draft S-1 to the SEC

https://openai.com/index/openai-submits-confidential-s-1/
317•hackerBanana•6h ago•236 comments

Launch HN: Intuned (YC S22) – Build and run reliable browser automations as code

https://intunedhq.com
103•fkilaiwi•14h ago•44 comments

Apple bets cheaper AI will woo small developers

https://techcrunch.com/2026/06/08/apple-bets-cheaper-ai-will-woo-small-developers/
35•jbernardo95•7h ago•16 comments

AI is slowing down

https://www.wheresyoured.at/ai-is-slowing-down/
448•crescit_eundo•12h ago•469 comments

We Think the SpaceX IPO Is Overvalued

https://www.morningstar.com/stocks/why-we-think-spacex-ipo-is-overvalued?content_id=20768396545
159•0xedb•2h ago•149 comments

1worldflag: A blue dot on a transparent background

https://1worldflag.com/
180•davidbarker•1d ago•153 comments

Federal judge blocks H1B visa $100K fee

https://www.alaskasnewssource.com/2026/06/08/federal-judge-blocks-h1-b-visa-100k-fee/
109•naturalmovement•4h ago•175 comments

Games Between Programs: The Ruliology of Competition

https://writings.stephenwolfram.com/2026/06/games-between-programs-the-ruliology-of-competition/
17•andromaton•3d ago•0 comments