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

Having Kids (2019)

https://paulgraham.com/kids.html
41•Anon84•40m ago•23 comments

ArXiv declares independence from Cornell

https://www.science.org/content/article/arxiv-pioneering-preprint-server-declares-independence-co...
542•bookstore-romeo•11h ago•184 comments

Entso-E final report on Iberian 2025 blackout

https://www.entsoe.eu/publications/blackout/28-april-2025-iberian-blackout/
99•Rygian•4h ago•23 comments

The Los Angeles Aqueduct Is Wild

https://practical.engineering/blog/2026/3/17/the-los-angeles-aqueduct-is-wild
59•michaefe•2d ago•14 comments

Flash-KMeans: Fast and Memory-Efficient Exact K-Means

https://arxiv.org/abs/2603.09229
109•matt_d•3d ago•8 comments

HP realizes that mandatory 15-minute support call wait times isn't good support

https://arstechnica.com/gadgets/2025/02/misguided-hp-customer-support-approach-included-forced-15...
117•felineflock•2h ago•60 comments

Video Encoding and Decoding with Vulkan Compute Shaders in FFmpeg

https://www.khronos.org/blog/video-encoding-and-decoding-with-vulkan-compute-shaders-in-ffmpeg
67•y1n0•3d ago•21 comments

Regex Blaster

https://mdp.github.io/regex-blaster/
53•mdp•2d ago•17 comments

The Soul of a Pedicab Driver

https://www.sheldonbrown.com/pedicab.html
88•haritha-j•5h ago•25 comments

Just Put It on a Map

https://progressandpoverty.substack.com/p/just-put-it-on-a-map
70•surprisetalk•4d ago•29 comments

Google details new 24-hour process to sideload unverified Android apps

https://arstechnica.com/gadgets/2026/03/google-details-new-24-hour-process-to-sideload-unverified...
1043•0xedb•22h ago•1095 comments

The Social Smolnet

https://ploum.net/2026-03-20-social-smolnet.html
11•aebtebeten•2h ago•0 comments

Show HN: Sonar – A tiny CLI to see and kill whatever's running on localhost

https://github.com/RasKrebs/sonar
67•raskrebs•5h ago•32 comments

Drawvg Filter for FFmpeg

https://ayosec.github.io/ffmpeg-drawvg/
135•nolta•3d ago•23 comments

Chuck Norris has died

https://variety.com/2026/film/news/chuck-norris-dead-walker-texas-ranger-dies-1236694953/
300•mp3il•1h ago•150 comments

I'm OK being left behind, thanks

https://shkspr.mobi/blog/2026/03/im-ok-being-left-behind-thanks/
530•coinfused•1h ago•382 comments

Full Disclosure: A Third (and Fourth) Azure Sign-In Log Bypass Found

https://trustedsec.com/blog/full-disclosure-a-third-and-fourth-azure-sign-in-log-bypass-found
237•nyxgeek•14h ago•71 comments

Exploring 8 Shaft Weaving

https://slab.org/2026/03/11/exploring-8-shaft-weaving/
9•surprisetalk•2h ago•0 comments

Germany Mandates ODF for Public Administration

https://linuxiac.com/germany-mandates-odf-for-public-administration/
38•mvdwoord•1h ago•1 comments

Drugwars for the TI-82/83/83 Calculators (2011)

https://gist.github.com/mattmanning/1002653/b7a1e88479a10eaae3bd5298b8b2c86e16fb4404
221•robotnikman•15h ago•66 comments

VisiCalc Reconstructed

https://zserge.com/posts/visicalc/
6•ingve•3d ago•0 comments

Too Much Color

https://www.keithcirkel.co.uk/too-much-color/
73•maguay•2d ago•35 comments

Super Micro Shares Plunge 25% After Co-Founder Charged in $2.5B Smuggling Plot

https://www.forbes.com/sites/tylerroush/2026/03/20/super-micro-shares-plunge-25-after-co-founder-...
23•pera•48m ago•1 comments

Schizophrenia study finds new biomarker, drug candidate in mice

https://news.northwestern.edu/stories/2026/03/schizophrenia-study-finds-new-biomarker-drug-candid...
86•gmays•2h ago•30 comments

Building a Reader for the Smallest Hard Drive

https://www.willwhang.dev/Reading-MK4001MTD/
73•voctor•4d ago•24 comments

Return of the Obra Dinn: spherical mapped dithering for a 1bpp first-person game

https://forums.tigsource.com/index.php?topic=40832.msg1363742#msg1363742
439•PaulHoule•3d ago•56 comments

Java is fast, code might not be

https://jvogel.me/posts/2026/java-is-fast-your-code-might-not-be/
53•siegers•1h ago•59 comments

Push events into a running session with channels

https://code.claude.com/docs/en/channels
373•jasonjmcghee•15h ago•218 comments

Show HN: Three new Kitten TTS models – smallest less than 25MB

https://github.com/KittenML/KittenTTS
491•rohan_joshi•23h ago•166 comments

How the Turner twins are mythbusting modern technical apparel

https://www.carryology.com/insights/how-the-turner-twins-are-mythbusting-modern-gear/
300•greedo•2d ago•156 comments