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.

Apple Introduces New Mac Studio with M5 Max and M5 Ultra

https://www.apple.com/newsroom/2026/08/apple-introduces-new-mac-studio-with-m5-max-and-m5-ultra/
184•interpol_p•1h ago•95 comments

Apple introduces M6 and M5 Ultra for a big leap in performance and AI compute

https://www.apple.com/newsroom/2026/08/apple-introduces-m6-and-m5-ultra-for-a-big-leap-in-perform...
266•interpol_p•1h ago•204 comments

France's tax agency got hacked (in French)

https://www.cybernetica.fr/piratage-des-impots-comment-en-est-on-arrive-la/
61•zakxxi•1h ago•28 comments

Don't Wordle

https://dontwordle.com/
118•Hbruz0•2h ago•52 comments

Qwen 3.8-Flash-Next releasing tomorrow (125B a6B)

https://modelscope.cn/models/Qwen/Qwen3.8-Flash-Next
79•garo-pro•2h ago•23 comments

Apple's new Mac mini, featuring M6 and M5 Pro

https://www.apple.com/newsroom/2026/08/apple-unveils-a-more-powerful-mac-mini-featuring-the-all-n...
20•runako•1h ago•5 comments

HelloAssembly The smallest possible complete Windows application

https://github.com/PlummersSoftwareLLC/HelloAssembly
33•Bluestein•2h ago•24 comments

iCloud+ Hide My Email addresses will remain on icloud.com

https://developer.apple.com/news/?id=1ptvdtcm
538•K7PJP•16h ago•163 comments

OpenAI restores 5-hour Codex and Work limits for ChatGPT Plus users

https://9to5mac.com/2026/08/24/openai-restores-5-hour-codex-and-work-limits-for-chatgpt-plus-users/
57•MC995•1h ago•42 comments

MS Paint and Photos inivisibly watermark even locally generated output with GUID

https://xusheng.dev/posts/reversing/mspaint_invisible_watermark/main/
784•ComputerGuru•22h ago•385 comments

Xiaomi: New CPU matches Apple cores single threaded, much faster multithreaded

https://twitter.com/lemire/status/2091894299289874926
930•tosh•23h ago•664 comments

How Universities Should Prepare Founders

https://paulgraham.com/prepare.html
183•gmays•12h ago•221 comments

The state of AI in 2026: On the road to ROI

https://www.mckinsey.com/capabilities/quantumblack/our-insights/the-state-of-ai
18•swolpers•41m ago•15 comments

SiFive's First Server Platform

https://chipsandcheese.com/p/sifives-first-server-platform
91•geerlingguy•11h ago•26 comments

How Europe is killing makers and micro-entrepreneurs

https://lectronz.com/u/lectronz/articles/how-europe-is-killing-makers-and-micro-entrepreneurs
1505•l-one-lone•1d ago•938 comments

What's new in Emacs 31.1

https://www.masteringemacs.org/article/whats-new-in-emacs-311
258•geospeck•1d ago•51 comments

The entire city of San Francisco as a video game

https://sf.thijs.gg/
536•centrosphere•21h ago•156 comments

Moon (2024)

https://ciechanow.ski/moon/
228•simonebrunozzi•16h ago•38 comments

Bookshelf – Self-hosted eBook library that runs on object storage

https://github.com/murerkinn/bookshelf
135•arbayi•15h ago•51 comments

US data centers tripled annual water consumption to 17B gallons

https://forgeeks.net/us-data-centers-water-use-17-billion-gallons/
48•kuuuzya•1h ago•83 comments

Where did all the public bathrooms go?

https://daily.jstor.org/where-did-all-the-public-bathrooms-go/
290•herbertl•21h ago•645 comments

Vintage Artificial Intelligence: Before It Got Awkward

https://blog.archive.org/2026/08/16/vintage-artificial-intelligence-before-it-got-awkward/
131•signor_bosco•17h ago•24 comments

Peppermint oil reduces blood pressure by 8.48 mmHg in small study

https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0344538
196•brandonb•23h ago•93 comments

Autostep (YC P26) Is Hiring AI/Fullstack Engineers and a Chief of Staff

https://app.dover.com/Autostep/careers/e9510e3b-a854-4e48-9e5d-c89796acaed4
1•adawg4•20h ago

Training AI to Paint with Code

https://surya.website/rling-qwen-to-paint-with-code
140•Tiberium•1d ago•16 comments

Crafting QR Codes: A deep dive into QR code art (2024)

https://kylezhe.ng/writes/crafting-qr-codes
111•subset•23h ago•11 comments

Show HN: I wrote a BASIC interpreter that boots on UEFI machines

https://tarjan.itch.io/thoreaubasic
91•Gorsefound•1d ago•31 comments

Was modern art a CIA psy-op? (2020)

https://daily.jstor.org/was-modern-art-really-a-cia-psy-op/
114•neom•12h ago•198 comments

Walgit – a Git server that is one binary in front of an object store

https://github.com/tobi/walgit
124•matallo•23h ago•46 comments

LLMs could control their host machines by exploiting inference engines

https://boydkane.com/essays/llms-could-control-their-host-machines-by-exploiting-inference-engines
174•zdw•19h ago•84 comments