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.

macOS Container Machines

https://github.com/apple/container/blob/main/docs/container-machine.md
440•timsneath•4h ago•146 comments

Claude Fable 5

https://www.anthropic.com/news/claude-fable-5-mythos-5
1956•Philpax•12h ago•1522 comments

Upcoming breaking changes for npm v12

https://github.blog/changelog/2026-06-09-upcoming-breaking-changes-for-npm-v12/
260•plasma•7h ago•83 comments

Rich Sutton on AI creativity and discovery

https://twitter.com/RichardSSutton/status/2061216087744946656
52•yimby•2h ago•20 comments

German ruling declares Google liable for false answers in AI Overviews

https://the-decoder.com/landmark-german-ruling-declares-googles-ai-overviews-are-googles-own-word...
222•ahlCVA•3h ago•117 comments

The oldest surviving animated feature film at 100

https://www.bbc.com/culture/article/20260603-how-a-26-year-old-german-woman-made-the-worlds-oldes...
60•1659447091•3d ago•4 comments

RIP software hackathons. Long live the hardware hackathon

https://blog.oscars.dev/posts/rip-software-hackathons-long-live-the-hardware-hackathon/
103•ozcap•6h ago•36 comments

Ultrafast machine learning on FPGAs via Kolmogorov-Arnold Networks

https://aarushgupta.io/posts/kan-fpga/
187•ag2718•9h ago•29 comments

More Molly Guards

https://unsung.aresluna.org/more-molly-guards/
80•zdw•3d ago•4 comments

What it feels like to work with Mythos

https://www.oneusefulthing.org/p/what-it-feels-like-to-work-with-mythos
208•swolpers•11h ago•178 comments

If Claude Fable stops helping you, you'll never know

https://jonready.com/blog/posts/claude-fable5-is-allowed-to-sabotage-your-app-if-youre-a-competit...
645•mips_avatar•7h ago•315 comments

Lies we tell ourselves about email addresses

https://gitpush--force.com/commits/2026/06/lies-we-tell-ourselves-about-email/
72•theanonymousone•1d ago•53 comments

CEOs who think AI replaces their employees are just bad CEOs

https://www.techdirt.com/2026/06/09/ceos-who-think-ai-replaces-their-employees-are-just-bad-ceos/
529•speckx•10h ago•213 comments

OpenCV 5 Is Here: The Biggest Leap in Years for Computer Vision

https://opencv.org/opencv-5/
721•ternaus•3d ago•127 comments

Let's Encrypt bans certificate usage in any US sanctioned territory [pdf]

https://letsencrypt.org/documents/LE-SA-v1.7-June-04-2026-diff.pdf
362•piskov•1d ago•297 comments

A giant star may have destroyed itself in one of the rarest explosions

https://phys.org/news/2026-05-giant-star-destroyed-universe-rarest.html
173•wglb•1d ago•26 comments

Exif Smuggling (2025)

https://github.com/signalblur/exifsmugglingpoc
73•rolph•7h ago•23 comments

Test-case reducers are underappreciated debugging tools

https://tratt.net/laurie/blog/2026/test_case_reducers_are_underappreciated_debugging_tools.html
102•ltratt•17h ago•13 comments

Launch HN: Transload (YC P26) – Measuring freight items with CCTV

40•nils_spatial•12h ago•15 comments

Grit: Rewriting Git in Rust with agents

https://blog.gitbutler.com/true-grit
106•cbrewster•9h ago•144 comments

It's death

https://jesseduffield.com/ITS-DEATH/
142•inatreecrown2•5h ago•46 comments

Value Numbering

https://bernsteinbear.com/blog/value-numbering/
13•surprisetalk•1d ago•0 comments

Making Graphics Like it's 1993

https://staniks.github.io/articles/catlantean-3d-blog-1/
814•sklopec•18h ago•137 comments

The Evolution of 'More Like This'

https://manticoresearch.com/blog/the-evolution-of-more-like-this/
4•snikolaev•1h ago•0 comments

Bit Propagation over a Noisy Grid

https://jasonfantl.com/posts/Propagating-Bit-on-Grid/
3•jfantl•1d ago•0 comments

Experience using AI software to prove Euler sum results [pdf]

https://www.davidhbailey.com/dhbpapers/Chatbots.pdf
6•cpp_frog•1d ago•0 comments

Show HN: Resonate – Low-latency, high-resolution spectral analysis

https://alexandrefrancois.org/Resonate/
32•arjf•3d ago•11 comments

FCC wants to kill burner phones by forcing telecoms to get all customers' IDs

https://www.404media.co/fcc-wants-to-kill-burner-phones-by-forcing-telecoms-to-get-all-customers-...
498•berlianta•13h ago•312 comments

WWDC 2026: Apple is Folding

https://cupertinolens.com/2026/06/09/wwdc-2026-apple-is-folding/
193•brandonb•15h ago•229 comments

Surprise, Pay $1000

https://forestwalk.ai/blog/surprise-blacksmith-costs/
30•apike•6h ago•4 comments