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/
426•Kaibeezy•1h ago•148 comments

Coding Models Are Doing Too Much

https://nrehiew.github.io/blog/minimal_editing/
43•pella•35m ago•12 comments

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

https://qwen.ai/blog?id=qwen3.6-27b
350•mfiguiere•5h ago•201 comments

Windows 9x Subsystem for Linux

https://social.hails.org/@hailey/116446826733136456
720•sohkamyung•8h ago•167 comments

5x5 Pixel font for tiny screens

https://maurycyz.com/projects/mcufont/
95•zdw•3d ago•26 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...
289•xnx•6h ago•145 comments

Martin Fowler: Technical, Cognitive, and Intent Debt

https://martinfowler.com/fragments/2026-04-14.html
61•theorchid•2h ago•11 comments

Parallel Agents in Zed

https://zed.dev/blog/parallel-agents
30•ajeetdsouza•47m ago•6 comments

Ultraviolet corona discharges on treetops

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

3.4M Solar Panels

https://tech.marksblogg.com/american-solar-farms-v2.html
231•marklit•6h ago•154 comments

Surveillance Pricing: Exploiting Information Asymmetries

https://lpeproject.org/blog/surveillance-pricing-exploiting-information-asymmetries/
17•cainxinth•1h ago•4 comments

Bodega Cats of New York

https://bodegacatsofnewyork.com
69•zdw•4d ago•29 comments

Workspace Agents in ChatGPT

https://openai.com/index/introducing-workspace-agents-in-chatgpt/
12•mfiguiere•39m ago•1 comments

GitHub CLI now collects pseudoanonymous telemetry

https://cli.github.com/telemetry
313•ingve•6h ago•241 comments

Who Killed the Florida Orange?

https://slate.com/business/2026/04/florida-state-orange-food-houses-real-estate.html
44•danso•1d ago•22 comments

Scoring Show HN submissions for AI design patterns

https://www.adriankrebs.ch/blog/design-slop/
219•hubraumhugo•3h ago•167 comments

Columnar Storage Is Normalization

https://buttondown.com/jaffray/archive/columnar-storage-is-normalization/
76•ibobev•5h ago•29 comments

Youth Suicides Declined After Creation of National Hotline

https://www.nytimes.com/2026/04/22/science/988-youth-suicides-decline.html
94•marojejian•2h ago•48 comments

OpenAI: Workspace Agents for Business

https://openai.com/business/workspace-agents/
6•tosh•22m ago•2 comments

Making RAM at Home [video]

https://www.youtube.com/watch?v=h6GWikWlAQA
552•kaipereira•1d ago•156 comments

How does GPS work?

https://perthirtysix.com/how-the-heck-does-gps-work
181•alfanick•9h ago•37 comments

XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?

https://devblogs.microsoft.com/oldnewthing/20260421-00/?p=112247
163•ingve•11h ago•170 comments

Show HN: Broccoli, one shot coding agent on the cloud

https://github.com/besimple-oss/broccoli
16•yzhong94•2h ago•12 comments

Another Day Has Come

https://daringfireball.net/2026/04/another_day_has_come
137•ndr42•21h ago•118 comments

DuckDB 1.5.2 – SQL database that runs on laptop, server, in the browser

https://duckdb.org/2026/04/13/announcing-duckdb-152
87•janandonly•3h ago•25 comments

Anker made its own chip to bring AI to all its products

https://www.theverge.com/tech/916463/anker-thus-chip-announcement
26•Brajeshwar•1h ago•8 comments

Startups Brag They Spend More Money on AI Than Human Employees

https://www.404media.co/startups-brag-they-spend-more-money-on-ai-than-human-employees/
35•SLHamlet•1h ago•30 comments

Drunk post: Things I've learned as a senior engineer (2021)

https://luminousmen.substack.com/p/drunk-post-things-ive-learned-as
286•zdw•18h ago•207 comments

MuJoCo – Advanced Physics Simulation

https://github.com/google-deepmind/mujoco
97•modinfo•3d ago•21 comments

Prefill-as-a-Service:KVCache of Next-Generation Models Could Go Cross-Datacenter

https://arxiv.org/abs/2604.15039
42•matt_d•3d ago•1 comments