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.

Tesla Roadster

https://www.tesla.com/roadster
807•shekhar101•19h ago•1471 comments

Claude reveals ECDSA curve origins

https://www.anthropic.com/research/ecdsa-curve-origins
327•ahlCVA•1h ago•125 comments

Llama.cpp on a jailbroken PS5: run any GGUF model natively on the console

https://github.com/cobanov/PS5LM
77•Anon84•2h ago•22 comments

Flux 3 Image Klein: open weights, 5.6B parameters

https://bfl.ai/blog/flux-3-image-klein
13•gmays•50m ago•1 comments

The Fatal Flaw of 911

https://www.themarshallproject.org/2026/10/16/911-book-policing-mental-health
21•plunge•1h ago•18 comments

Waymo in Toronto

https://waymo.com/blog/2026/10/waymo-in-toronto/
162•ChrisArchitect•5h ago•274 comments

JPEG XL vs. AVIF for web use-cases

https://jakearchibald.com/2026/jpeg-xl-vs-avif/
137•farlight•4h ago•99 comments

Designing more efficient quantum circuits with Claude

https://www.anthropic.com/research/designing-efficient-quantum-circuits
51•pretext•2h ago•7 comments

90% of US working hours are spent on tasks not covered well by AI benchmarks

https://www.mercor.com/research/labor-index/benchmark-map/
277•speckx•3h ago•244 comments

C++26: The New Debugging Header

https://www.sandordargo.com/blog/2026/09/30/cpp26-debugging
20•jandeboevrie•1h ago•1 comments

Apple ML Research: Muse Spark Open with MLX on Mac Studio

https://machinelearning.apple.com/research/mlx-distributed-inference
219•antipaul•6h ago•101 comments

How the Claude Code team does code review

https://claude.dev/blog/solving-code-review-at-anthropic/
70•pretext•1h ago•64 comments

Piramidal (YC W24) Is Hiring

https://job-boards.greenhouse.io/piramidalinc/jobs/4443102009
1•dsacellarius•3h ago

eBay Restricts Listings of Radio Equipment, but Exempts Ham-Band-Only Gear

https://www.arrl.org/arrlletterissue?issue=2026-10-15#eBay-Restricts-Listings-of-Radio-Equipment_...
96•7402•2h ago•73 comments

Big Fish: Exploiting a 37-Year-Old Kernel Bug in OpenBSD

https://calif.io/research/big-fish
141•rs_rs_rs_rs_rs•5h ago•41 comments

You could have invented transformers from memory

https://alexwang.ai/posts/associative-memory/
15•speckx•1h ago•0 comments

Show HN: Gemini 4 Argon plays StarCraft

https://starskirmish.com/bench/v0-2/
154•__cayenne__•6h ago•72 comments

/dev/null: social network for developers

https://dev-null.sh
65•mnapoli•3h ago•86 comments

Show HN: Wonderhop – A daily game: guess what most people say, or what none do

https://wonderhop.io/en/
35•mtlduo•2d ago•43 comments

What on Earth Is Dekton?

https://www.worksinprogress.news/p/porcelain
104•wawayanda•6h ago•37 comments

Stolen Renoir paintings found hidden, and damaged, behind cinder block wall

https://www.cbsnews.com/news/stolen-renoir-paintings-found-behind-wall-france/
85•ohjeez•3d ago•56 comments

GifCities

https://gifcities.org/
23•augury•3h ago•0 comments

Anthropic assigned highest junk credit rating in June

https://www.ft.com/content/5a310aee-f555-4266-874c-b1b4db20186d
113•JumpCrisscross•2h ago•32 comments

Monte-Carlo Simulations

https://eli.thegreenplace.net/2026/monte-carlo-simulations/
16•ibobev•3d ago•0 comments

I Love Software Rendering

https://www.jamesfmackenzie.com/2026/10/13/i-love-software-rendering/
258•speckx•7h ago•178 comments

Show HN: Stoke Money – Personal finance app built around a cash flow forecast

https://stoke.money
12•_wesley•1h ago•6 comments

Woman who rescued injured crow keeps getting 'thank-you gifts' from birds [video]

https://www.youtube.com/watch?v=sjNpfz4UzqU
802•johnnyApplePRNG•3d ago•235 comments

Symmetries in Boolean Scan

https://ap29600.github.io/boolean_scans.html
5•g0xA52A2A•1d ago•0 comments

RFC8950: Announce IPv4 with an IPv6 next-hop

https://anuragbhatia.com/post/2026/06/rfc8950-announce-ipv4-with-ipv6-next-hop/
80•porridgeraisin•6h ago•45 comments

Making 1,750 programmable PCB badges for Canada's biggest hackathon

https://va3ndf.com/blog/hacker-badges/
40•va3ndf•2d ago•10 comments