IntegersealedA 64-bit signed whole number -- the type of integer literals like 42.
Arithmetic between two Integers stays an Integer (/ truncates toward zero); an operation with a Double operand is carried out in floating point and yields a Double. There is no automatic promotion to arbitrary precision -- convert explicitly with BigInteger.of: when a value can outgrow 64 bits.
7 / 2 "* -> 3 7 / 2.0 "* -> 3.5
Quoin-side numeric conveniences; the arithmetic itself is native.
Integers gain the .. range constructor.
Conversions from the built-in Integer to the arbitrary-precision stdlib number types. (BigInteger / BigDecimal themselves are native — src/runtime/big_integer.rs, src/runtime/big_decimal.rs — registered before this loads.)
The type's zero value (0); Iterate#sum: seeds an accumulation with it.
Parse a hexadecimal String into an Integer -- surrounding whitespace is ignored and an optional 0x/0X prefix is accepted; raises a ValueError for a non-hex string. Handy where protocols carry hex, e.g. HTTP chunk sizes.
Integer.fromHex:'ff' "* -> 255 Integer.fromHex:'0x1A' "* -> 26
The remainder after truncating division (a % b); the result takes the dividend's sign. A zero Integer divisor raises an ArithmeticError; a Double operand yields a Double remainder.
7 % 3 "* -> 1 (0 - 7) % 3 "* -> -1
Multiplication (a * b). Integer * Integer yields an Integer; a Double operand makes the result a Double.
6 * 7 "* -> 42
Addition (a + b). Integer + Integer yields an Integer; a Double operand makes the result a Double.
1 + 2.5 "* -> 3.5
Unary minus (-self).
Subtraction (a - b). Integer - Integer yields an Integer; a Double operand makes the result a Double.
10 - 3 "* -> 7
A NumberRange from self (inclusive) to e (exclusive); counts down when self > e.
(2..5).list "* -> #(2 3 4)
Division (a / b). Between two Integers the quotient truncates toward zero, and dividing by zero raises an ArithmeticError; a Double operand gives true floating-point division.
7 / 2 "* -> 3 (0 - 7) / 2 "* -> -3 7 / 2.0 "* -> 3.5
Whether the receiver is less than the argument (a < b, Integer or Double). The one native comparison -- >, <= and >= all derive from it.
2 < 3 "* -> true
Numeric equality with any value. Integers and Doubles compare by numeric value; a non-number is simply unequal, never an error.
5 == 5.0 "* -> true 5 == 'a' "* -> false
Absolute value.
(-5).abs "* -> 5
This Integer as an exact arbitrary-precision BigInteger.
2.asBigInteger.pow:100 "* -> 1267650600228229401496703205376
The receiver itself: a whole number is its own ceiling. Mirrors Double.ceil.
The receiver itself: a whole number is its own floor. Present so Integer mirrors Double's rounding surface (where floor rounds down to an Integer).
Identity — an Integer answers itself, so integer normalizes a value that may already be an Integer.
The larger of the receiver and the argument, returned as the winning operand itself -- a mixed Integer/Double comparison keeps the winner's own type (so 5.max: 7.0 is the Double 7.0).
5.max: 3.0 "* -> 5
The smaller of the receiver and the argument, returned as the winning operand itself -- a mixed Integer/Double comparison keeps the winner's own type.
3.min: 9 "* -> 3
The next integer up: self + 1.
3.next "* -> 4
The receiver raised to the argument's power. A non-negative Integer exponent stays an Integer and is overflow-checked (an out-of-range result raises an ArithmeticError -- there is no auto-promotion to BigInteger); a negative or Double exponent leaves the integer domain and yields a Double.
2.pow: 10 "* -> 1024 2.pow: 0 - 1 "* -> 0.5
The receiver itself: a whole number is already rounded. Mirrors Double.round.
The decimal digits as a String.
1024.s "* -> 1024
-1, 0, or 1 by the receiver's sign.
(0 - 5).sign "* -> -1 0.sign "* -> 0
The square root, as a Double. Raises an ArithmeticError for a negative receiver.
2.sqrt "* -> 1.4142135623730951
The receiver itself: a whole number has no fraction to drop. Mirrors Double.truncate.