Integers on HTML5

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,134
For those who's interested I made some comparisons regarding the range of integers that's possible on HTML5 and Desktop (Linux) platforms. It includes some useful code but basically it just shows that you sometimes can get as high as 53 Integers on HTML5.

You still can't assign anything higher than 32-bit inside the program so far as I understand, but you can initialize any amount it seems. Also pow, Print statement etc can use these bits.
Code:
Import mojo2

Function Main ()
    New Game
    Return 0
End 

Class Game Extends App
  
    Method OnCreate ()
  
        Local aa:Int = 2147483647
        Local bb:Int = 1
        Local cc:Int = aa + bb ' This one will be set to 4294967294
      
        ' DESKTOP OUTPUTS
        ' -2147483648
        ' -2147483648
        ' -1
        ' -2
        ' -2147483648
      
        ' HTML5 OUTPUTS
        ' 2147483648
        ' 2147483648
        ' 0
        ' 4294967294
        ' -2147483648
      
        Print Abs(2147483647)+1
        Print cc
        Print Overflow(aa,bb) ' Check for overflow
        Print aa+aa
      
        aa = 2147483647+1 ' This one will not be set to 2147483648 even in HTML5
        Print aa 
      

        Return 0
    End

End

Function Overflow:Int(a:Int,b:Int)
    Local result:Int = 0
    result = a + b
    If(a > 0 And b > 0 And result < 0) Then Return -1
    If(a < 0 And b < 0 And result > 0) Then Return -1
    Return 0
End

Function Trunc:Int(number:Float)
    If number > 0 Then Return Floor(number) Else Return Ceil(number)
End
 
Last edited:
Top Bottom