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•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.

You don't know HTML Lists

https://blog.frankmtaylor.com/2026/05/13/you-dont-know-html-lists/
167•speckx•1h ago•26 comments

SANA-WM, a 2.6B open-source world model for 1-minute 720p video

https://nvlabs.github.io/Sana/WM/
225•mjgil•6h ago•93 comments

Kioxia and Dell cram 10 PB into slim 2RU server

https://www.blocksandfiles.com/flash/2026/05/14/kioxia-and-dell-cram-10-pb-into-slim-2ru-server/5...
18•rbanffy•1h ago•8 comments

How an Australian Teen Team Is Making Radio Astronomy Affordable for Schools

https://mag.openrockets.com/p/how-an-australian-teen-team-is-making-radio-astronomy-affordable-fo...
77•openrockets•3h ago•24 comments

Windows 9x Subsystem for Linux

https://codeberg.org/hails/wsl9x
65•ibobev•3d ago•27 comments

Accelerando (2005)

https://www.antipope.org/charlie/blog-static/fiction/accelerando/accelerando.html
165•eamag•7h ago•88 comments

Moving away from Tailwind, and learning to structure my CSS

https://jvns.ca/blog/2026/05/15/moving-away-from-tailwind--and-learning-to-structure-my-css-/
273•mpweiher•9h ago•176 comments

Δ-Mem: Efficient Online Memory for Large Language Models

https://arxiv.org/abs/2605.12357
156•44za12•9h ago•38 comments

Show HN: Rocksky – Music scrobbling and discovery on the AT Protocol

https://tangled.org/rocksky.app/rocksky
15•tsiry•1h ago•4 comments

Accelerate

https://github.com/AccelerateHS/accelerate
57•tosh•5h ago•14 comments

Project Gutenberg – keeps getting better

https://www.gutenberg.org/
1091•JSeiko•1d ago•237 comments

DeepSeek-V4-Flash means LLM steering is interesting again

https://www.seangoedecke.com/steering-vectors/
127•Brajeshwar•3h ago•47 comments

Greek Alphabet Cards

https://labs.randomquark.com/alphabet_cards/
71•ricochet11•6h ago•27 comments

My Favorite Bugs: Invalid Surrogate Pairs

https://george.mand.is/2026/05/my-favorite-bugs-invalid-surrogate-pairs/
65•meysamazad•6h ago•35 comments

US Is Starting to See Heavy Job Losses in Roles Exposed to AI

https://www.bloomberg.com/news/articles/2026-05-15/us-is-starting-to-see-heavy-job-losses-in-role...
20•elsewhen•51m ago•3 comments

Futhark by Example

https://futhark-lang.org/examples.html
92•tosh•9h ago•23 comments

Fame! A Misunderstanding: A new translation of Albert Camus's complete notebooks

https://lareviewofbooks.org/article/albert-camus-complete-notebooks-ryan-bloom-existentialism-abs...
7•Caiero•2d ago•1 comments

Clusters become personal (like PCs did)

https://aranya.tech/blog/arrival-of-the-personal-cluster
18•druid•3d ago•7 comments

Kyber (YC W23) Is Hiring a Founding Marketer

https://www.ycombinator.com/companies/kyber/jobs/1rLQAro-founding-marketer-content-community
1•asontha•6h ago

Nearly 50 Years Later, WKRP in Cincinnati Becomes a Real Radio Station

https://www.openculture.com/2026/05/nearly-50-years-later-wkrp-in-cincinnati-becomes-a-real-radio...
74•bookofjoe•4d ago•46 comments

After 8 years, I rewrote my open-source PyTorch curvature library

https://github.com/noahgolmant/pytorch-hessian-eigenthings
40•noahgolmant•2d ago•1 comments

I believe there are entire companies right now under AI psychosis

https://twitter.com/mitchellh/status/2055380239711457578
1728•reasonableklout•22h ago•938 comments

Orthrus-Qwen3: up to 7.8×tokens/forward on Qwen3, identical output distribution

https://github.com/chiennv2000/orthrus
197•FranckDernoncou•20h ago•34 comments

The bird eye was pushed to an evolutionary extreme

https://www.quantamagazine.org/how-the-bird-eye-was-pushed-to-an-evolutionary-extreme-20260513/
192•sohkamyung•2d ago•63 comments

Ploopy Bean: a trackpoint for every computer

https://ploopy.co/shop/bean-pointing-stick/
153•jibcage•3d ago•70 comments

What Were Ancient Greco-Roman Curse Tablets?

https://www.history.com/articles/what-were-ancient-roman-curse-tablets
11•speckx•4d ago•7 comments

Gaining control of every projector and camera on campus

https://www.edna.land/blogs/posts/scanning/
93•ednaordinary•2d ago•30 comments

A 0-click exploit chain for the Pixel 10

https://projectzero.google/2026/05/pixel-10-exploit.html
421•happyhardcore•1d ago•223 comments

The sigmoids won't save you

https://www.astralcodexten.com/p/the-sigmoids-wont-save-you
276•Tomte•1d ago•257 comments

I 3D Printed Origami [video]

https://www.youtube.com/watch?v=FNVBK7-h9Fs
6•Teever•48m ago•1 comments