VBScript never displays more than 15 significant digits. Any digits beyond the first 15 are displayed
as zeros. However, the values are represented internally accurate to 53 bits. For example, all integers
up to 2^53 are represented exactly.
2^53 = 9,007,199,254,740,992
VBScript internally represents all even integers accurately up to 2^54, and all powers of two up to 2^63.
The following VBScript functions can handle numbers as follows:
|Function||Valid values for x||Valid values for y|
|CInt(x)||-32,768.5 <= x < 32,767.5|
|x AND y||-2,147,483,648.5 <= x < 2,147,483,647.5||-2,147,483,648.5 <= y < 2,147,483,647.5|
|x Or y||-2,147,483,648.5 <= x < 2,147,483,647.5||-2,147,483,648.5 <= y < 2,147,483,647.5|
|x XOR y||-2,147,483,648.5 <= x < 2,147,483,647.5||-2,147,483,648.5 <= y < 2,147,483,647.5|
|NOT x||-2,147,483,648.5 <= x < 2,147,483,647.5|
|x Mod y||-2,147,483,648.5 <= x < 2,147,483,647.5||-2,147,483,648.5 <= y < 2,147,483,647.5|
|CLng(x)||-2,147,483,648.5 <= x < 2,147,483,647.5|
|Hex(x)||-2,147,483,648.5 <= x < 2,147,483,647.5|
|CCur(x)|||x| <= 922,337,203,685,477.56|
The functions raise an overflow error if the input values are outside the ranges indicated.
Linear Congruential and Multiply With Carry generators require that large integers be multiplied and added. The calculations must be exact with no round off errors. Intermediate results can easily be too large for VBScript to represent exactly. 32-bit generators require the multiplication of two 32-bit integers, resulting in a 64-bit product. This can be handled by breaking the integers into 16-bit high and low parts. For example to calculate A * X, where both A and X can be up to 2^32 -1, we can break both A and X into 16-bit high and low parts:
A = (A_Hi * 2^16) + A_Lo
A_Hi = Int(A / 2^16)
A_Lo = A - (A_Hi * 2^16)
We do not use the expression (A Mod 2^16) to calculate A_Lo because A can exceed 2^31, which would cause the VBScript Mod function to overflow. In similar fashion, we calculate:
X = (X_Hi * 2^16) + X_Lo
X_Hi = Int(X / 2^16)
X_Lo = X - (X_Hi * 2^16)
Now the product A * X can be calculated exactly as follows:
((A_Hi * 2^16) + A_Lo) * ((X_Hi * 2^16) + X_Lo)
= A_Hi * X_Hi * 2^32 + ((A_Hi * X_Lo) + (A_Lo * X_Hi)) * 2^16 + (A_Lo * X_Lo)
This product modulo 2^32 can be easily calculated by noting that the 2^32 factor can be discarded completely. Also, the high 16-bit part of the second factor can be discarded. This product modulo 2^32 would be:
(((A_Hi * X_Lo) + (A_Lo * X_Hi)) Mod 2^16 + (A_Lo * X_Lo)) Mod 2^32
The Mod function in this expression can overflow, so we must instead divide and calculate the remainder. However, all of this math can be done exactly with no possibility of overflow.