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

Comments

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

Gentoo Linux 2025 Review

https://www.gentoo.org/news/2026/01/05/new-year.html
76•akhuettel•2h ago•13 comments

"Food JPEGs" in Super Smash Bros. & Kirby Air Riders

https://sethmlarson.dev/food-jpegs-in-super-smash-bros-and-kirby-air-riders
66•SethMLarson•4d ago•7 comments

C++ std::move doesn't move anything: A deep dive into Value Categories

https://0xghost.dev/blog/std-move-deep-dive/
137•signa11•2d ago•84 comments

Think of Pavlov

https://boz.com/articles/think-pavlov
41•kiyanwang•3h ago•12 comments

BasiliskII Macintosh 68k Emulator Ported to ESP32-P4 / M5Stack Tab5

https://github.com/amcchord/M5Tab-Macintosh
14•rcarmo•2h ago•1 comments

The Concise TypeScript Book

https://github.com/gibbok/typescript-book
136•javatuts•8h ago•30 comments

Vojtux – Unofficial Linux Distribution Aimed at Visually Impaired Users

https://github.com/vojtapolasek/vojtux
80•TheWiggles•4d ago•24 comments

Iran Shuts Down Starlink Internet for First Time

https://www.forbes.com/sites/zakdoffman/2026/01/11/kill-switch-iran-shuts-down-starlink-internet-...
90•neom•1h ago•44 comments

More than one hundred years of Film Sizes

https://wichm.home.xs4all.nl/filmsize.html
50•exvi•6h ago•13 comments

Finding and fixing Ghostty's largest memory leak

https://mitchellh.com/writing/ghostty-memory-leak-fix
510•thorel•19h ago•109 comments

Show HN: I used Claude Code to discover connections between 100 books

https://trails.pieterma.es/
404•pmaze•21h ago•120 comments

'Bandersnatch': The Works That Inspired the 'Black Mirror' Interactive Feature (2019)

https://www.hollywoodreporter.com/tv/tv-news/black-mirror-bandersnatch-real-life-works-influences...
57•rafaepta•5d ago•23 comments

CPU Counters on Apple Silicon: article + tool

https://blog.bugsiki.dev/posts/apple-pmu/
117•verte_zerg•4d ago•0 comments

Code and Let Live

https://fly.io/blog/code-and-let-live/
375•usrme•1d ago•137 comments

Google: Don't make "bite-sized" content for LLMs

https://arstechnica.com/google/2026/01/google-dont-make-bite-sized-content-for-llms-if-you-care-a...
25•cebert•2h ago•15 comments

Show HN: Ferrite – Markdown editor in Rust with native Mermaid diagram rendering

https://github.com/OlaProeis/Ferrite
196•OlaProis•12h ago•109 comments

Open Chaos: A self-evolving open-source project

https://www.openchaos.dev/
392•stefanvdw1•22h ago•81 comments

A Year of Work on the Arch Linux Package Management (ALPM) Project

https://devblog.archlinux.page/2026/a-year-of-work-on-the-alpm-project/
83•susam•12h ago•24 comments

Outward Signs of Inner Mysteries

https://lareviewofbooks.org/article/outward-signs-of-inner-mysteries/
3•prismatic•4d ago•0 comments

Max Payne – two decades later – Graphics Critique (2021)

https://darkcephas.blogspot.com/2021/07/max-payne-two-decades-later-graphics.html
84•davikr•10h ago•25 comments

AI is a business model stress test

https://dri.es/ai-is-a-business-model-stress-test
283•amarsahinovic•21h ago•270 comments

HTML-only conditional lazy loading (via preload and media)

https://orga.cat/blog/html-conditional-lazy-loading/
10•netol•3h ago•1 comments

Overdose deaths are falling in America because of a 'supply shock': study

https://www.economist.com/united-states/2026/01/08/why-overdose-deaths-are-falling-in-america
174•marojejian•18h ago•149 comments

Show HN: Play poker with LLMs, or watch them play against each other

https://llmholdem.com/
138•projectyang•19h ago•71 comments

Show HN: Librario, a book metadata API that aggregates G Books, ISBNDB, and more

116•jamesponddotco•14h ago•40 comments

Show HN: I built an Open Source screen timer for the m5stickc (Arduino)

https://partridge.works/screenie-christmas-project-2025-26/
12•urbandw311er•5d ago•0 comments

An Experimental Approach to Printf in HLSL

https://www.abolishcrlf.org//2025/12/31/Printf.html
30•ibobev•4d ago•2 comments

LLM poetry and the "greatness" question: Experiments by Gwern and Mercor

https://hollisrobbinsanecdotal.substack.com/p/llm-poetry-and-the-greatness-question
15•networked•1h ago•0 comments

A battle over Canada’s mystery brain disease

https://www.bbc.com/news/articles/c623r47d67lo
172•lewww•9h ago•116 comments

Verifiable Brute Force Strength

https://gist.github.com/atoponce/a7715930ae6eb7d6b487f2f76b57a68d
6•upofadown•5d ago•1 comments