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.

Zed 1.0

https://zed.dev/blog/zed-1-0
848•salkahfi•3h ago•295 comments

The Abstraction Fallacy: Why AI can simulate but not instantiate consciousness

https://deepmind.google/research/publications/231971/
40•joshus•35m ago•26 comments

We need a federation of forges

https://blog.tangled.org/federation/
372•icy•4h ago•196 comments

FastCGI: 30 years old and still the better protocol for reverse proxies

https://www.agwa.name/blog/post/fastcgi_is_the_better_protocol_for_reverse_proxies
69•agwa•1h ago•9 comments

Online age verification is the hill to die on

https://x.com/GlennMeder/status/2049088498163216560
289•Cider9986•2h ago•178 comments

Soft launch of open-source code platform for government

https://www.nldigitalgovernment.nl/news/soft-launch-for-government-open-source-code-platform/
439•e12e•8h ago•109 comments

Ghostty is leaving GitHub

https://mitchellh.com/writing/ghostty-leaving-github
3217•WadeGrimridge•22h ago•951 comments

Third Editor Fired in Elsevier's Citation Cartel Crackdown

https://www.chrisbrunet.com/p/third-editor-fired-in-elseviers-citation
58•RigbyTaro•2h ago•13 comments

Linux 7.0 Broke PostgreSQL: The Preemption Regression Explained

https://read.thecoder.cafe/p/linux-broke-postgresql
82•0xKelsey•2h ago•27 comments

An open-source stethoscope that costs between $2.5 and $5 to produce

https://github.com/GliaX/Stethoscope
60•0x54MUR41•3h ago•26 comments

Cursor Camp

https://neal.fun/cursor-camp/
51•bpierre•2h ago•8 comments

How to Build the Future: Demis Hassabis [video]

https://www.youtube.com/watch?v=JNyuX1zoOgU
16•sandslash•3h ago•2 comments

Show HN: A new benchmark for testing LLMs for deterministic outputs

https://interfaze.ai/blog/introducing-structured-output-benchmark
21•khurdula•2h ago•5 comments

Mistral Medium 3.5

https://mistral.ai/news/vibe-remote-agents-mistral-medium-3-5
219•meetpateltech•2h ago•125 comments

Making AI chatbots friendly leads to mistakes and support of conspiracy theories

https://www.theguardian.com/technology/2026/apr/29/making-ai-chatbots-more-friendly-mistakes-supp...
40•Cynddl•2h ago•23 comments

Letting AI play my game – building an agentic test harness to help play-testing

https://blog.jeffschomay.com/letting-ai-play-my-game
87•jschomay•5h ago•17 comments

GitHub – DOS 1.0: Transcription of Tim Paterson's DOS Printouts

https://github.com/DOS-History/Paterson-Listings
78•s2l•6h ago•4 comments

Stardex Is Hiring a Founding Customer Success Lead

https://www.ycombinator.com/companies/stardex/jobs/6GCK1HC-founding-customer-success-lead
1•sanketc•6h ago

Ramp's Sheets AI Exfiltrates Financials

https://www.promptarmor.com/resources/ramps-sheets-ai-exfiltrates-financials
3•takira•21m ago•0 comments

Improving ICU handovers by learning from Scuderia Ferrari F1 team

https://healthmanagement.org/c/icu/IssueArticle/improving-handovers-by-learning-from-scuderia-fer...
43•embedding-shape•4h ago•43 comments

Maryland becomes first state to ban surveillance pricing in grocery stores

https://www.theguardian.com/technology/2026/apr/29/maryland-grocery-stores-ban-surveillance-pricing
45•01-_-•1h ago•15 comments

Bugs Rust won't catch

https://corrode.dev/blog/bugs-rust-wont-catch/
547•lwhsiao•15h ago•310 comments

Before GitHub

https://lucumr.pocoo.org/2026/4/28/before-github/
613•mlex•20h ago•201 comments

Show HN: Adblock-rust Manager – Firefox extension to enable the Brave ad blocker

https://github.com/electricant/adblock-rust-manager
62•electricant•5h ago•33 comments

Court Rules 2nd Amendment Covers Firearms Parts Good News Those Who Build Guns

https://cowboystatedaily.com/2026/04/28/court-rules-2nd-amendment-covers-firearms-parts-good-news...
59•Bender•1h ago•34 comments

How ChatGPT serves ads

https://www.buchodi.com/how-chatgpt-serves-ads-heres-the-full-attribution-loop/
460•lmbbuchodi•18h ago•317 comments

Laws of UX

https://lawsofux.com/
5•bobbiechen•1h ago•0 comments

Why Software Needs a Third Loop [audio]

https://www.heavybit.com/library/podcasts/third-loop/ep-3-give-it-a-name-why-software-needs-a-thi...
4•mooreds•1h ago•0 comments

Rise of the Forward Deployed Engineer

https://www.hfsresearch.com/research/fde-optional-ai-flywheel-spin/
4•nipponese•1h ago•1 comments

Why AI companies want you to be afraid of them

https://www.bbc.com/future/article/20260428-ai-companies-want-you-to-be-afraid-of-them
232•rolph•2h ago•171 comments