This section provides some detail rules and a tutorial example on how arithmetic exponentiation operation works in VBScript.
Here are some detail rules about the arithmetic operation - exponentiation:
Arithmetic exponentiation operation uses the exponentiation operator: "^"
Arithmetic exponentiation operation requires that at least one of the operands is a numeric subtype:
Byte, Integer, Long, Single or Double.
If an operand is not a numeric subtype, it will be converted into a numeric subtype.
The Boolean subtype is considered as a numeric subtype in a exponentiation operation.
"True" represents a numeric value of -1. "False" represents a numeric value of 0.
The Empty subtype is considered as a numeric subtype in a exponentiation operation.
"Empty" represents a numeric value of 0.
When a String value is used in a exponentiation operation, it will be parsed into a Long value.
If the parsing process fails, the exponentiation operation will raise the "Type mismatch" runtime error.
If the first operand is a negative value, the second operand must be an integer.
Otherwise, the operation will fail.
The returning value is the result of the first operand raised to the power of the second operand.
The subtype of the returning value is always Double.
Here is a tutorial example showing you how arithmetic modulus operation rules work:
The output confirms some of arithmetic exponentiation operation rules:
Return values from all tests are Double values .
"2^3=8 : Double" shows that the result is a Double value, even if the whole operation could be done in integer mode.
"2^0.5=1.4142135623731 : Double" shows an interesting problem.
If VBScript is doing the calculation Double mode, The result should have more digits, like 1.4142135623730950488016887242097.
The statement on (-2^0.5) is commented out, because the second operand must an integer
if first operand is negative.
The statement on (False^True) is commented out, because it will be converted to (0^-1),
which will result an operation of dividing by 0.