App Inventor Computes With Big Integers

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:

https://www.exploringbinary.com/wp-content/uploads/AI.Bigint.blocks.png
App Inventor Blocks That Compute 2234112

They give this 376-digit answer:

https://www.exploringbinary.com/wp-content/uploads/AI.Bigint.emulator.png
App Output For Computation of 2234112

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:

https://www.exploringbinary.com/wp-content/uploads/AI.Bigint.infinity.block.png
The Value of 2234112 Pasted Into a Number Block Becomes Infinity

It’s too big for double-precision floating-point.

Dingbat

9 comments

  1. 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.

  2. @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:
    https://www.exploringbinary.com/wp-content/uploads/AI.Bigint.text.blocks.jpg

    Emulator output:

    https://www.exploringbinary.com/wp-content/uploads/AI.Bigint.text.emulator.jpg

    (That is the correct answer.)

    This is a good way to work with big integer arguments. Thanks for the suggestion.

  3. I thought you said it wouldn’t work in the other discussion. But it does! That makes my life MUCH easier. Thanks!

  4. Oh! An intiger, not a decimal. O.K., It’s back to being . . . well, not dificul, but teadious. O.K., thanks!

  5. 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!

  6. 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!

Comments are closed.

Copyright © 2008-2024 Exploring Binary

Privacy policy

Powered by WordPress

css.php