Integer Operations
The Expression Language provides a number of operators that act on integral values:
-
The comparison operators, which result in a value of type
Boolean
:-
Numerical Comparison Operators (<, <=, >, and >=).
-
Numeric Equality Operators (== and !=).
-
-
The numerical operators, which result in a value of type
int
orlong
orBigInteger
:-
Unary Plus Operator (+) and Unary Minus Operator (-).
-
Multiplicative Operators (*, /, and %).
-
Additive Operators (+ and -) for Numeric Types.
-
Prefix Increment Operator (++) and Postfix Increment Operator (++).
-
Prefix Decrement Operator (--) and Postfix Decrement Operator (--).
-
Shift Operators (<<, >>, and >>>).
-
Bitwise Complement Operator (~).
-
Integer Bitwise Operators (&, ^, and |).
-
-
Conditional Operator (? :)
-
Field Access Using a Primary.
-
Method Invocation Expressions.
-
The cast operator, which can convert from an integral value or a string value to a value of any specified numeric type.
-
The String Concatenation Operator +, which, when given a String operand and an integral operand, will convert the integral operand to a String representing its value in decimal form, and then produces a newly created String that is the concatenation of the two strings.
-
The prompt concatenation operator +, which, when given a Prompt operand and an integral operand, will convert the integral operand to a Prompt representing its value in spoken form, and then produce a newly created Prompt that is the concatenation of the two prompts.
Except for the prompt concatenation operator, these operations are the same as those in Java. For descriptions of the operations you can have on expressions, see: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#44393.
Other useful constructors, methods, and constants are predefined in the classes Byte, Short, Integer, Long, BigInteger, and Character.
If an integer operator other than a shift operator has at least one operand of type BigInteger, then the operation is carried out using BigInteger precision and the result of the numerical operator is of type BigInteger.
If at least one operand is of type long, then the operation is carried out using 64-bit precision, and the result of the numerical operator is of type long. If the other operand is not long or BigInteger, it is first widened to type long or BigInteger by numeric promotion. Otherwise, the operation is carried out using 32-bit precision, and the result of the numerical operator is of type int. If either operand is not an int, it is first widened to type int by numeric promotion.
The built-in integer operators do not indicate overflow or underflow in any way. The only numeric operators that can throw an exception are the integer divide operator / and the integer remainder operator %, which throw an ArithmeticException in the complex expression block or an ExpressionArithmeticException in the script if the right-hand operand is zero.
The example:
{
Prompt p = null;
int i = 1000000;
p = N[i * i];
long l = i;
p += N[l * l];
p += [20296 / (l - i)];
return p;
}
would create a concatenated prompt that would playback the spoken representation of -727379968 and 1000000000000 and then encounters an ArithmeticException in the division by l - i, because l - i is zero. The first multiplication is performed in 32-bit precision, whereas the second multiplication is a long multiplication. The value -727379968 is the decimal value of the low 32 bits of the mathematical result, 1000000000000, which is a value too large for type int.
Any value of any integral type may be cast to or from any numeric type and from the String type in which case an ExpressionTargetExeption with a nested NumberFormatException is thrown back if the string value cannot be properly parsed into an integral type. There are no casts between integral types and the type Boolean.