← index

Integersealed

inherits Object

A 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
extended at core/00-bootstrap.qn:302

Quoin-side numeric conveniences; the arithmetic itself is native.

extended at core/03-number_range.qn:62

Integers gain the .. range constructor.

extended at core/08-bignum.qn:4

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.)

Class methods

default

The type's zero value (0); Iterate#sum: seeds an accumulation with it.

core/00-bootstrap.qn:305

fromHex:String

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

native

Instance methods

%:Integer
%:Double

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

native

*:Integer
*:Double

Multiplication (a * b). Integer * Integer yields an Integer; a Double operand makes the result a Double.

6 * 7     "* -> 42

native

+:Integer
+:Double

Addition (a + b). Integer + Integer yields an Integer; a Double operand makes the result a Double.

1 + 2.5     "* -> 3.5

native

-

Unary minus (-self).

core/00-bootstrap.qn:320

-:Integer
-:Double

Subtraction (a - b). Integer - Integer yields an Integer; a Double operand makes the result a Double.

10 - 3     "* -> 7

native

..:

A NumberRange from self (inclusive) to e (exclusive); counts down when self > e.

(2..5).list    "* -> #(2 3 4)

core/03-number_range.qn:69

/:Integer
/:Double

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

native

<:Integer
<:Double

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

native

==:

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

native

abs

Absolute value.

(-5).abs    "* -> 5

core/00-bootstrap.qn:327

asBigInteger

This Integer as an exact arbitrary-precision BigInteger.

2.asBigInteger.pow:100    "* -> 1267650600228229401496703205376

core/08-bignum.qn:10

ceil

The receiver itself: a whole number is its own ceiling. Mirrors Double.ceil.

native

floor

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).

native

integer

Identity — an Integer answers itself, so integer normalizes a value that may already be an Integer.

core/00-bootstrap.qn:310

max:Integer
max:Double

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

native

min:Integer
min:Double

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

native

next

The next integer up: self + 1.

3.next    "* -> 4

core/00-bootstrap.qn:317

pow:Integer
pow:Double

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

native

round

The receiver itself: a whole number is already rounded. Mirrors Double.round.

native

s

The decimal digits as a String.

1024.s     "* -> 1024

native

sign

-1, 0, or 1 by the receiver's sign.

(0 - 5).sign     "* -> -1
0.sign           "* -> 0

native

sqrt

The square root, as a Double. Raises an ArithmeticError for a negative receiver.

2.sqrt     "* -> 1.4142135623730951

native

truncate

The receiver itself: a whole number has no fraction to drop. Mirrors Double.truncate.

native