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•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.

Microsoft open-sources "the earliest DOS source code discovered to date"

https://arstechnica.com/gadgets/2026/04/microsoft-open-sources-the-earliest-dos-source-code-disco...
137•DamnInteresting•4h ago•27 comments

Why Is Vivado 2026.1 Dropping Linux Support for Free Tier?

https://adaptivesupport.amd.com/s/question/0D5Pd00001YQLdMKAX/why-is-vivado-20261-dropping-linux-...
32•zdw•1h ago•6 comments

Amazon Web Services – Four Years and Out

https://www.adventuresinoss.com/aws-four-years/
14•RyeCombinator•32m ago•0 comments

Scammers are abusing an internal Microsoft account to send spam links

https://techcrunch.com/2026/05/21/scammers-are-abusing-an-internal-microsoft-account-to-send-spam/
88•spike021•4h ago•17 comments

Wake up! 16b

https://hellmood.111mb.de/wake_up_16b_writeup.html
122•MaximilianEmel•4h ago•7 comments

Time to talk about my writerdeck

https://veronicaexplains.net/my-first-writerdeck/
340•hggh•10h ago•198 comments

Green card seekers must leave U.S. to apply, Trump administration says

https://www.nytimes.com/2026/05/22/us/politics/green-card-changes-trump.html
744•tlhunter•1d ago•1264 comments

Alexander Grothendieck Revolutionized 20th-Century Mathematics

https://www.quantamagazine.org/how-alexander-grothendieck-revolutionized-20th-century-mathematics...
12•anujbans•2h ago•1 comments

On The <dl> (2021)

https://benmyers.dev/blog/on-the-dl/
373•ravenical•16h ago•110 comments

My two-part desk setup (2025)

https://arslan.io/2025/11/18/my-two-part-desk-setup/
251•James72689•3d ago•148 comments

My I3-Emacs Integration

https://khz.ac/software/i3-integration.html
48•nosolace•6h ago•10 comments

Sales and Dungeons: Thermal printer TTRPG utility

https://sales-and-dungeons.app/
73•hyperific•1d ago•22 comments

Judson's Last Ride

https://www.realclearpolitics.com/articles/2026/05/22/judsons_last_ride_154150.html
77•NaOH•17h ago•4 comments

Schlitz Is Gone, but First It's Getting One Last Hurrah

https://www.milwaukeemag.com/schlitz-is-gone/
17•NaOH•2d ago•6 comments

The Art of Money Getting

https://kk.org/cooltools/book-freak-210-the-art-of-money-getting/
244•dxs•16h ago•143 comments

Byrne's Euclid

https://www.c82.net/euclid/
34•layer8•7h ago•10 comments

Buildcraft Is a Compiler Problem

https://mitander.xyz/posts/buildcraft-is-a-compiler-problem/
7•mitander•1d ago•0 comments

'Fuck you, Bambu': How one private message could change the face of 3D printing

https://www.theverge.com/tech/931532/bambu-agpl-pawel-jarczak-open-source-threat-dmca-github
17•tambourine_man•1h ago•4 comments

New map reveals lost roads of the Roman Empire

https://www.scientificamerican.com/article/new-high-resolution-map-transforms-what-we-know-about-...
62•sohkamyung•3d ago•7 comments

Hengefinder: Finding when the sun aligns with your street

https://victoriaritvo.com/blog/hengefinder/
127•evakhoury•1d ago•27 comments

.NET (OK, C#) finally gets union types

https://andrewlock.net/exploring-the-dotnet-11-preview-2-dotnet-gets-union-types/
174•ingve•1d ago•153 comments

Reverse engineering circuitry in a Spacelab computer from 1980

https://www.righto.com/2026/05/reverse-engineering-spacelab-computer.html
95•elpocko•12h ago•19 comments

Air France and Airbus found guilty of manslaughter over 2009 plane crash

https://www.bbc.com/news/articles/czd2qmdvmq6o
47•baal80spam•9h ago•24 comments

80386 microcode disassembled

https://www.reenigne.org/blog/80386-microcode-disassembled/
236•nand2mario•17h ago•46 comments

Show HN: Anyone interested in a tool helps to explore C++ ASTs

https://uvic-aurora.github.io/acav-manual/index.html
27•leomicv•2d ago•2 comments

-​-dangerously-skip-reading-code

https://olano.dev/blog/dangerously-skip/
128•fagnerbrack•19h ago•126 comments

Revised^7 Report on Scheme, Large: Procedural Fascicle Draft is now public

https://r7rs.org/large/fascicles/proc/
20•pmcgoron•3d ago•4 comments

Kindle loyalists scramble as Amazon turns page on old e-readers

https://www.reuters.com/business/retail-consumer/kindle-loyalists-scramble-amazon-turns-page-old-...
142•cf100clunk•4d ago•161 comments

PHP's Oddities

https://flowtwo.io/post/php%27s-oddities
110•thejoeflow•4d ago•129 comments

Show HN: Twixt – transform one word into another in four moves

https://twixt.games/
12•unseen_forms•2d ago•5 comments