←back to thread

631 points wojtczyk | 1 comments | | HN request time: 0s | source
Show context
rgovostes ◴[] No.41410786[source]
A friend doing homework for a university assignment, circa Leopard or Snow Leopard, noticed that Calculator produced negative values when raising a negative number to an even power.

The bug turned out to be in CFNumber, in Core Foundation. CFNumber does a lot of fiddly stuff at the bit level for performance, and one of their optimizations for exponentiation was incorrect. Somehow it was never found by tests or due to buggy behaviors it created in other apps, but by someone clicking buttons and thinking critically about the output.

replies(5): >>41410865 #>>41411004 #>>41411294 #>>41411316 #>>41412437 #
0x0 ◴[] No.41411004[source]
Interesting, I started playing with spotlight and typing in (-20)^21 returns " = 0", which is obviously not correct.

And typing in "(-22)^21" gives "-71100888972574851072", but wolfram alpha insists it should be "-15519448971100888972574851072".

Looks like there are still bugs here.

replies(4): >>41411908 #>>41412231 #>>41413462 #>>41414489 #
1. crazygringo ◴[] No.41412231[source]
Wow that's bizarre.

At first I thought it was just an overflow error but no it's nothing like that. The math is indeed very clearly broken, as I play around with it on Sonoma on my M1.

I'm genuinely shocked. I though this kind of floating-point math was rock-solid, tested thoroughly over the decades.