sjbarag / brs

An interpreter for the BrightScript language that runs on non-Roku platforms.
MIT License
114 stars 43 forks source link

Support "%" type declaration character #627

Closed alimnios72 closed 3 years ago

alimnios72 commented 3 years ago

In Brightscript numbers with 10 or more digits are treated with the following logic:

  1. If a constant contains 10 or more digits, or if D is used in the exponent, that number is double precision. Adding a # declaration character also forces a constant to be double precision.
  2. If the number is not double-precision, and if it contains a decimal point, then the number is float. If the number is expressed in exponential notation with E preceding the exponent, the number is float.
  3. If neither of the above is true of the constant, then it is an integer.

but you can also force long numbers to be casted as integers (as long as they fit in 32 bits) by using the % character.

Brightscript Debugger> myvar = 1234567890%
Brightscript Debugger> print getInterface(myvar, "ifDouble")
invalid
Brightscript Debugger> print getinterface(myvar, "ifInt")
<Interface: ifInt>

However % isn't supported in brs

brs> myvar = 1234567890%
REPL(1,18-19): Unexpected character '%'
brs> myvar = 1234567890
brs> print getInterface(myvar, "ifDouble")
<Interface: ifDouble>
brs> print getinterface(myvar, "ifInt")
invalid