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:
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?
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.
If you wrap an integer argument of a math block in a text block it is treated as a big integer; check it out:
(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!
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.
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!
I’m glad you found what you needed. Good luck with the app.
Comments are closed.