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

Comments

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

Cognitive Debt: When Velocity Exceeds Comprehension

https://www.rockoder.com/beyondthecode/cognitive-debt-when-velocity-exceeds-comprehension/
266•pagade•2h ago•110 comments

Obsidian Sync now has a headless client

https://help.obsidian.md/sync/headless
130•adilmoujahid•2h ago•50 comments

Addressing Antigravity Bans and Reinstating Access

https://github.com/google-gemini/gemini-cli/discussions/20632
128•RyanShook•4h ago•99 comments

Verified Spec-Driven Development (VSDD)

https://gist.github.com/dollspace-gay/d8d3bc3ecf4188df049d7a4726bb2a00
36•todsacerdoti•1h ago•12 comments

Woxi: Wolfram Mathematica Reimplementation in Rust

https://github.com/ad-si/Woxi
149•adamnemecek•3d ago•63 comments

New evidence that Cantor plagiarized Dedekind?

https://www.quantamagazine.org/the-man-who-stole-infinity-20260225/
40•rbanffy•3d ago•26 comments

Show HN: Now I Get It – Translate scientific papers into interactive webpages

https://nowigetit.us
90•jbdamask•5h ago•68 comments

Ghosts'n Goblins – “Worse danger is ahead”

https://superchartisland.com/ghostsn-goblins/
23•elvis70•3d ago•5 comments

747s and Coding Agents

https://carlkolon.com/2026/02/27/engineering-747-coding-agents/
60•cckolon•1d ago•17 comments

Werner Herzog Between Fact and Fiction

https://www.thenation.com/article/culture/werner-herzog-future-truth/
6•Hooke•1d ago•0 comments

How Long Is the Coast of Britain? (1967)

https://www.jstor.org/stable/1721427
7•Hooke•3d ago•1 comments

We Will Not Be Divided

https://notdivided.org
2344•BloondAndDoom•17h ago•744 comments

The whole thing was a scam

https://garymarcus.substack.com/p/the-whole-thing-was-scam
73•guilamu•1h ago•11 comments

Show HN: Tomoshibi – A writing app where your words fade by firelight

https://tomoshibi.in-hakumei.com/
5•hakumei•1h ago•0 comments

Show HN: SQLite for Rivet Actors – one database per agent, tenant, or document

https://github.com/rivet-dev/rivet
21•NathanFlurry•2h ago•6 comments

OpenAI fires an employee for prediction market insider trading

https://www.wired.com/story/openai-fires-employee-insider-trading-polymarket-kalshi/
170•bookofjoe•4h ago•103 comments

CSP for Pentesters: Understanding the Fundamentals

https://www.kayssel.com/newsletter/issue-20/
5•zdw•51m ago•0 comments

From Noise to Image – interactive guide to diffusion

https://lighthousesoftware.co.uk/projects/from-noise-to-image/
39•simedw•2d ago•8 comments

The Life Cycle of Money

https://doap.metal.bohyen.space/blog/post/complete-life-cycle-of-money/
51•nanacnote•5h ago•8 comments

Unsloth Dynamic 2.0 GGUFs

https://unsloth.ai/docs/basics/unsloth-dynamic-2.0-ggufs
145•tosh•9h ago•46 comments

The Eternal Promise: A History of Attempts to Eliminate Programmers

https://www.ivanturkovic.com/2026/01/22/history-software-simplification-cobol-ai-hype/
164•dinvlad•3d ago•119 comments

A new California law says all operating systems need to have age verification

https://www.pcgamer.com/software/operating-systems/a-new-california-law-says-all-operating-system...
759•WalterSobchak•1d ago•648 comments

Seeing Like a Sedan

https://asteriskmag.com/issues/13/seeing-like-a-sedan
10•surprisetalk•3d ago•1 comments

The Future of AI

https://lucijagregov.com/2026/02/26/the-future-of-ai/
58•BerislavLopac•7h ago•57 comments

Stop Burning Your Context Window – How We Cut MCP Output by 98% in Claude Code

https://mksg.lu/blog/context-mode
85•mksglu•8h ago•17 comments

The United States and Israel have launched a major attack on Iran

https://www.cnn.com/2026/02/28/middleeast/israel-attack-iran-intl-hnk
756•lavp•12h ago•1791 comments

OpenAI agrees with Dept. of War to deploy models in their classified network

https://twitter.com/sama/status/2027578652477821175
1208•eoskx•15h ago•579 comments

Don't trust AI agents

https://nanoclaw.dev/blog/nanoclaw-security-model
245•gronky_•5h ago•132 comments

Don't use passkeys for encrypting user data

https://blog.timcappalli.me/p/passkeys-prf-warning/
201•zdw•15h ago•170 comments

Latency numbers every programmer should know

https://cheat.sh/latency
54•ksec•5h ago•16 comments