The Number type is the base type for all numeric types in Vikari. Number inherits from Value. Vikari supports the following six concrete numeric types:
Type Name | Example Literal Values | Explanation |
---|---|---|
Integer | 3, 22i, 314I | A 32-bit integer. |
Long | 3i, 22I | A 64-bit integer. |
BigInteger | 3b, 22B | An integer of arbitrarily large precision. |
Float | 3.14f, 6.28F | A 32-bit floating point number. |
Double | 3.14, 6.18d, 1.618D | A 64-bit floating point number. |
BigDecimal | 3.14b, 6.28B | A floating point number of arbitrarily large precision. |
Integer literals without a postscript character denoting its type default to the Integer type. For example: 5. Floating-point literals without a postscript character denoting its type default to the Double type. For example: 5.0. Postscript characters of I and L denote a Integer and Long literal respectively. While postscript characters of F and D denote Float and Double respectively. While B without a decimal portion denotes a BigInteger literal, and B with a decimal portion denotes a BigDecimal.
Postscript characters of numeric literals can be either uppercase or lowercase.
Calculations of numeric values in arithmetic expressions are automatically promoted to the smallest possible enclosing type. This is based on both the types of the operands, and the resulting value. So if an Integer and a Long are added together, the result will be a Long value. Unless the result is too large or small to be encompassed by the type Long, in which case the result will then be a BigInteger.
The same is the case for floating point numbers. Also, all floating point numbers are considered to be a larger enclosing type then integer type numbers. So a BigInteger and a Float added together will result in a Float. Unless the result is too large or small for a Float type, in which case the result will be either Double or BigDecimal, respectively. But the upper and lower bounds of values for the Float and the Double types backing the type system used by Vikari are exceedingly difficult to reach by most ordinary calculations, in comparison to integer type limits.
The result of assigning numeric values to a variable depends on that variable's declared type. Variables of type AtonementCrystal, Value, or Number will always hold the exact result of the assigned value. But specifically typed variables of one of the six concrete types will automatically promote or demote the value to the appropriate type before assignment. This will truncate the value, if necessary.
The following demonstrates usage and properties of numeric types in Vikari.