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.

Microgpt

http://karpathy.github.io/2026/02/12/microgpt/
691•tambourine_man•6h ago•115 comments

Switch to Claude Without Starting Over

https://claude.com/import-memory
41•doener•55m ago•23 comments

10-202: Introduction to Modern AI (CMU)

https://modernaicourse.org
15•vismit2000•57m ago•1 comments

We do not think Anthropic should be designated as a supply chain risk

https://twitter.com/OpenAI/status/2027846016423321831
503•golfer•11h ago•239 comments

The Windows 95 user interface: A case study in usability engineering (1996)

https://dl.acm.org/doi/fullHtml/10.1145/238386.238611
249•ksec•10h ago•144 comments

The happiest I've ever been

https://ben-mini.com/2026/the-happiest-ive-ever-been
467•bewal416•3d ago•232 comments

Obsidian Sync now has a headless client

https://help.obsidian.md/sync/headless
467•adilmoujahid•16h ago•159 comments

Sub-second volumetric 3D printing by synthesis of holographic light fields

https://www.nature.com/articles/s41586-026-10114-5
55•zdw•3d ago•11 comments

H-Bomb: A Frank Lloyd Wright Typographic Mystery

https://www.inconspicuous.info/p/h-bomb-a-frank-lloyd-wright-typographic
76•mrngm•2d ago•19 comments

Block the “Upgrade to Tahoe” Alerts

https://robservatory.com/block-the-upgrade-to-tahoe-alerts-and-system-settings-indicator/
217•todsacerdoti•13h ago•103 comments

Hardwood: A New Parser for Apache Parquet

https://www.morling.dev/blog/hardwood-new-parser-for-apache-parquet/
20•rmoff•2d ago•1 comments

Woxi: Wolfram Mathematica Reimplementation in Rust

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

Addressing Antigravity Bans and Reinstating Access

https://github.com/google-gemini/gemini-cli/discussions/20632
230•RyanShook•18h ago•190 comments

Verified Spec-Driven Development (VSDD)

https://gist.github.com/dollspace-gay/d8d3bc3ecf4188df049d7a4726bb2a00
181•todsacerdoti•15h ago•94 comments

MCP server that reduces Claude Code context consumption by 98%

https://mksg.lu/blog/context-mode
358•mksglu•22h ago•77 comments

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

https://nowigetit.us
233•jbdamask•19h ago•105 comments

Our Agreement with the Department of War

https://openai.com/index/our-agreement-with-the-department-of-war
290•surprisetalk•11h ago•216 comments

Cracking the Python Monorepo

https://gafni.dev/blog/cracking-the-python-monorepo/
9•amcvitty•2d ago•1 comments

SpacetimeDB ThreeJS Support

https://discourse.threejs.org/t/spacetimedb-threejs-support-and-free-tier/90052
19•ryker2000•3d ago•5 comments

Qwen3.5 122B and 35B models offer Sonnet 4.5 performance on local computers

https://venturebeat.com/technology/alibabas-new-open-source-qwen3-5-medium-models-offer-sonnet-4-...
336•lostmsu•12h ago•197 comments

New evidence that Cantor plagiarized Dedekind?

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

Werner Herzog Between Fact and Fiction

https://www.thenation.com/article/culture/werner-herzog-future-truth/
75•Hooke•2d ago•15 comments

Samsung Galaxy update removes Android recovery menu tools, including sideloading

https://9to5google.com/2026/02/27/samsung-galaxy-update-android-recovery-menu-removed/
105•pabs3•6h ago•21 comments

Building a Minimal Transformer for 10-digit Addition

https://alexlitzenberger.com/blog/post.html?post=/building_a_minimal_transformer_for_10_digit_add...
53•kelseyfrog•10h ago•8 comments

The Science of Detecting LLM-Generated Text

https://dl.acm.org/doi/10.1145/3624725
22•vinhnx•6h ago•6 comments

The whole thing was a scam

https://garymarcus.substack.com/p/the-whole-thing-was-scam
777•guilamu•15h ago•231 comments

The archivist preserving decaying floppy disks

https://www.popsci.com/technology/floppy-disk-archivist-project/
69•Brajeshwar•3d ago•13 comments

Deterministic Programming with LLMs

https://www.mcherm.com/deterministic-programming-with-llms.html
43•todsacerdoti•3d ago•24 comments

747s and coding agents

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

The Eternal Promise: A History of Attempts to Eliminate Programmers

https://www.ivanturkovic.com/2026/01/22/history-software-simplification-cobol-ai-hype/
272•dinvlad•4d ago•178 comments