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

Git commands I run before reading any code

https://piechowski.io/post/git-commands-before-reading-code/
794•grepsedawk•5h ago•179 comments

MegaTrain: Full Precision Training of 100B+ Parameter LLMs on a Single GPU

https://arxiv.org/abs/2604.05091
99•chrsw•2h ago•17 comments

Veracrypt project update

https://sourceforge.net/p/veracrypt/discussion/general/thread/9620d7a4b3/
656•super256•7h ago•211 comments

They're Made Out of Meat (1991)

http://www.terrybisson.com/theyre-made-out-of-meat-2/
80•surprisetalk•3h ago•22 comments

Škoda DuoBell: A bicycle bell that penetrates noise-cancelling headphones

https://www.skoda-storyboard.com/en/skoda-world/skoda-duobell-a-bicycle-bell-that-outsmarts-even-...
239•ra•6h ago•318 comments

US cities are axing Flock Safety surveillance technology

https://www.cnet.com/home/security/when-flock-comes-to-town-why-cities-are-axing-the-controversia...
186•giuliomagnifico•2h ago•93 comments

Show HN: We fingerprinted 178 AI models' writing styles and similarity clusters

https://rival.tips/research/model-similarity
15•nuancedev•45m ago•3 comments

Audio Reactive LED Strips Are Diabolically Hard

https://scottlawsonbc.com/post/audio-led
89•surprisetalk•1d ago•24 comments

Project Glasswing: Securing critical software for the AI era

https://www.anthropic.com/glasswing
1404•Ryan5453•20h ago•726 comments

Revision Demoparty 2026: Razor1911 [video]

https://www.youtube.com/watch?v=Lw4W9V57SKs&t=5716s
260•tetrisgm•9h ago•89 comments

Lunar Flyby

https://www.nasa.gov/gallery/lunar-flyby/
855•kipi•23h ago•208 comments

The Harvard Library Passport

https://fi-le.net/stamps/
24•fi-le•2d ago•4 comments

Show HN: We built a camera only robot vacuum for less than 300$ (Well almost)

https://indraneelpatil.github.io/blog/2026/robot-vacuum/
68•indraneelpatil•2d ago•19 comments

Your File System Is Already A Graph Database

https://rumproarious.com/2026/04/04/your-file-system-is-already-a-graph-database/
82•alxndr•2d ago•31 comments

Protect your shed

https://dylanbutler.dev/blog/protect-your-shed/
230•baely•11h ago•62 comments

System Card: Claude Mythos Preview [pdf]

https://www-cdn.anthropic.com/53566bf5440a10affd749724787c8913a2ae0841.pdf
773•be7a•20h ago•569 comments

Mario and Earendil

https://lucumr.pocoo.org/2026/4/8/mario-and-earendil/
36•doppp•5h ago•14 comments

GLM-5.1: Towards Long-Horizon Tasks

https://z.ai/blog/glm-5.1
577•zixuanlimit•22h ago•233 comments

LLM plays an 8-bit Commander X16 game using structured "smart senses"

https://pvp-ai.russell-harper.com
7•russellharper•1h ago•0 comments

Native Americans had dice 12k years ago

https://www.nbcnews.com/science/science-news/native-americans-dice-games-probability-study-rcna26...
106•delichon•4d ago•46 comments

Cambodia unveils statue to honour famous landmine-sniffing rat

https://www.bbc.com/news/articles/c0rx7xzd10xo
444•speckx•21h ago•105 comments

How to get better at guitar

https://www.jakeworth.com/posts/how-to-get-better-at-guitar/
409•jwworth•2d ago•208 comments

Slightly safer vibecoding by adopting old hacker habits

http://addxorrol.blogspot.com/2026/03/slightly-safer-vibecoding-by-adopting.html
142•transpute•5d ago•81 comments

A truck driver spent 20 years making a scale model of every building in NYC

https://www.smithsonianmag.com/smart-news/a-truck-drive-spent-20-years-making-this-astonishing-sc...
375•1659447091•2d ago•64 comments

S3 Files

https://www.allthingsdistributed.com/2026/04/s3-files-and-the-changing-face-of-s3.html
342•werner•19h ago•102 comments

Show HN: An interactive map of Tolkien's Middle-earth

https://middle-earth-interactive-map.web.app/
255•frasermarlow•18h ago•51 comments

Show HN: I pipe free sports streams into Jellyfin – no ads, just HLS

https://github.com/pcruz1905/hls-restream-proxy
23•pruz•2h ago•2 comments

Binary obfuscation used in AAA Games

https://blog.farzon.org/2026/04/binary-obfuscation-that-doesnt-kill-lto.html
122•noztol•2d ago•67 comments

Cloudflare targets 2029 for full post-quantum security

https://blog.cloudflare.com/post-quantum-roadmap/
370•ilreb•1d ago•112 comments

Show HN: Gemma 4 Multimodal Fine-Tuner for Apple Silicon

https://github.com/mattmireles/gemma-tuner-multimodal
208•MediaSquirrel•19h ago•26 comments