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. That is, for every integer int, 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
See also integerSize, parseInteger()

no subtypes hierarchy

Initializer
Integer(Integer integer)
Attributes
byteSource Codeshared Byte byte

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

characterSource Codeshared Character character

The UTF-32 character with this UCS code point.

Throws
evenSource Codeshared 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.

floatSource Codeshared 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

fractionalPartSource Codeshared 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.

hashSource Codeshared 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.

Refines Object.hash
magnitudeSource Codeshared 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.
negatedSource Codeshared actual Integer negated

The additive inverse of this value.

negativeSource Codeshared actual Boolean negative

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

notSource Codeshared actual Integer not

The binary complement of this sequence of bits.

Refines Binary.not
positiveSource Codeshared actual Boolean positive

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

predecessorSource Codeshared actual Integer predecessor

The predecessor of this value.

Refines Enumerable.predecessor ultimately refines Ordinal.predecessor
signSource Codeshared actual Integer sign

The sign of this number:

Must satisfy:

x.magnitude.timesInteger(x.sign) == x
Refines Number.sign
stringSource Codeshared 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.

successorSource Codeshared actual Integer successor

The successor of this value.

Refines Enumerable.successor ultimately refines Ordinal.successor
unitSource Codeshared actual Boolean unit

Determine if the number is the multiplicative identity.

wholePartSource Codeshared 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.

zeroSource Codeshared actual Boolean zero

Determine if the number is the additive identity.

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

Performs a logical AND operation.

Refines Binary.and
clearSource Codeshared 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
compareSource Codeshared 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).
dividedSource Codeshared 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.
equalsSource Codeshared actual Boolean equals(Object that)

Determine if two values are equal. Implementations should respect the constraints that:

  • if x===y then x==y (reflexivity),
  • if x==y then y==x (symmetry),
  • if x==y and y==z then x==z (transitivity).

Furthermore it is recommended that implementations ensure that if x==y then x and y have the same concrete class.

A class which explicitly refines equals() is said to support value equality, and the equality operator == is considered much more meaningful for such classes than for a class which simply inherits the default implementation of identity equality from Identifiable.

flipSource Codeshared 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
getSource Codeshared actual Boolean get(Integer index)

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

Refines Binary.get
largerThanSource Codeshared actual Boolean largerThan(Integer other)

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

leftLogicalShiftSource Codeshared 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.

minusSource Codeshared actual Integer minus(Integer other)

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

neighbourSource Codeshared 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.
notLargerThanSource Codeshared actual Boolean notLargerThan(Integer other)

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

notSmallerThanSource Codeshared actual Boolean notSmallerThan(Integer other)

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

offsetSource Codeshared 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.
offsetSignSource Codeshared actual Integer offsetSign(Integer other)

The sign of the offset from the given value.

orSource Codeshared actual Integer or(Integer other)

Performs a logical inclusive OR operation.

Refines Binary.or
plusSource Codeshared 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.

plusIntegerSource Codeshared actual Integer plusInteger(Integer integer)

The result of adding this number to the given Integer.

powerSource Codeshared actual Integer power(Integer other)

The result of raising this number to the given power.

powerOfIntegerSource Codeshared actual Integer powerOfInteger(Integer integer)

The result of raising this number to the given non-negative Integer power. For a negative power, the behavior is implementation-dependent.

remainderSource Codeshared actual Integer remainder(Integer other)

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

rightArithmeticShiftSource Codeshared 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.

rightLogicalShiftSource Codeshared 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.

setSource Codeshared 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
smallerThanSource Codeshared actual Boolean smallerThan(Integer other)

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

timesSource Codeshared actual Integer times(Integer other)

The product of this number and the given number.

timesIntegerSource Codeshared actual Integer timesInteger(Integer integer)

The result of multiplying this number by the given Integer.

xorSource Codeshared actual Integer xor(Integer other)

Performs a logical exclusive OR operation.

Refines Binary.xor
Inherited Methods
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>