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.

Claude Opus 4.7

https://www.anthropic.com/news/claude-opus-4-7
1380•meetpateltech•9h ago•1005 comments

Codex for almost everything

https://openai.com/index/codex-for-almost-everything/
627•mikeevans•6h ago•349 comments

A Better R Programming Experience Thanks to Tree-sitter

https://ropensci.org/blog/2026/04/02/tree-sitter-overview/
57•sebg•2h ago•1 comments

Guy builds AI driven hardware hacker arm from duct tape, old cam and CNC machine

https://github.com/gainsec/autoprober
60•scaredpelican•2h ago•9 comments

Official Clojure Documentary page with Video, Shownotes, and Links

https://clojure.org/about/documentary
77•adityaathalye•4h ago•16 comments

Android CLI: Build Android apps 3x faster using any agent

https://android-developers.googleblog.com/2026/04/build-android-apps-3x-faster-using-any-agent.html
89•ingve•5h ago•24 comments

New unsealed records reveal Amazon's price-fixing tactics, California AG claims

https://www.theguardian.com/us-news/ng-interactive/2026/apr/16/amazon-price-fixing-california-law...
54•kmfrk•1h ago•9 comments

Qwen3.6-35B-A3B: Agentic coding power, now open to all

https://qwen.ai/blog?id=qwen3.6-35b-a3b
865•cmitsakis•10h ago•406 comments

Qwen3.6-35B-A3B on my laptop drew me a better pelican than Claude Opus 4.7

https://simonwillison.net/2026/Apr/16/qwen-beats-opus/
267•simonw•6h ago•61 comments

Cloudflare's AI Platform: an inference layer designed for agents

https://blog.cloudflare.com/ai-platform/
223•nikitoci•10h ago•57 comments

Show HN: Marky – A lightweight Markdown viewer for agentic coding

https://github.com/GRVYDEV/marky
26•GRVYDEV•7h ago•6 comments

Join Akkari's Founding Team (YC P26) as an Engineer

1•michael_moore•2h ago

The future of everything is lies, I guess: Where do we go from here?

https://aphyr.com/posts/420-the-future-of-everything-is-lies-i-guess-where-do-we-go-from-here
478•aphyr•10h ago•510 comments

Launch HN: Kampala (YC W26) – Reverse-Engineer Apps into APIs

https://www.zatanna.ai/kampala
66•alexblackwell_•8h ago•61 comments

IBM AP-101 general-purpose computer [pdf]

https://gandalfddi.z19.web.core.windows.net/Shuttle/IBM%20AP-101S%20General%20Purpose%20Computer%...
15•__patchbit__•3d ago•4 comments

GPT‑Rosalind for life sciences research

https://openai.com/index/introducing-gpt-rosalind/
41•babelfish•4h ago•8 comments

Artifacts: Versioned storage that speaks Git

https://blog.cloudflare.com/artifacts-git-for-agents-beta/
146•jgrahamc•10h ago•15 comments

Python Package Compiler:Package Matlab Programs for Deployment as Python Package

https://www.mathworks.com/help/compiler_sdk/ml_code/pythonpackagecompiler-app.html
6•teleforce•3d ago•0 comments

Playdate’s handheld changed how Duke University teaches game design

https://news.play.date/news/duke-playdate-education/
40•Ivoah•4h ago•18 comments

George Orwell Predicted the Rise of "AI Slop" in Nineteen Eighty-Four (1949)

https://www.openculture.com/2026/04/how-george-orwell-predicted-the-rise-of-ai-slop.html
12•doener•42m ago•3 comments

Circuit Transformations, Loop Fusion, and Inductive Proof

https://natetyoung.github.io/carry_save_fusion/
20•matt_d•3d ago•1 comments

"Wretches, Speak Evil of Me": Goethe and Schiller's Xenions (1896 Edition)

https://publicdomainreview.org/collection/xenions/
3•benbreen•2d ago•0 comments

Show HN: CodeBurn – Analyze Claude Code token usage by task

https://github.com/AgentSeal/codeburn
69•agentseal•3d ago•14 comments

The "Passive Income" trap ate a generation of entrepreneurs

https://www.joanwestenberg.com/the-passive-income-trap-ate-a-generation-of-entrepreneurs/
107•devonnull•3h ago•87 comments

Show HN: MacMind – A transformer neural network in HyperCard on a 1989 Macintosh

https://github.com/SeanFDZ/macmind
110•hammer32•10h ago•31 comments

Codex Hacked a Samsung TV

https://blog.calif.io/p/codex-hacked-a-samsung-tv
200•campuscodi•13h ago•116 comments

AI cybersecurity is not proof of work

https://antirez.com/news/163
192•surprisetalk•13h ago•78 comments

Cloudflare Email Service

https://blog.cloudflare.com/email-for-agents/
397•jilles•10h ago•188 comments

European civil servants are being forced off WhatsApp

https://www.politico.eu/article/european-civil-servants-new-messaging-services/
82•aa_is_op•4h ago•49 comments

Six Characters

https://ajitem.com/blog/iron-core-part-2-six-characters/
85•Airplanepasta•3d ago•13 comments