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.

The map that keeps Burning Man honest

https://www.not-ship.com/burning-man-moop/
174•speckx•1h ago•48 comments

AlphaEvolve: Gemini-powered coding agent scaling impact across fields

https://deepmind.google/blog/alphaevolve-impact/
45•berlianta•39m ago•2 comments

Child marriages plunged when girls stayed in school in Nigeria

https://www.nature.com/articles/d41586-026-00796-2
90•surprisetalk•2h ago•46 comments

I Want to Live Like Costco People

https://tastecooking.com/i-want-to-live-like-costco-people/
18•speckx•22m ago•7 comments

The Self-Cancelling Subscription

https://predr.ag/blog/the-self-cancelling-subscription/
27•surprisetalk•1h ago•10 comments

RaTeX: KaTeX-compatible LaTeX rendering engine in pure Rust

https://ratex.lites.dev/
82•atilimcetin•2d ago•41 comments

Indian matchbox labels as a visual archive

https://www.itsnicethat.com/features/the-view-from-mumbai-matchbook-graphic-design-130426
90•sahar_builds•3d ago•26 comments

Valve releases Steam Controller CAD files under Creative Commons license

https://www.digitalfoundry.net/news/2026/05/valve-releases-steam-controller-cad-files-under-creat...
1626•haunter•23h ago•538 comments

Boris Cherny: TI-83 Plus Basic Programming Tutorial (2004)

https://www.ticalc.org/programming/columns/83plus-bas/cherny/
120•suoken•2d ago•52 comments

Grand Theft Oil Futures: Insider traders keep making a killing at our expense

https://paulkrugman.substack.com/p/grand-theft-oil-futures
308•Qem•4h ago•207 comments

SQLite Is a Library of Congress Recommended Storage Format

https://sqlite.org/locrsf.html
465•whatisabcdefgh•17h ago•146 comments

Appearing productive in the workplace

https://nooneshappy.com/article/appearing-productive-in-the-workplace/
1426•diebillionaires•23h ago•570 comments

GovernGPT (YC W24) Is Hiring Engineers to Build Thinking Systems in Montreal

https://www.ycombinator.com/companies/governgpt/jobs/hRyltS0-backend-engineer-thinking-systems
1•owalerys•3h ago

37x Speedup in Lattice Boltzmann Cylinder Flow

https://github.com/alikamp/Parks-KPBM-Scaling
18•kauai1•2d ago•2 comments

Agent-harness-kit scaffolding for multi-agent workflows (MCP, provider-agnostic)

https://ahk.cardor.dev
53•enmanuelmag•4h ago•14 comments

The brave souls who bought a used, 340k-mile rental camper van

https://www.thedrive.com/news/meet-the-brave-souls-who-bought-a-used-340000-mile-rental-camper-van
49•PaulHoule•1d ago•39 comments

Diskless Linux boot using ZFS, iSCSI and PXE

https://aniket.foo/posts/20260505-netboot/
147•stereo-highway•12h ago•83 comments

The mechanical latching memory of an adhesive tape

https://iopscience.iop.org/article/10.1088/1367-2630/ae4acc
12•gnabgib•1d ago•5 comments

Why should a Trace-ID be 128 bits? (A Surprisingly Long Answer)

https://newsletter.signoz.io/p/why-should-a-trace-id-be-128-bits
3•elza_1111•1d ago•0 comments

SingleRide: Longest route on NYC Subway without visiting the same station twice

https://singleride.nyc/
67•TMWNN•1d ago•30 comments

LinkedIn profile visitor lists belong to the people, says Noyb

https://www.theregister.com/offbeat/2026/05/05/noyb-cries-foul-on-linkedin-withholding-profile-vi...
152•robin_reala•4h ago•76 comments

Chevrolet Performance eCrate package (400v/200hp)

https://www.chevrolet.com/performance-parts/crate-engines/ecrate
109•mindcrime•2d ago•84 comments

Vibe coding and agentic engineering are getting closer than I'd like

https://simonwillison.net/2026/May/6/vibe-coding-and-agentic-engineering/
694•e12e•1d ago•777 comments

Permacomputing Principles

https://permacomputing.net/principles/
212•andsoitis•13h ago•135 comments

RSS feeds send me more traffic than Google

https://shkspr.mobi/blog/2026/05/rss-feeds-send-me-more-traffic-than-google/
200•SpyCoder77•15h ago•44 comments

ProgramBench: Can Language Models Rebuild Programs from Scratch?

https://arxiv.org/abs/2605.03546
103•jonbaer•11h ago•59 comments

Motherboard sales are now collapsing amid unprecedented shortages fueled by AI

https://www.tomshardware.com/pc-components/motherboards/motherboard-sales-collapse-by-more-than-2...
9•speckx•18m ago•1 comments

Google Cloud fraud defense, the next evolution of reCAPTCHA

https://cloud.google.com/blog/products/identity-security/introducing-google-cloud-fraud-defense-t...
365•unforgivenpasta•21h ago•374 comments

Show HN: Agent-skills-eval – Test whether Agent Skills improve outputs

https://github.com/darkrishabh/agent-skills-eval
46•darkrishabh•9h ago•20 comments

Making LLM Training Faster with Unsloth and NVIDIA

https://unsloth.ai/blog/nvidia-collab
96•segmenta•8h ago•15 comments