An exact representation of a positive whole number, negative whole number, or zero. The largest and smallest representable values are platform-dependent:

  • For the JVM runtime, integer values between -263 and 263-1 may be represented without overflow.
  • For the JavaScript runtime, integer values with a magnitude no greater than 253 may be represented without loss of precision.

Overflow or loss of precision occurs silently (with no exception raised).

An integer is considered equal to its float representation, if that exists. That is, for every integer int, either int.float throws an OverflowException, or the expression int.float==int evaluates to true.

An integer is represented as a sequence of bits. Not all of the bits in the representation may be addressed by the methods inherited from Binary:

  • For the JVM runtime, the bits at all indices (0 to 63) are addressable.
  • For the JavaScript runtime, the bits at indices 0 to 31 are addressable.

Literal integers may be written in decimal, hexadecimal, or binary notation:

8660
#21D4
$10000111010100

Underscores may be used to group digits:

8660
#21_D4
$10_0001_1101_0100

no subtypes hierarchy

Initializer
Integer(Integer integer)
Attributes
absoluteSee magnitude
byteshared Byte byte

A Byte whose signed and unsigned interpretations are congruent modulo 256 to this integer.

charactershared Character character

The UTF-32 character with this UCS code point.

Throws
  • OverflowException

    if this integer is not in the range 0..#10FFFF of legal Unicode code points

evenshared Boolean even

Determine if this integer is even.

An integer i is even if there exists an integer k such that:

i == 2*k

Thus, i is even if and only if i%2 == 0.

floatshared Float float

The number, represented as a Float, if such a representation is possible.

Throws
  • OverflowException

    if the number cannot be represented as a Float without loss of precision, that is, if

    this.magnitude>runtime.maxExactIntegralFloat
    
fractionalPartshared actual Integer fractionalPart

The fractional part of this number, after truncation of the integral part. For Integral numeric types, the fractional part is always zero.

hashshared actual Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines Object.equals() must also refine hash.

Because the Integer type is platform-dependent a compiler for a given platform is permitted to further manipulate the calculated hash for an object, and the resulting hash may differ between platforms.

Refines Object.hash
magnitudeshared actual Integer magnitude

The magnitude of this number, defined for any instance x as:

  • -x if x<0, or
  • x otherwise,

where 0 is the additive identity. Hence:

  • x.magnitude >= 0 for any x, and
  • x.magnitude == 0 if and only if x==0.
Aliases: absolute
nearestFloatshared Float nearestFloat

The nearest Float to this number.

  • For any integer with magnitude smaller than runtime.maxExactIntegralFloat (253), this is a Float with the exact same mathematical value (and the same value as float).
  • For larger integers on the JVM platform, the Floats are less dense than the Integers so there may be loss of precision.

This method never throws an OverflowException.

negatedshared actual Integer negated

The additive inverse of this value.

negativeshared actual Boolean negative

Determine if the number is strictly negative, that is, if this<0, where 0 is the additive identity.

notshared actual Integer not

The binary complement of this sequence of bits.

Refines Binary.not
positiveshared actual Boolean positive

Determine if the number is strictly positive, that is, if this>0, where 0 is the additive identity.

predecessorshared actual Integer predecessor

The predecessor of this value.

Refines Enumerable.predecessor ultimately refines Ordinal.predecessor
signshared actual Integer sign

The sign of this number:

Must satisfy:

x.magnitude.timesInteger(x.sign) == x
Refines Number.sign
stringshared actual String string

A developer-friendly string representing the instance. Concatenates the name of the concrete class of the instance with the hash of the instance. Subclasses are encouraged to refine this implementation to produce a more meaningful representation.

successorshared actual Integer successor

The successor of this value.

Refines Enumerable.successor ultimately refines Ordinal.successor
unitshared actual Boolean unit

Determine if the number is the multiplicative identity.

wholePartshared actual Integer wholePart

The integral value of the number after truncation of the fractional part. For Integral numeric types, the integral value of a number is the number itself.

zeroshared actual Boolean zero

Determine if the number is the additive identity.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Binary<Other>
Attributes inherited from: Enumerable<Other>
Attributes inherited from: Integral<Other>
Attributes inherited from: Invertible<Other>
Attributes inherited from: Number<Other>
Attributes inherited from: Ordinal<Other>
Methods
andshared actual Integer and(Integer other)

Performs a logical AND operation.

Refines Binary.and
clearshared actual Integer clear(Integer index)

If the index is for an addressable bit, an instance with the same addressable bits as this instance, but with that bit cleared. Otherwise an instance with the same addressable bits as this instance.

Refines Binary.clear
compareshared actual Comparison compare(Integer other)

Compares this value with the given value. Implementations must respect the constraints that:

  • x==y if and only if x<=>y == equal (consistency with equals()),
  • if x>y then y<x (symmetry), and
  • if x>y and y>z then x>z (transitivity).
dividedshared actual Integer divided(Integer other)

The quotient obtained by dividing this number by the given number. For integral numeric types, this operation results in a remainder.

When the given number is 0, the additive identity, the behavior depends on the numeric type:

  • For some numeric types, including Integer, division by 0 results in an exception.
  • For others, including Float, it results in a special value of the type, for example, infinity.
dividesshared actual Boolean divides(Integer other)

Determine if this number is a factor of the given number.

equalsshared actual Boolean equals(Object that)

Determines if the given object is equal to this Integer, that is, if:

  • the given object is an Integer representing the same whole number.

Or if:

flipshared actual Integer flip(Integer index)

If the index is for an addressable bit, an instance with the same addressable bits as this instance, but with that bit flipped. Otherwise an instance with the same addressable bits as this instance.

Refines Binary.flip
getshared actual Boolean get(Integer index)

If the index is for an addressable bit, the value of that bit. Otherwise false.

Refines Binary.get
largerThanshared actual Boolean largerThan(Integer other)

Determines if this value is strictly larger than the given value.

leftLogicalShiftshared actual Integer leftLogicalShift(Integer shift)

If shift is in the range of addressable bits (0..runtime.integerAddressableSize-1), shift the addressable bits to the left by shift positions. Otherwise shift the addressable bits to the left by (bits + (shift % bits)) % bits where bits=runtime.integerAddressableSize.

minusshared actual Integer minus(Integer other)

The difference between this number and the given number. Must produce the value x + -y.

moduloshared actual Integer modulo(Integer modulus)

The modulo, after dividing this number by the given number. This differs from Integral.remainder() in that the result is always positive.

neighbourshared actual Integer neighbour(Integer offset)

The indirect successor or predecessor at the given offset, where:

  • x.neighbour(0) == x,
  • x.neighbour(i+1) == x.neighbour(i).successor, and
  • x.neighbour(i-1) == x.neighbour(i).predecessor.
notLargerThanshared actual Boolean notLargerThan(Integer other)

Determines if this value is smaller than or equal to the given value.

notSmallerThanshared actual Boolean notSmallerThan(Integer other)

Determines if this value is larger than or equal to the given value.

offsetshared actual Integer offset(Integer other)

Compute the offset from the given value, where:

  • x.offset(x) == 0, and
  • x.successor.offset(x) == 1 if x!=x.successor.
offsetSignshared actual Integer offsetSign(Integer other)

The sign of the offset from the given value.

orshared actual Integer or(Integer other)

Performs a logical inclusive OR operation.

Refines Binary.or
plusshared actual Integer plus(Integer other)

The result of adding the given value to this value. This operation should never perform any kind of mutation upon either the receiving value or the argument value.

plusIntegershared actual Integer plusInteger(Integer integer)

The result of adding this number to the given Integer.

powershared actual Integer power(Integer other)

The result of raising this number to the given non-negative integer power, where 0^0 evaluates to 1.

Throws
powerOfIntegershared actual Integer powerOfInteger(Integer integer)

The result of raising this number to the given non-negative integer power, where 0^0 evaluates to 1.

Throws
remaindershared actual Integer remainder(Integer other)

The remainder, after dividing this number by the given number.

rightArithmeticShiftshared actual Integer rightArithmeticShift(Integer shift)

If shift is in the range of addressable bits (0..runtime.integerAddressableSize-1), shift the addressable bits to the right by shift positions, with sign extension. Otherwise shift the addressable bits to the right by (bits + (shift % bits)) % bits where bits=runtime.integerAddressableSize.

rightLogicalShiftshared actual Integer rightLogicalShift(Integer shift)

If shift is in the range of addressable bits (0..runtime.integerAddressableSize-1), shift the addressable bits to the right by shift positions, with zero extension. Otherwise shift the addressable bits to the right by (bits + (shift % bits)) % bits where bits=runtime.integerAddressableSize.

setshared actual Integer set(Integer index, Boolean bit)

If the index is for an addressable bit, an instance with the same addressable bits as this instance, but with that bit set to bit. Otherwise an instance with the same addressable bits as this instance.

Refines Binary.set
smallerThanshared actual Boolean smallerThan(Integer other)

Determines if this value is strictly smaller than the given value.

timesshared actual Integer times(Integer other)

The product of this number and the given number.

timesIntegershared actual Integer timesInteger(Integer integer)

The result of multiplying this number by the given Integer.

xorshared actual Integer xor(Integer other)

Performs a logical exclusive OR operation.

Refines Binary.xor
Inherited Methods
Methods inherited from: Object
Methods inherited from: Binary<Other>
Methods inherited from: Comparable<Other>
Methods inherited from: Enumerable<Other>
Methods inherited from: Exponentiable<This,Other>
Methods inherited from: Integral<Other>
Methods inherited from: Invertible<Other>
Methods inherited from: Number<Other>
Methods inherited from: Numeric<Other>
Methods inherited from: Summable<Other>