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...
284•DamnInteresting•10h ago•89 comments

Greg Brockman: Inside the 72 Hours That Almost Killed OpenAI

https://fs.blog/knowledge-project-podcast/greg-brockman/
35•prakashqwerty•3h ago•17 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-...
191•zdw•7h ago•77 comments

I spent 50 hours drawing a line graph

https://www.dougmacdowell.com/50-hours-to-draw-some-lines.html
60•dougdude3339•2d ago•6 comments

Wake up! 16b

https://hellmood.111mb.de/wake_up_16b_writeup.html
274•MaximilianEmel•11h ago•19 comments

Silk: Open-source cooperative fiber scheduler

https://github.com/ClickHouse/silk
40•animetyan•3d ago•4 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/
164•spike021•10h ago•76 comments

The C64 Dead Test Font

https://www.masswerk.at/nowgobang/2026/c64-dead-test-font
56•masswerk•7h ago•8 comments

Alexander Grothendieck Revolutionized 20th-Century Mathematics

https://www.quantamagazine.org/how-alexander-grothendieck-revolutionized-20th-century-mathematics...
74•anujbans•8h ago•13 comments

Time to talk about my writerdeck

https://veronicaexplains.net/my-first-writerdeck/
383•hggh•16h ago•230 comments

Converting an Integer to a Decimal String in Under Two Nanoseconds

https://onlinelibrary.wiley.com/doi/10.1002/spe.70079
42•mpweiher•4d ago•16 comments

On The <dl> (2021)

https://benmyers.dev/blog/on-the-dl/
401•ravenical•22h ago•116 comments

Swap tables, flash-friendly swap, swap_ops, and more

https://lwn.net/SubscriberLink/1072657/394b87abd7cc215e/
6•mkesper•3d ago•0 comments

All Lean Books and Where to Find Them

https://lakesare.brick.do/all-lean-books-and-where-to-find-them-x2nYwjM3AwBQ
7•atomicnature•3h ago•0 comments

My two-part desk setup (2025)

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

The Art of Money Getting

https://kk.org/cooltools/book-freak-210-the-art-of-money-getting/
306•dxs•22h ago•158 comments

My I3-Emacs Integration

https://khz.ac/software/i3-integration.html
81•nosolace•12h ago•22 comments

Sales and Dungeons: Thermal printer TTRPG utility

https://sales-and-dungeons.app/
100•hyperific•2d ago•32 comments

Judson's Last Ride

https://www.realclearpolitics.com/articles/2026/05/22/judsons_last_ride_154150.html
106•NaOH•23h ago•5 comments

Amazon Web Services – Four Years and Out

https://www.adventuresinoss.com/aws-four-years/
222•RyeCombinator•6h ago•75 comments

The Worlds Left to Conquer

https://ludic.mataroa.blog/blog/the-worlds-left-to-conquer/
8•pards•44m ago•3 comments

Key, in sight – A guide, of sorts, to keyboard customization

https://aresluna.org/key-in-sight/
14•anotherevan•4d ago•2 comments

Neoclassical C++: segmented iterators revisited

https://boostedcpp.net/2026/05/18/neoclassical-c-segmented-iterators-revisited-1/
31•ibobev•1d ago•11 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
901•tlhunter•1d ago•1509 comments

Hengefinder: Finding when the sun aligns with your street

https://victoriaritvo.com/blog/hengefinder/
152•evakhoury•1d ago•35 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-...
174•cf100clunk•4d ago•205 comments

80386 microcode disassembled

https://www.reenigne.org/blog/80386-microcode-disassembled/
253•nand2mario•23h ago•49 comments

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

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

-​-dangerously-skip-reading-code

https://olano.dev/blog/dangerously-skip/
155•fagnerbrack•1d ago•154 comments

Reverse engineering circuitry in a Spacelab computer from 1980

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