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.

Muse Spark Open

https://research.meta.ai/blog/muse-spark-open
392•bigwheels•2h ago•249 comments

Neural networks are clean

https://already-clean.goodfire.com/
322•themgt•4h ago•99 comments

E Ink Launches Latest Version of Color EPaper Platform, E Ink Kaleido 4

https://www.eink.com/news/detail/EInk-Launches-Latest-Version-of-Color-ePaper-Platform-E-Ink-Kale...
55•Perroboc•1h ago•17 comments

Wayland desktop for Linux with skeuomorphic design

https://github.com/fyzugx/DEsk
405•FinalDestiny•7h ago•165 comments

Krea 3 – An image model built for editing at scale

https://www.krea.ai/krea-3
181•dvrp•4h ago•66 comments

AdFection: Targeted ads turned into a pipeline for zero-click mercenary spyware

https://citizenlab.ca/research/how-discover-tech-turned-targeted-ads-into-a-pipeline-for-spyware/
283•jcomp•9h ago•448 comments

Why I Wrote PGP (1991, revised 1999)

https://philzimmermann.com/EN/essays/WhyIWrotePGP.html
50•GaryBluto•1d ago•10 comments

Celebrating 70 Years of Fortran

https://fortran-lang.org/news/2026/09-15-Fortran-birthday/
167•rbanffy•5h ago•67 comments

Delta’s Biscoff cookies were supposed to be temporary

https://www.seriouseats.com/biscoff-history-12168161
116•mhb•1d ago•106 comments

The engineering that allows articulated buses to bend

https://www.theautopian.com/you-wont-believe-the-incredible-engineering-that-allows-articulated-b...
26•CharlesW•19h ago•14 comments

Libreboot 26.10 "Ominous Olive" released with UEFI, Chromebook support

https://libreboot.org/news/libreboot2610.html
218•iamnothere•7h ago•124 comments

Show HN: Unfenced – Land for sale that borders public land

https://unfenced.land/
221•otherwatersflow•8h ago•156 comments

Simons Foundation launches $15M effort to help mathematicians navigate AI era

https://www.simonsfoundation.org/news/simons-foundation-launches-15m-effort-to-help-mathematician...
195•aaraujo002•5h ago•171 comments

The technical actions needed to ensure the continuity of UTC

https://www.bipm.org/en/cgpm-2026/resolution-5
75•gliffie•4h ago•34 comments

Show HN: Proa – A Rust web framework with fast SSR and multi-target rendering

https://proa.so/
59•burnrate•4h ago•10 comments

Jev Meets the Trolley Problem

https://zachlandes.com/trolley-problem/
131•zlandes86•4h ago•59 comments

Steam Client is now faster than Epic's new vibe coded launcher

https://respawnfirst.com/steam-client-is-now-faster-than-epics-new-vibe-coded-launcher/
203•starkparker•4h ago•222 comments

C++26 Contracts: Introduction to Preconditions and Postconditions

https://www.cppstories.com/2026/cpp26_contracts/
105•ibobev•7h ago•103 comments

I know why the mathematicians weep

https://www.derekthompson.org/p/i-know-why-the-mathematicians-weep
298•RickJWagner•6h ago•478 comments

Wanted to download an ISO, ended up writing a kernel exploit

https://blog.dfb.sh/blog/eap770-root-for-two-zeros/
317•0xdeafbeef•2d ago•156 comments

Show HN: My Terminal Themes Web App

24•bado•17h ago•14 comments

Show HN: Sygal – Convert PDFs, scans and web pages to Markdown, locally

https://sygal.app
26•cyrillsemah•3h ago•7 comments

Why We're Banning AI

https://www.currentaffairs.org/news/why-were-banning-ai
183•vinyl7•1h ago•137 comments

Rediscovering the Romance of Travel Clocks

https://www.acollectedman.com/blogs/journal/rediscovering-travel-clocks
4•austinallegro•2d ago•1 comments

Game of Life – But Multiplayer, Hypermedia and Python

https://stario.dev/apps/life
23•bobowski•1d ago•9 comments

"I'm a Lawyer." Said the White House Press Secretary. Florida Would Like a Word

https://chazstevens.substack.com/p/im-a-lawyer
14•embedding-shape•37m ago•0 comments

More on Anthropic's Scion ripping off Mononoke

https://sunshowers.io/posts/anthropic-mononoke-2/
191•sunshowers•3h ago•56 comments

The largest eagle hunted unlike any other bird of prey (2021)

https://www.nhm.ac.uk/discover/news/2021/december/worlds-largest-eagle-hunted-unlike-any-other-bi...
44•EndXA•2d ago•2 comments

We are entering a period of overlapping crises

https://hamishcampbell.com/we-are-entering-a-period-of-overlapping-crises/
22•speckx•1h ago•13 comments

Prompt injection in HTTP headers: what 217M web responses show

https://www.signalscorps.com/blog/prompt-injection-in-http-headers/
74•panoramas4good•5h ago•11 comments