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.

Can we have the day off?

https://mlsu.io/posts/day-off/
368•mlsu•1h ago•226 comments

YouTube to automatically label AI-generated videos

https://blog.youtube/news-and-events/improving-ai-labels-viewers-creators/
554•nopg•6h ago•329 comments

I think Anthropic and OpenAI have found product-market fit

https://simonwillison.net/2026/May/27/product-market-fit/
661•simonw•9h ago•814 comments

What Apple and Google are doing to push notifications

https://www.jacquescorbytuech.com/writing/what-apple-and-google-are-doing-your-push-notifications
182•iamacyborg•6h ago•187 comments

SimCity 3k in 4k (2025)

https://www.thran.uk/writ/hdid/2025/12/simcity-3k-in-4k.html
290•speckx•8h ago•108 comments

A New Typst Template for Pandoc

https://imaginarytext.ca/posts/2025/typst-templates-for-pandoc/
40•ankitg12•1d ago•4 comments

Rust (and Slint) on a Jailbroken Kindle

https://sverre.me/blog/rust-on-kindle/
107•homarp•6h ago•11 comments

The Ask

https://randsinrepose.com/archives/the-ask/
12•digitallogic•2d ago•4 comments

I'm Getting into Mesh Networks (Meshtastic, MeshCore, and Reticulum)

https://www.jonaharagon.com/posts/im-getting-into-mesh-networks-meshtastic-meshcore-and-reticulum/
77•Panda_•6h ago•21 comments

FBI Arrests CIA Official with $40M in Gold Bars in His Home

https://www.nytimes.com/2026/05/27/us/politics/fbi-arrest-cia-official-gold-bars.html
95•cwwc•2h ago•48 comments

DuckDuckGo search saw 28% more visits after Google said people love AI mode

https://www.pcgamer.com/hardware/duckduckgos-ai-free-search-saw-nearly-28-percent-more-visits-in-...
679•HelloUsername•9h ago•342 comments

Interleaved Deltas

https://mmapped.blog/posts/51-interleaved-deltas
34•surprisetalk•1d ago•0 comments

Pelica (YC P25) Is Hiring

https://www.ycombinator.com/companies/pelica/jobs/MDeC49o-machine-learning-engineer
1•lalitkundu•3h ago

Go: Support for Generic Methods

https://github.com/golang/go/issues/77273
195•f311a•17h ago•146 comments

Incident with Pull Requests, Issues, Git Operations and API Requests

https://www.githubstatus.com/incidents/xy1tt3hs572m
263•maxnoe•14h ago•193 comments

Canada to order military plane fleet from Sweden in shift from US suppliers

https://www.theguardian.com/world/2026/may/27/canada-sweden-saab-globaleye-aircraft
419•tosh•9h ago•307 comments

Gemini, Gophers, and Fingers. Oh My Alternative Internets Beyond HTTPS

https://brennan.day/gemini-gophers-and-fingers-oh-my-alternative-internets-beyond-https/
94•ChrisArchitect•8h ago•47 comments

Last.fm is now independent

https://support.last.fm/t/last-fm-is-now-independent/118591
632•twistslider•10h ago•179 comments

Mini Micro Fantasy Computer

https://miniscript.org/MiniMicro/index.html#about
233•nicoloren•16h ago•80 comments

On Labubu and the Hyperreal

https://2earth.github.io/website/20260525.html
71•2earth•6h ago•80 comments

Stress disrupts hippocampal integration of overlapping events, memory inference

https://www.science.org/doi/10.1126/sciadv.aea5496?user_id=66c4bf745d78644b3aa57b08
78•gmays•9h ago•13 comments

Show HN: Open-Source AI Racing Harness

https://www.elodin.systems/post/elodin-ai-grand-prix-race-sim-harness
16•danAtElodin•5h ago•4 comments

Justice Dept. Is Said to Open Criminal Inquiry of E. Jean Carroll

https://www.nytimes.com/2026/05/27/us/politics/criminal-inquiry-e-jean-carroll-trump-accusations....
14•JumpCrisscross•55m ago•1 comments

Tech CEOs are apparently suffering from AI psychosis

https://techcrunch.com/2026/05/27/tech-ceos-are-apparently-suffering-from-ai-psychosis/
580•IAmGraydon•10h ago•294 comments

What Is a Direct Attach Copper (DAC) Cable? (2021)

https://www.servethehome.com/what-is-a-direct-attach-copper-dac-cable/
98•teleforce•2d ago•79 comments

Private equity bought America's essential services

https://rubbishtalk.com/economy/how-private-equity-bought-americas-essential-services/
442•NoRagrets•14h ago•496 comments

Matrix Multiplications on GPUs Run Faster When Given “Predictable” Data (2024)

https://www.thonking.ai/p/strangely-matrix-multiplications
156•tosh•4d ago•45 comments

All of human cooking compressed into 2 megabytes

https://arxiv.org/abs/2605.22391
365•josefchen•18h ago•151 comments

Google employee charged with $1M Polymarket insider trading bet on search term

https://www.cnbc.com/2026/05/27/google-employee-polymarket-insider-trading.html
15•pseudolus•1h ago•2 comments

Freediving, Embodiment and Humanity

https://tracesofhumanity.org/freediving-embodiment-and-humanity/
28•transpute•3d ago•13 comments