# Smallest & largest Numbers that sb can handle

• ### Question

• As the title says:

Wich are the smallest and the largest absolute values that sb can handle?

I mean something like 20019883777212456 or 0.0000000000000000071 in real numbers

not Stuff like \$FFFFFFF or 1+E2.3456 (how should I enter that?)

And why is there no Error-handling possible- that's kind of stupid

Tuesday, October 9, 2012 10:06 PM

• Smallest number (about division) is 0.0000000000000000000000000001 = 10^(-28).

Nonki Takahashi

• Marked as answer by Wednesday, October 10, 2012 1:28 PM
Wednesday, October 10, 2012 6:28 AM
• There are two largest numbers about Math.Power(x, 2).

To get correct answer, the largest number is 31622776.

To get answer (not overflow), the largest number is 281474976710655 = 2^48 - 1.

Nonki Takahashi

Wednesday, October 10, 2012 1:14 PM

### All replies

• I think, Small Basic uses the same max. and min. number like Windows. So I think it is without an end. (Or perhaps at 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 and 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

Greetings Timo

• Edited by Tuesday, October 9, 2012 10:10 PM
Tuesday, October 9, 2012 10:10 PM
• The largest number Small Basic can do is 79228162514264337593543950335. As for the smallest, I do not know. The reason why it is that number is that that number is (2 to 95 power) + (2 to 94 power) .......... all the way to (2 to 0 power) because computers use binary, which consists of 2 digits, 1 and 0.

I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."

Tuesday, October 9, 2012 10:22 PM
• 7922816251426433759354395039 seems to be the largest number.

If you go one higher than this it throws a exception

One thing that is impossible is impossible no matter if it is proven so first.

Tuesday, October 9, 2012 11:16 PM
• 79,228,162,514,264,337,593,543,950,335 is the largest (The Primitive data type of Small Basic is just a Decimal)

-79,228,162,514,264,337,593,543,950,335  is the smallest (Again, it is just the Decimal with its sign bit flipped)

Here's a great article on how computers store numbers: http://www.personal.psu.edu/jhm/f90/lectures/real_num.html. Basically, there is a base number, a sign bit (negative or positive) and a mantissa, or the exponent. That is how decimals are stored (truly as binary integers with exponents).

If you need error handling, you can do sanity checks. Also, you need to convert hex to decimal for your needs. I would recommend C# or VB --- your knowledge of programming and expectations seems to be past the point of what SB can handle =)
Tuesday, October 9, 2012 11:49 PM
• you misunderstood me. i mean the smallest absolute value, i.e. something like 0.0000000000000000000000001837

but the suqare root of that large number could be interesting, but my win-internal-calculator results me with something like 1+E^123454 - stuff that I cannot type in.

Problem is, the compiler complains (should have been called complainer instead) that Math.Power() cant handle a number given by my program. In my code there is some

X = Math.Power(aVal,2)

since there is no OnError-command I have to stop calculating before the squareroot of aVal reaches the point when the compiler breaks my program. Now this (minus one) would be the exact number I need to stay on the safe side. I'm playing around with some fractal graphics but can't finish because I dont know exactly where to stop calculating. In any other language you would type (in sb-syntax): OnError = ErrorHandler

• Edited by Wednesday, October 10, 2012 12:27 AM
Wednesday, October 10, 2012 12:10 AM
• Sorry I misunderstood you. Okay, here's my best shot at this:

A decimal in memory is 128 bits. Therefore, we have 1 sign bit; that leaves us with 128 bits. Next, we have our base number (an integer): that is 96 bits, so we have 31 bits left. Those are the mantissa, or exponent bits (in powers of 10), which I believe is also signed, so we have 30 bits to work with. So, our smallest positive value would be 1 * 10^-(29^2)), or 1 * 10^-536870912, which works out to INVALID INPUT in the Windows Calculator. So, although that value can be saved in memory, it cannot be calculated =)

I am not sure this is correct but am *pretty sure it* is. I'm just taking Algebra II, so I am no expert it this stuff.
Wednesday, October 10, 2012 1:07 AM
• Thanx for you help. as a reward here's another 50-liner wich draws pretty fractals. That's where I was sitting on half of the night

( it's 3:40 am in germany)

TLX408

Wednesday, October 10, 2012 1:37 AM
• This is good question.  I think there is different limit number for each operation or function.  I'd like to investigate the limit numbers.

Nonki Takahashi

Wednesday, October 10, 2012 3:44 AM
• Largest number (about addition) is 79228162514264337593543950335 = 2^96 - 1 as Math Man and gungan37 said.

Nonki Takahashi

Wednesday, October 10, 2012 6:00 AM
• Smallest number (about division) is 0.0000000000000000000000000001 = 10^(-28).

Nonki Takahashi

• Marked as answer by Wednesday, October 10, 2012 1:28 PM
Wednesday, October 10, 2012 6:28 AM
• There are two largest numbers about Math.Power(x, 2).

To get correct answer, the largest number is 31622776.

To get answer (not overflow), the largest number is 281474976710655 = 2^48 - 1.

Nonki Takahashi

Wednesday, October 10, 2012 1:14 PM
• Thank you Nonki :D

Could not be more precisely.

Now we've covered "largest and smallest (absolute) number" for sure. See what happens if I mark both of your post as answer?

If the internet will crash or be deleted then?

Wednesday, October 10, 2012 1:27 PM
• Actualy SmallBasic stores numbers as strings, which can be very long. Only the calculations and functions have a limitation on the size. To use this very long strings you have to write your own routines.

In april I published a little program which can do long division, with the answer for instance 3000 digits long (import TPV950)  See also:http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/de6f7ffc-2ca8-483a-b0fb-b1a4cef1d898

As you want to use MathPower(x,2) which is the square of x, you could to try to write a routine which can multiply two long numberstrings. (split de strings in substrings of e.g. 6 digits, which can be muliplied in the way a multiplication with pen and paper is done).

Hope this helps.

Jan [ WhTurner ] The Netherlands

Wednesday, October 10, 2012 2:09 PM
• Rene_Miner,

Both two articles are marked as answers.

Thanks.

Nonki Takahashi

Thursday, October 11, 2012 12:28 AM