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

How OpenAI delivers low-latency voice AI at scale

https://openai.com/index/delivering-low-latency-voice-ai-at-scale/
166•Sean-Der•3h ago•69 comments

I am worried about Bun

https://wwj.dev/posts/i-am-worried-about-bun/
337•remote-dev•6h ago•241 comments

Talking to strangers at the gym

https://thienantran.com/talking-to-35-strangers-at-the-gym/
1023•thitran•11h ago•495 comments

Securing a DoD contractor: Finding a multi-tenant authorization vulnerability

https://www.strix.ai/blog/how-strix-found-zero-auth-vulnerability-dod-backed-startup
140•bearsyankees•5h ago•63 comments

GameStop makes $55.5B takeover offer for eBay

https://www.bbc.co.uk/news/articles/cn0p8yled1do
607•n1b0m•13h ago•570 comments

Pulitzer Prize Winners 2026

https://www.pulitzer.org/prize-winners-by-year/2026
25•brightbeige•1h ago•10 comments

Testing macOS on the Apple Network Server 2.0 ROMs

http://oldvcr.blogspot.com/2026/05/testing-macos-on-apple-network-server.html
13•zdw•1d ago•0 comments

Microsoft Edge stores all passwords in memory in clear text, even when unused

https://twitter.com/L1v1ng0ffTh3L4N/status/2051308329880719730
325•cft•4h ago•128 comments

Redis array: short story of a long development process

https://antirez.com/news/164
204•antirez•8h ago•76 comments

Does Employment Slow Cognitive Decline? Evidence from Labor Market Shocks

https://www.nber.org/papers/w35117
170•littlexsparkee•7h ago•155 comments

Formatting a 25M-line codebase overnight

https://stripe.dev/blog/formatting-an-entire-25-million-line-codebase-overnight-the-rubyfmt-story
82•r00k•2h ago•45 comments

Agent Skills

https://addyosmani.com/blog/agent-skills/
12•BOOSTERHIDROGEN•1h ago•2 comments

UK Fuel Price Intelligence – Market analytics from reporting stations

https://www.fuelinsight.co.uk
146•theazureguy•7h ago•72 comments

US healthcare marketplaces shared citizenship and race data with ad tech giants

https://techcrunch.com/2026/05/04/us-healthcare-marketplaces-shared-citizenship-and-race-data-wit...
373•ZeidJ•5h ago•127 comments

1966 Ford Mustang Converted into a Tesla with Working 'Full Self-Driving'

https://electrek.co/2026/05/02/tesla-1966-mustang-ev-conversion-full-self-driving/
93•Brajeshwar•7h ago•71 comments

Pomiferous: The most extensive apples (pommes) database

https://pomiferous.com/
91•Ariarule•8h ago•41 comments

How Monero’s proof of work works

https://blog.alcazarsec.com/tech/posts/how-moneros-proof-of-work-works
216•alcazar•8h ago•168 comments

Let's talk about LLMs

https://www.b-list.org/weblog/2026/apr/09/llms/
100•cdrnsf•5h ago•66 comments

Stop big tech from making users behave in ways they don't want to

https://economist.com/by-invitation/2026/04/29/stop-big-tech-from-making-users-behave-in-ways-the...
192•andsoitis•5h ago•128 comments

Sierra Raises $950M at $15B Valuation

https://sierra.ai/blog/better-customer-experiences-built-on-sierra
69•doppp•7h ago•94 comments

Heat pump sales rise across Europe

https://www.pv-magazine.com/2026/05/04/heat-pump-sales-rise-17-across-europe-in-q1-as-energy-pric...
181•doener•5h ago•97 comments

Transformers Are Inherently Succinct

https://arxiv.org/abs/2510.19315
15•bearseascape•2h ago•5 comments

Show HN: nfsdiag – A NFS diagnostic application

https://github.com/lsferreira42/nfsdiag
28•lsferreira42•2d ago•3 comments

The Visible Zorker: Zork 3

https://eblong.com/infocom/visi/zork3/
32•zarlez•5h ago•1 comments

A little comparison between R and Kap

https://blog.dhsdevelopments.com/a-little-comparison-between-r-and-kap
14•tosh•2d ago•1 comments

'Point of no return': New Orleans relocation must start now due to sea level

https://www.theguardian.com/us-news/2026/may/04/new-orleans-sea-levels-relocation-climate-crisis
23•dmm•1h ago•10 comments

“Kitten Space Agency”, a Spiritual Successor to “Kerbal Space Program” (2025)

https://www.space.com/entertainment/space-games/kitten-space-agency-is-the-spiritual-successor-to...
123•Tomte•5h ago•41 comments

Newton's law of gravity passes its biggest test

https://www.science.org/content/article/newton-s-law-gravity-passes-its-biggest-test-ever
124•pseudolus•10h ago•113 comments

Offenders sentenced up to 10 years for spying on TSMC

https://www.taipeitimes.com/News/front/archives/2026/04/28/2003856358
93•ironyman•4h ago•16 comments

Using “underdrawings” for accurate text and numbers

https://samcollins.blog/underdrawings/
357•samcollins•3d ago•126 comments