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.

Alberta startup sells no-tech tractors for half price

https://wheelfront.com/this-alberta-startup-sells-no-tech-tractors-for-half-price/
1341•Kaibeezy•9h ago•473 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...
374•cdrnsf•5h ago•96 comments

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

https://fingerprint.com/blog/firefox-tor-indexeddb-privacy-vulnerability/
450•danpinto•8h ago•129 comments

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

https://qwen.ai/blog?id=qwen3.6-27b
708•mfiguiere•12h ago•342 comments

5x5 Pixel font for tiny screens

https://maurycyz.com/projects/mcufont/
438•zdw•3d ago•106 comments

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

https://nrehiew.github.io/blog/minimal_editing/
296•pella•8h ago•172 comments

Website streamed live directly from a model

https://flipbook.page/
158•sethbannon•8h ago•57 comments

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

https://tempest.homemade.systems
10•mwenge•1h ago•1 comments

Approximating Hyperbolic Tangent

https://jtomschroeder.com/blog/approximating-tanh/
24•jtomschroeder•2h ago•4 comments

Technical, cognitive, and intent debt

https://martinfowler.com/fragments/2026-04-02.html
200•theorchid•10h ago•47 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...
72•wslh•11h ago•84 comments

Our eighth generation TPUs: two chips for the agentic era

https://blog.google/innovation-and-ai/infrastructure-and-cloud/google-cloud/eighth-generation-tpu...
403•xnx•14h ago•197 comments

3.4M Solar Panels

https://tech.marksblogg.com/american-solar-farms-v2.html
291•marklit•14h ago•225 comments

The handmade beauty of Machine Age data visualizations

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

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

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

Scoring Show HN submissions for AI design patterns

https://www.adriankrebs.ch/blog/design-slop/
276•hubraumhugo•11h ago•201 comments

Effectful Recursion Schemes

https://effekt-lang.org/blog/recursion-schemes/
14•marvinborner•2d ago•1 comments

The Illuminated Man: an unconventional portrait of JG Ballard

https://www.theguardian.com/books/2026/apr/20/the-illuminated-man-by-christopher-priest-and-nina-...
49•agronaut•5h ago•16 comments

Parallel agents in Zed

https://zed.dev/blog/parallel-agents
165•ajeetdsouza•8h ago•101 comments

Another Day Has Come

https://daringfireball.net/2026/04/another_day_has_come
194•ndr42•1d ago•143 comments

Ultraviolet corona discharges on treetops during storms

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

Bring your own Agent to MS Teams

https://microsoft.github.io/teams-sdk/blog/bring-your-agent-to-teams/
18•umangsehgal93•3h ago•6 comments

The Neon King of New Orleans

https://gardenandgun.com/new-orleans-neon-king
35•renameme•4h ago•4 comments

Bodega cats of New York

https://bodegacatsofnewyork.com
158•zdw•4d ago•58 comments

What killed the Florida orange?

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

OpenAI's response to the Axios developer tool compromise

https://openai.com/index/axios-developer-tool-compromise/
6•shpat•1h ago•0 comments

Workspace Agents in ChatGPT

https://openai.com/index/introducing-workspace-agents-in-chatgpt/
104•mfiguiere•8h ago•39 comments

The great Scouse pasty war

https://www.livpost.co.uk/the-great-scouse-pasty-war/
44•DamonHD•2d ago•10 comments

GitHub CLI now collects pseudoanonymous telemetry

https://cli.github.com/telemetry
413•ingve•14h ago•301 comments

New study compares growing corn for energy to solar production

https://www.anthropocenemagazine.org/2025/04/new-study-compares-growing-corn-for-energy-to-solar-...
68•dotcoma•6h ago•104 comments