I recently wrote that App Inventor represents its numbers in floating-point. I’ve since discovered something curious about integers. When typed into math blocks, they are represented in floating-point; but when generated through calculations, they are represented as arbitrary-precision integers — big integers.
These blocks compute 2234112:
They give this 376-digit answer:
The answer is correct, as verified by PARI/GP:
1251165911380633363439551245873923892575406170188234549606572475115624640753800326057488115314970472673616740287115362948597337642238001620534807048434385387640177043977953923362977754905583813005405988071298529087198946391690484805791659317249521886229287098023259873676442017917402620362904960297832651819179978331881529482366801904894211236715599906760678041822804003782656
The only way App Inventor could have done this correctly is by using big integers.
On the other hand, when I paste that number into a number block, App Inventor sets it to infinity:
It’s too big for double-precision floating-point.
What if you posted it into a text block?
@Frank,
I don’t understand your question.
Well, there’s number blocks and text blocks. What I’m going to try is to see if text blocks can be used in math.
@Frank,
If you wrap an integer argument of a math block in a text block it is treated as a big integer; check it out:
Blocks:
Emulator output:
(That is the correct answer.)
This is a good way to work with big integer arguments. Thanks for the suggestion.
I thought you said it wouldn’t work in the other discussion. But it does! That makes my life MUCH easier. Thanks!
Oh! An intiger, not a decimal. O.K., It’s back to being . . . well, not dificul, but teadious. O.K., thanks!
Hi Rick,
I’m building an App Inventor class for grade 8s, and I’m putting together some example apps for them to build (following help videos I’ll make). One app I thought they’d like is a calculator. But I’m discovering issues in displaying large numbers, and for catching errors (like squaring a value until it is too big and the app freezes).
You seem to understand these number issue (unlike me); could you point me in the right direction for formatting large numbers into scientific notation for a fixed display size (say 16 characters)? Sometimes the numbers are displayed in SI, but sometimes its a huge integer that wraps.
Thank you!
Never mind, Rick! I used your 2234^112 number to test against, and I avoid the app crashing. Too bad there isn’t a built-in test or constant. Thank goodness you have the info!
@Chris,
I’m glad you found what you needed. Good luck with the app.