In AS3, what getTimer () will get when the value is greater than the maximum int value

Per Adobe getTimer ():

Used to calculate relative time. For an ActionScript 3.0 Flash runtime, this method returns the number of milliseconds that have passed since the Flash Runtime Virtual Machine started for ActionScript 3.0 (AVM2).

Since getTimer returns an int, which:

The int class allows you to work with a data type representing a 32-bit signed integer. The range of values โ€‹โ€‹represented by the int class is -2,147,483,648 (-2 ^ 31) to 2,147,483,647 (2 ^ 31-1)

What will getTimer () get after 2,147,483,647 milliseconds? I think it will be approximately 24.85 days in a row. Not a usual situation, as for the digital signage and kiosk context, which is quite possible.

Should getTimer () be avoided in these situations? Can a Date.UTC () object be more secure since it returns a Number type?

+4
source share
1 answer

I guess it will loop into itself, just like int.

var nt:int = int.MAX_VALUE + 10; //outputs -2147483639 var nt2:int = int.MIN_VALUE + 9; //outputs -2147483639 

As you can see, MAX + 10 same as MIN + 9 (you need to consider at least the min value). Therefore, when you click on this 24-day mark, it will look like -24 days and begin to return.

There is also the possibility that the function itself will not return the actual time, but something like this:

 return timer % int.MAX_VALUE; 

This will reset the time every time it presses MAX_VALUE to 0 using a simple module. I honestly wonโ€™t be surprised if this is what they do (since you donโ€™t want a negative runtime, obviously)

+1
source

Source: https://habr.com/ru/post/1446314/


All Articles