r/AskComputerScience • u/precious_waste • Apr 27 '25
How does my phone calculator get 10^10000 + 1 - 10^10000 right ?
I was quite sure it would say 0. What is the most likely answer? Symbolic calculation? Did it recognize some kind of pattern?
It's the Google calculator app btw.
195
Upvotes
70
u/PhilNEvo Apr 27 '25
this is worth a read: https://chadnauseam.com/coding/random/calculator-app and at the end of it there's a link to a paper that's worth a read :b
24
u/EagleCoder Apr 27 '25
Google's Android calculator app has "variable-precision" which means the results are extremely precise. There are no intermediate rounding errors.
Here's a short video about it: https://youtu.be/CKPRhaaAAtk?si=X7EcFhnn7htdebpx
18
u/qqqqqx Apr 27 '25
The Google calc app is really well engineered, you can read about it in the article someone else commented. And as they note you would be correct in some other calculator programs, but someone worked really hard on making the Google one handle a bunch of edge cases like this instead of using the naive method that would induce more rounding errors.
15
u/Intrepid-Secret-9384 Apr 27 '25
because google's calculator is a work of art
2
u/rasputin1 Apr 27 '25
why did you think it would say 0?
4
u/assembly_wizard Apr 28 '25
Check out this in depth explanation https://youtu.be/Ub86BRzqndA by Dr. Treffor Bazett. He made it just a month ago, so great timing.
1
u/ConsequenceOk5205 Apr 29 '25
One has just to store the number as a larger expression. Floating point numbers are stored as a small expression, a * ((b) ^ (exponent + bias)).
1
u/Gishky Apr 30 '25
well designed calculators calculate big numbers with exponents.
1
u/fixermark May 02 '25
https://www.youtube.com/watch?v=Ub86BRzqndA
tl;dr Google has huge nerds working for it. The kind of nerds who get pissed off enough about calculators sucking to bother to put far more work than necessary into it.
1
u/defectivetoaster1 Apr 27 '25
probably uses some sort of arbitrary precision library that can dynamically increase the amount of memory used up by an integer type in order to maintain accuracy
1
u/OnThePath Apr 28 '25
The numbers are large but not large to represent. 1010000 is roughly 30000 bits, roughly 4kB. So it doesn't fit into a registry but easily into the memory's computer.
0
u/[deleted] Apr 27 '25
[deleted] — view deleted comment