frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Critical CVE issued for hallucinated SQLite vulnerability

https://research.jfrog.com/post/sqlite-critical-cves-or-llm-slops/
549•ymir_e•4h ago•185 comments

Devtools must be open source

https://blog.exe.dev/devtools-must-be-open-source
125•bryanmikaelian•2h ago•42 comments

MiniMax H3 Day-0 Support in ComfyUI: Open Weights, Native Audio, and 2K Video

https://blog.comfy.org/p/minimax-h3-day-0-support-in-comfyui
123•vblanco•2h ago•43 comments

Taylor Farms Has Rewritten Its Cyclospora Statement Four Times in Sixteen Days

https://www.marlerblog.com/case-news/taylor-farms-has-rewritten-its-cyclospora-statement-four-tim...
103•speckx•56m ago•36 comments

Hollywood Stopped Making Movies in Hollywood

https://www.statsignificant.com/p/how-hollywood-stopped-making-movies
59•speckx•6d ago•35 comments

Don't be a meat proxy

https://gruhn.me/blog/2026-08-03/
1350•ngruhn•9h ago•566 comments

Andy Pavlo Joins ClickHouse to Establish ClickHouse Labs

https://clickhouse.com/blog/andy-pavlo-joins-clickhouse
81•nikolay_sivko•2h ago•18 comments

Qwen3.8-Max: A New Bar for Coding and Cowork

https://qwen.ai/blog?id=qwen3.8
905•ai2027•14h ago•466 comments

AirLLM 70B inference with single 4GB GPU

https://github.com/lyogavin/airllm
105•Anon84•5h ago•39 comments

Bonsai: Janestreet's UI Library

https://github.com/janestreet/bonsai
198•KolmogorovComp•7h ago•74 comments

SPF Record Syntax: Mechanisms, Qualifiers, Modifiers, and Macros

https://dmarcguard.io/blog/spf-record-syntax/
25•meysamazad•2h ago•7 comments

The Abandoned Fish Sauce Terrorizing a Small Canadian Town

https://defector.com/abandoned-fish-sauce-canada-interview
136•ohjeez•3d ago•100 comments

Rust project goals: Immobile types and guaranteed destructors

https://github.com/rust-lang/rust-project-goals/blob/main/src/2026/move-trait.md
179•paavohtl•9h ago•63 comments

Prevent cognitive debt by manually retyping LLM-generated code

https://ankursethi.com/blog/prevent-cognitive-debt-by-manually-retyping-llm-generated-code/
263•mpweiher•6h ago•228 comments

Show HN: Nightcrawler – A local AI pentesting agent running on a smartphone

https://github.com/garagehq/nightcrawler/
69•NickySlicks•5h ago•23 comments

Games at the press of a button: The Rip-O-Bot (1989)

https://blog.gingerbeardman.com/2026/08/02/games-at-the-press-of-a-button-the-rip-o-bot/
22•msephton•20h ago•2 comments

Utah produced more power from solar than any other source in May, a new first

https://www.sltrib.com/news/environment/2026/08/03/utah-sets-solar-power-record/
51•toomuchtodo•2h ago•17 comments

Walk on Decomposed Subdomains

https://clementjambon.github.io/wods/index.html#blogpost
27•E-Reverance•6d ago•2 comments

What DMARC Protects You From, and What It Does Not

https://senderledger.com/articles/what-dmarc-actually-protects-you-from
83•adulion•6h ago•22 comments

Kraid is a now a real compiler

https://www.collabora.com/news-and-blog/news-and-events/kraid-is-a-now-a-real-compiler.html
8•losgehts•4d ago•0 comments

Finding zombies in our systems: A real-world story of CPU bottlenecks

https://medium.com/pinterest-engineering/finding-zombies-in-our-systems-a-real-world-story-of-cpu...
13•fagnerbrack•1d ago•4 comments

Train Simulator Controller

https://z80.me/blog/tsc-2026-july/
73•austinallegro•3d ago•5 comments

Why does Mail app contact iCloud when sending a non-iCloud email?

https://lapcatsoftware.com/articles/2026/8/2.html
49•cdrnsf•1h ago•10 comments

Octane – React's programming model, compiled

https://octanejs.dev
97•nnx•8h ago•33 comments

Wind and solar overtake fossil fuels in Germany for the first time

https://www.intellinews.com/wind-and-solar-overtake-fossil-fuels-in-germany-for-the-first-time-ev...
15•just_some_user•3h ago•0 comments

Show HN: Isopolis – Isometric pixel map of SF

https://sf.isopolis.city/
305•nuwandavek•15h ago•69 comments

The true power of regular expressions (2012)

https://www.npopov.com/2012/06/15/The-true-power-of-regular-expressions.html
62•uneven9434•7h ago•49 comments

Show HN: We Fixed UniFi's Slow PPPoE Performance with PPPoE Half-Bridge

https://arcbox.dev/blog/unifi-pppoe-half-bridge-acceleration
57•uneven9434•7h ago•31 comments

Why we write our own C and C++ inference engines

https://localai.io/blog/why-we-write-our-own-engines/
106•eatonphil•3d ago•44 comments

Characterizing Warp Divergence from Pascal to Blackwell

https://arxiv.org/abs/2607.23402
19•matt_d•3d ago•1 comments