Small Basic - Limits of Literals
I found three types of limits about numeric literals in Small Basic. Following explanation is about positive numbers, but negative numbers have the similar limits.
Rounded
Numeric literal larger than 1015 will be rounded at substitution. In following code, the second one is rounded. But the third one (text) is not rounded.
n `` = ``1000000000000000
TextWindow``.``WriteLine``(``n``)
n `` = ``1000000000000001
TextWindow``.``WriteLine``(``n``)
n `` = ``"1000000000000001"
TextWindow``.``WriteLine``(``n``)
1000000000000000
1000000000000000
1000000000000001
Substitution Error
In following code, the first substitution succeeds. But the second one fails with a run time error "Value was either too large or too small for a Decimal."
n `` = ``79228162514264333199999999999
TextWindow``.``WriteLine``(``n``)
n `` = ``79228162514264333200000000000
TextWindow``.``WriteLine``(``n``)
79228162514264300000000000000
Unhandled Exception: System.OverflowException: Value was either too large or too
small for a Decimal.
at System.Decimal..ctor(Double value)
at Microsoft.SmallBasic.Library.Primitive.op_Implicit(Double value)
at _SmallBasicProgram._Main()
Treated as Text
In following code, the first text is not treated as a number. The second one is treated as a number, so causes run time error when increased.
n `` = ``"79228162514264337593543950336"
TextWindow``.``WriteLine``(``n``)
TextWindow``.``WriteLine``(`` n `` - ``1``)
TextWindow``.``WriteLine``(`` n `` + ``1``)
n `` = ``"79228162514264337593543950335"
TextWindow``.``WriteLine``(``n``)
TextWindow``.``WriteLine``(`` n `` - ``1``)
TextWindow``.``WriteLine``(`` n `` + ``1``)
79228162514264337593543950336
-1
792281625142643375935439503361
79228162514264337593543950335
79228162514264337593543950334
Unhandled Exception: System.OverflowException: Value was either too large or too
small for a Decimal.
at System.Decimal.FCallAddSub(Decimal& d1, Decimal& d2, Byte bSign)
at Microsoft.SmallBasic.Library.Primitive.Add(Primitive addend)
at _SmallBasicProgram._Main()
See Also
Comments
Anonymous
June 15, 2015
Great article. Thanks.Anonymous
June 21, 2015
i've download small basic and I've started to write simple program but after saved it i have not any out put exe i don't have any icon to run after saving. i know after saving i have to have 3 icon.Anonymous
June 28, 2015
In Exploer [View] menu, select [Details]. So you can see the [Type] of files.
- Small Basic file : source file
- Application : executable file <- You can run this file without the Small Basic environment!
- Program Debug Database : don't mind
- Anonymous
June 28, 2015
I found another limit of literal. The nearest numbers to zero are: 0.000000000000000000000000000050000000000000007 = 5E-29 + 7E-45 and -0.000000000000000000000000000050000000000000007 = -5E-29 - 7E-45 At substitution, these numbers will be rounded to: 0.0000000000000000000000000001 = 1E-28 and -0.0000000000000000000000000001 = -1E-28