by rgovostes · 2y ago · 0 comments
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.
Source: have made this mistake. Have been flagged.
Brackets, exponents, division, multiplication, addition, subtraction.
Bedmas, Christmas in bed!
And typing in "(-22)^21" gives "-71100888972574851072", but wolfram alpha insists it should be "-15519448971100888972574851072".
Looks like there are still bugs here.
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.
"(-20)^21" = -2.097152e27 "(-22)^21" = -1.551944897e28
(-20)^21 = -2.097152x10^27 and (-22)^21 = -1.5519448971*10^28
That always amused me.
also mentioned by Raymond Chen, https://devblogs.microsoft.com/oldnewthing/20040525-00/?p=39... :
"Today, Calc’s internal computations are done with infinite precision for basic operations (addition, subtraction, multiplication, division) and 32 digits of precision for advanced operations (square root, transcendental operators)."
And they fixed the square-root-of-a-perfect-square bug a few years ago, https://www.reddit.com/r/Windows10/comments/89s53g/microsoft...
Or another even simpler case: If division is infinite precision, and I enter (2/3) * X, does the calculator internally work with fractions? Otherwise it would have infinite digits to compute.