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

Comments

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

Keep Android Open

https://f-droid.org/2026/02/20/twif.html
1306•LorenDB•12h ago•499 comments

Meta Deployed AI and It Is Killing Our Agency

https://mojodojo.io/blog/meta-is-systematically-killing-our-agency/
45•zenincognito•2h ago•20 comments

Turn Dependabot Off

https://words.filippo.io/dependabot/
381•todsacerdoti•9h ago•98 comments

I found a Vulnerability. They found a Lawyer

https://dixken.de/blog/i-found-a-vulnerability-they-found-a-lawyer
473•toomuchtodo•11h ago•203 comments

Facebook is cooked

https://pilk.website/3/facebook-is-absolutely-cooked
943•npilk•12h ago•535 comments

Ggml.ai joins Hugging Face to ensure the long-term progress of Local AI

https://github.com/ggml-org/llama.cpp/discussions/19759
708•lairv•16h ago•177 comments

CERN rebuilt the original browser from 1989 (2019)

https://worldwideweb.cern.ch
140•tylerdane•7h ago•49 comments

Wikipedia deprecates Archive.today, starts removing archive links

https://arstechnica.com/tech-policy/2026/02/wikipedia-bans-archive-today-after-site-executed-ddos...
381•nobody9999•12h ago•225 comments

What Is OAuth?

https://leaflet.pub/p/did:plc:3vdrgzr2zybocs45yfhcr6ur/3mfd2oxx5v22b
85•cratermoon•5h ago•18 comments

Microsoft team creates 'revolutionary' data storage system that lasts millennia

https://www.nature.com/articles/d41586-026-00502-2
24•gnabgib•2d ago•9 comments

Index, Count, Offset, Size

https://tigerbeetle.com/blog/2026-02-16-index-count-offset-size/
60•ingve•2d ago•13 comments

Every company building your AI assistant is now an ad company

https://juno-labs.com/blogs/every-company-building-your-ai-assistant-is-an-ad-company
157•ajuhasz•11h ago•78 comments

OpenScan

https://openscan.eu/pages/scan-gallery
134•joebig•9h ago•5 comments

Cord: Coordinating Trees of AI Agents

https://www.june.kim/cord
61•gfortaine•5h ago•23 comments

Show HN: Mines.fyi – all the mines in the US in a leaflet visualization

https://mines.fyi/
69•irasigman•9h ago•40 comments

Blue light filters don't work – controlling total luminance is a better bet

https://www.neuroai.science/p/blue-light-filters-dont-work
150•pminimax•12h ago•170 comments

Across the US, people are dismantling and destroying Flock surveillance cameras

https://www.bloodinthemachine.com/p/across-the-us-people-are-dismantling
273•latexr•7h ago•121 comments

SwiftForth IDE for Windows, Linux, macOS

https://www.forth.com/swiftforth/
16•tosh•3d ago•2 comments

The path to ubiquitous AI (17k tokens/sec)

https://taalas.com/the-path-to-ubiquitous-ai/
707•sidnarsipur•20h ago•402 comments

Don't create .gitkeep files, use .gitignore instead (2023)

https://adamj.eu/tech/2023/09/18/git-dont-create-gitkeep/
69•frou_dh•8h ago•39 comments

Trump's global tariffs struck down by US Supreme Court

https://www.bbc.com/news/live/c0l9r67drg7t
1345•blackguardx•15h ago•1091 comments

Making frontier cybersecurity capabilities available to defenders

https://www.anthropic.com/news/claude-code-security
111•surprisetalk•12h ago•51 comments

The true story behind the Toronto mystery tunnel

https://macleans.ca/society/elton-mcdonald-and-the-incredible-true-story-behind-the-toronto-myste...
58•mhb•3d ago•11 comments

Lil' Fun Langs

https://taylor.town/scrapscript-000
110•surprisetalk•13h ago•15 comments

Colorado moves age checks from websites to operating systems

https://www.biometricupdate.com/202602/colorado-moves-age-checks-from-websites-to-operating-systems
9•iamnothere•43m ago•7 comments

Show HN: A native macOS client for Hacker News, built with SwiftUI

https://github.com/IronsideXXVI/Hacker-News
198•IronsideXXVI•16h ago•141 comments

Reproducible and traceable configuration for Conan C and C++ package manager

https://blog.conan.io/cpp/conan/configuration/reproducibility/lockfile/2026/02/17/Reproducible-Co...
11•ibobev•2d ago•2 comments

Untapped Way to Learn a Codebase: Build a Visualizer

https://jimmyhmiller.com/learn-codebase-visualizer
213•andreabergia•21h ago•36 comments

Building a model that visualizes strategic golf

https://golfcoursewiki.substack.com/p/i-spent-the-last-month-and-a-half
51•scoofy•4d ago•15 comments

How to Review an AUR Package

https://bertptrs.nl/2026/01/30/how-to-review-an-aur-package.html
64•exploraz•3d ago•11 comments