When an operator involves two distinct types, the expression language has to make a decision about which type to use to implement the operation. If one of the two types can be converted without loss into the other, then it will be. For instance, int can be converted losslessly to double, so 1.0/2 will result in 2 being first converted to 2.0, so the result will be 0.5.
|
Among the scalar types unsignedByte can be converted to anything else, int can be converted to double and double can be converted to complex. Note that long cannot be converted to double without loss, nor vice versa, so an expression like 2.0/2L yields the following error message: Error evaluating expression "2.0/2L" It is because the divide method is not supported between VisualSim.data.DoubleToken '2.0' and VisualSim.data.LongToken '2L' as the types are incomparable.
|
All scalar types have limited precision and magnitude. As a result of this, Arithmetic Operations are subject to underflow and overflow. For Double Numbers, overflow results in the corresponding positive or negative infinity. Underflow (i.e. the precision does not suffice to represent the result) will yield zero.
For integer types and fixedpoint, overflow results in wraparound. For instance, while the value of MaxInt is 2147483647, the expression is “MaxInt + 1 yields –2147483648”. Similarly, while MaxUnsignedByte has value 255ub, “MaxUnsignedByte + 1ub” has value 0ub.
However the “MaxUnsignedByte + 1” yields 256, which is an int and not an unsignedByte. This is because MaxUnsignedByte can be losslessly converted to an int, so the addition is int addition, not unsignedByte addition. Note that these relational operators check the values when possible, irrespective of type.
|
>> 1 == 1.0 returns true To check for equality of both type and value, use the equals() method, as in >> 1.equals(1.0) false
|
Created with the Personal Edition of HelpNDoc: Easily create Help documents