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

Comments

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

The Tulip Creative Computer

https://github.com/shorepine/tulipcc
31•apitman•44m ago•8 comments

Influencers and OnlyFans models are dominating U.S. O-1 visa requests

https://www.theguardian.com/us-news/2026/jan/11/onlyfans-influencers-us-o-1-visa
72•bookofjoe•1h ago•33 comments

What a year of solar and batteries saved us in 2025

https://scotthelme.co.uk/what-a-year-of-solar-and-batteries-really-saved-us-in-2025/
142•MattSayar•2h ago•165 comments

Cowork: Claude Code for the rest of your work

https://claude.com/blog/cowork-research-preview
1174•adocomplete•22h ago•509 comments

Apple Creator Studio

https://www.apple.com/newsroom/2026/01/introducing-apple-creator-studio-an-inspiring-collection-o...
314•lemonlime227•3h ago•277 comments

Scott Adams has died

https://www.usatoday.com/story/entertainment/celebrities/2026/01/13/scott-adams-dead-dilbert-crea...
296•schmuckonwheels•1h ago•172 comments

Text-based web browsers

https://cssence.com/2026/text-based-web-browsers/
223•pabs3•12h ago•86 comments

Legion Health (YC S21) Hiring Cracked Founding Eng for AI-Native Ops

https://jobs.ashbyhq.com/legionhealth/ffdd2b52-eb21-489e-b124-3c0804231424
1•ympatel•53m ago

Show HN: An iOS budget app I've been maintaining since 2011

https://primoco.me/en/
95•Priotecs•7h ago•50 comments

Local Journalism Is How Democracy Shows Up Close to Home

https://buckscountybeacon.com/2026/01/opinion-local-journalism-is-how-democracy-shows-up-close-to...
286•mooreds•4h ago•199 comments

Git Rebase for the Terrified

https://www.brethorsting.com/blog/2026/01/git-rebase-for-the-terrified/
148•aaronbrethorst•5d ago•168 comments

TimeCapsuleLLM: LLM trained only on data from 1800-1875

https://github.com/haykgrigo3/TimeCapsuleLLM
703•admp•1d ago•290 comments

Everything you never wanted to know about file locking (2010)

https://apenwarr.ca/log/20101213
12•SmartHypercube•5d ago•3 comments

Postal Arbitrage

https://walzr.com/postal-arbitrage
508•The28thDuck•1d ago•259 comments

Show HN: SnackBase – Open-source, GxP-compliant back end for Python teams

https://snackbase.dev
43•lalitgehani•5h ago•6 comments

The chess bot on Delta Air Lines will destroy you (2024) [video]

https://www.youtube.com/watch?v=c0mLhHDcY3I
314•cjaackie•21h ago•313 comments

Indifference is a power

https://aeon.co/essays/why-stoicism-is-one-of-the-best-mind-hacks-ever-devised
162•suioir•3h ago•172 comments

The U.S. Government Just Followed Through on Its Ban of DJI Drones

https://www.popularmechanics.com/technology/robots/a69937082/us-bans-new-foreign-made-drones/
141•DamnInteresting•5d ago•154 comments

Unauthenticated remote code execution in OpenCode

https://cy.md/opencode-rce/
404•CyberShadow•1d ago•134 comments

Mozilla's open source AI strategy

https://blog.mozilla.org/en/mozilla/mozilla-open-source-ai-strategy/
113•nalinidash•5h ago•90 comments

Dilbert's Scott Adams Dies

https://www.inc.com/jennifer-conrad/scott-adams-dilbert-dies-at-68/91286247
16•MHofman12•22m ago•2 comments

Some ecologists fear their field is losing touch with nature

https://www.nature.com/articles/d41586-025-04150-w
153•Growtika•5d ago•72 comments

The Cray-1 Computer System (1977) [pdf]

https://s3data.computerhistory.org/brochures/cray.cray1.1977.102638650.pdf
131•LordGrey•3d ago•74 comments

Fabrice Bellard's TS Zip (2024)

https://www.bellard.org/ts_zip/
218•everlier•21h ago•84 comments

Robotopia: A 3D, first-person, talking simulator

https://elbowgreasegames.substack.com/p/introducing-robotopia-a-3d-first
87•psawaya•4d ago•36 comments

The UK is shaping a future of precrime and dissent management (2025)

https://freedomnews.org.uk/2025/04/11/how-the-uk-is-shaping-a-future-of-precrime-and-dissent-mana...
159•robtherobber•5h ago•181 comments

Chromium Has Merged JpegXL

https://chromium-review.googlesource.com/c/chromium/src/+/7184969
316•thunderbong•11h ago•98 comments

Anthropic has made a large contribution to the Python Software Foundation

https://discuss.python.org/t/anthropic-has-made-a-large-contribution-to-the-python-software-found...
232•ayhanfuat•2h ago•101 comments

Implementing a web server in a single printf() call (2014)

https://tinyhack.com/2014/03/12/implementing-a-web-server-in-a-single-printf-call/
70•nateb2022•4d ago•8 comments

Show HN: AI in SolidWorks

https://www.trylad.com
180•WillNickols•1d ago•98 comments