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

Comments

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

I am building a cloud

https://crawshaw.io/blog/building-a-cloud
253•bumbledraven•3h ago•108 comments

Alberta startup sells no-tech tractors for half price

https://wheelfront.com/this-alberta-startup-sells-no-tech-tractors-for-half-price/
1704•Kaibeezy•15h ago•544 comments

Apple fixes bug that cops used to extract deleted chat messages from iPhones

https://techcrunch.com/2026/04/22/apple-fixes-bug-that-cops-used-to-extract-deleted-chat-messages...
558•cdrnsf•11h ago•137 comments

We found a stable Firefox identifier linking all your private Tor identities

https://fingerprint.com/blog/firefox-tor-indexeddb-privacy-vulnerability/
664•danpinto•14h ago•186 comments

Ars Technica: Our newsroom AI policy

https://arstechnica.com/staff/2026/04/our-newsroom-ai-policy/
36•zdw•3h ago•22 comments

5x5 Pixel font for tiny screens

https://maurycyz.com/projects/mcufont/
579•zdw•3d ago•121 comments

A True Life Hack: What Physical 'Life Force' Turns Biology's Wheels?

https://www.quantamagazine.org/what-physical-life-force-turns-biologys-wheels-20260420/
59•Prof_Sigmund•1d ago•11 comments

The Onion to Take over InfoWars

https://www.nytimes.com/2026/04/20/business/infowars-alex-jones-the-onion.html
119•lxm•2d ago•18 comments

Over-editing refers to a model modifying code beyond what is necessary

https://nrehiew.github.io/blog/minimal_editing/
353•pella•14h ago•202 comments

Tempest vs. Tempest: The Making and Remaking of Atari's Iconic Video Game

https://tempest.homemade.systems
66•mwenge•7h ago•22 comments

Website streamed live directly from a model

https://flipbook.page/
256•sethbannon•14h ago•74 comments

Technical, cognitive, and intent debt

https://martinfowler.com/fragments/2026-04-02.html
257•theorchid•16h ago•66 comments

Plexus P/20 Emulator

https://spritetm.github.io/plexus_20_emu/
15•hggh•3d ago•1 comments

Borrow-checking without type-checking

https://www.scattered-thoughts.net/writing/borrow-checking-without-type-checking/
53•jamii•5h ago•13 comments

OpenAI's response to the Axios developer tool compromise

https://openai.com/index/axios-developer-tool-compromise/
67•shpat•7h ago•38 comments

Ping-pong robot beats top-level human players

https://www.reuters.com/sports/ping-pong-robot-ace-makes-history-by-beating-top-level-human-playe...
115•wslh•17h ago•129 comments

Parallel agents in Zed

https://zed.dev/blog/parallel-agents
221•ajeetdsouza•14h ago•120 comments

Verus is a tool for verifying the correctness of code written in Rust

https://verus-lang.github.io/verus/guide/
49•fanf2•2d ago•9 comments

Qwen3.6-27B: Flagship-Level Coding in a 27B Dense Model

https://qwen.ai/blog?id=qwen3.6-27b
824•mfiguiere•18h ago•383 comments

An amateur historian's favorite books about the Silk Road

https://bookdna.com/best-books/silk-road
6•bwb•1d ago•2 comments

Scoring Show HN submissions for AI design patterns

https://www.adriankrebs.ch/blog/design-slop/
305•hubraumhugo•17h ago•218 comments

Your hex editor should color-code bytes

https://simonomi.dev/blog/color-code-your-bytes/
3•tobr•1d ago•0 comments

Ultraviolet corona discharges on treetops during storms

https://www.psu.edu/news/earth-and-mineral-sciences/story/treetops-glowing-during-storms-captured...
229•t-3•18h ago•65 comments

Arch Linux Now Has a Bit-for-Bit Reproducible Docker Image

https://antiz.fr/blog/archlinux-now-has-a-reproducible-docker-image/
31•maxloh•6h ago•3 comments

Bodega cats of New York

https://bodegacatsofnewyork.com
190•zdw•5d ago•70 comments

Flow Map Learning via Nongradient Vector Flow [pdf]

https://openreview.net/pdf?id=C1bkDPqvDW
23•E-Reverance•5h ago•0 comments

Workspace Agents in ChatGPT

https://openai.com/index/introducing-workspace-agents-in-chatgpt/
132•mfiguiere•14h ago•50 comments

Windows 9x Subsystem for Linux

https://social.hails.org/@hailey/116446826733136456
944•sohkamyung•22h ago•224 comments

The handmade beauty of Machine Age data visualizations

https://resobscura.substack.com/p/the-handmade-beauty-of-machine-age
33•benbreen•17h ago•1 comments

What killed the Florida orange?

https://slate.com/business/2026/04/florida-state-orange-food-houses-real-estate.html
151•danso•2d ago•135 comments