Basic types Numbers

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 representable 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 `runtime.integerSize`

- `Anything`
  - `Object`
    - `Integer` ...and other supertypes

- `Integer`
  - `Binary`
  - `Exponentiable`
    - `Numeric`
      - `Invertible`
        - `Summable`
  - `Integral`
    - `Enumerable`
      - `Ordinal`
    - `Number`
      - `Comparable`
      - `Numeric`
        - `Invertible`
          - `Summable`
  - `Object`
    - `Anything`

no subtypes hierarchy

Constructors
`Integer` | Source Code `shared Integer(Integer integer)`

Attributes
`absolute` | See `magnitude`
`byte` | Source Code `shared Byte byte` A `Byte` whose signed and unsigned interpretations are congruent modulo 256 to this integer. Since 1.1.0
`character` | Source Code `shared 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
`even` | Source Code `shared 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`. Since 1.1.0
- `float` | Source Code `shared Float float` The number, represented as a `Float`, if such a representation is possible. Any integer with `magnitude` smaller than `runtime.maxExactIntegralFloat` (253) has such a representation. For larger integers on the JVM platform, an `OverflowException` is thrown. If this behavior is not desired, use `nearestFloat` instead. Throws `OverflowException` if the number cannot be represented as a `Float` without loss of precision, that is, if
      this.magnitude>runtime.maxExactIntegralFloat
(Note that `nearestFloat` does not produce an exception in this case.) See also `runtime.maxExactIntegralFloat`, `nearestFloat` Since 1.1.0
`fractionalPart` | Source Code `shared 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. Refines `Number.fractionalPart`
`hash` | Source Code `shared actual Integer hash` The hash code of this `Integer`, which is just the `Integer` itself, except on the JVM platform where, as with all `hash` codes, this 64-bit `Integer` value is truncated to 32 bits by taking the exclusive disjunction of the 32 lowest-order bits with the 32 highest-order bits, that is:
    int.hash == int.rightArithmeticShift(32).exclusiveOr(int)
Refines `Object.hash`
`magnitude` | Source Code `shared 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`. Refines `Number.magnitude` Aliases: `absolute`
`nearestFloat` | Source Code `shared 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`. See also `float` Since 1.2.0
`negated` | Source Code `shared actual Integer negated` The additive inverse of this value. Refines `Invertible.negated`
`negative` | Source Code `shared actual Boolean negative` Determine if the number is strictly negative, that is, if `this<0`, where `0` is the additive identity. Refines `Number.negative`
`not` | Source Code `shared actual Integer not` The binary complement of this sequence of bits. Refines `Binary.not`
`positive` | Source Code `shared actual Boolean positive` Determine if the number is strictly positive, that is, if `this>0`, where `0` is the additive identity. Refines `Number.positive`
`predecessor` | Source Code `shared actual Integer predecessor` The predecessor of this value. Refines `Enumerable.predecessor` ultimately refines `Ordinal.predecessor`
`sign` | Source Code `shared actual Integer sign` The sign of this number: `1` if the number is `Number.positive`, `-1` if it is `Number.negative`, or `0` if it is the additive identity. Must satisfy:
    x.magnitude.timesInteger(x.sign) == x
Refines `Number.sign`
`string` | Source Code `shared 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. See also `formatInteger()` Refines `Object.string`
`successor` | Source Code `shared actual Integer successor` The successor of this value. Refines `Enumerable.successor` ultimately refines `Ordinal.successor`
`unit` | Source Code `shared actual Boolean unit` Determine if the number is the multiplicative identity. Refines `Integral.unit`
`wholePart` | Source Code `shared 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. Refines `Number.wholePart`
`zero` | Source Code `shared actual Boolean zero` Determine if the number is the additive identity. Refines `Integral.zero`

Inherited Attributes
Attributes inherited from: `Object` `hash`, `string`
Attributes inherited from: `Binary<Other>` `not`
Attributes inherited from: `Enumerable<Other>` `predecessor`, `successor`
Attributes inherited from: `Integral<Other>` `unit`, `zero`
Attributes inherited from: `Invertible<Other>` `negated`
Attributes inherited from: `Number<Other>` `absolute`, `fractionalPart`, `magnitude`, `negative`, `positive`, `sign`, `wholePart`
Attributes inherited from: `Ordinal<Other>` `predecessor`, `successor`

Methods
`and` | Source Code `shared actual Integer and(Integer other)` Performs a logical AND operation. Refines `Binary.and`
`clear` | Source Code `shared 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`
`compare` | Source Code `shared actual Comparison compare(Integer other)` Compare this integer with the given integer, returning: `smaller`, if `this < other`, `larger`, if `this > other`, or `equal`, if `this == other`. Refines `Number.compare` ultimately refines `Comparable.compare`
`divided` | Source Code `shared actual Integer divided(Integer other)` The quotient obtained by dividing this number by the given number. For integral numeric types, this operation rounds toward `0`, the additive identity, and results in a remainder. When the given divisor is exactly `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`. Refines `Numeric.divided`
`divides` | Source Code `shared actual Boolean divides(Integer other)` Determines if this integer is a factor of the given integer, that is, if `remainder(other)==0`. Refines `Integral.divides`
`equals` | Source Code `shared 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: the given object is a `Float`, its value is neither `Float.undefined`, nor `infinity`, the fractional part of its value equals `0.0`, and the integer part part of its value equals this integer, and this integer is between -253 and 253 (exclusive). Refines `Object.equals`
`flip` | Source Code `shared 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`
`format` | Source Code Numbers `shared String format(Integer integer, Integer radix = ..., Character? groupingSeparator = null)` The string representation of the given `integer` in the base given by `radix`. If the given integer is negative, the string representation will begin with `-`. Digits consist of decimal digits `0` to `9`, together with and lowercase letters `a` to `z` for bases greater than 10. For example: `formatInteger(-46)` is `"-46"` `formatInteger(9,2)` is `"1001"` `formatInteger(10,8)` is `"12"` `formatInteger(511,16)` is `"1ff"` `formatInteger(512,32)` is `"g0"` Parameters: `integer` The integer value to format. `radix = 10` The base, between `minRadix` and `maxRadix` inclusive. `groupingSeparator = null` If not `null`, `groupingSeparator` will be used to separate each group of three digits if `radix` is 10 (the default), or each group of four digits if `radix` is 2 or 16. `groupingSeparator` may not be '-', a digit as defined by the Unicode general category Nd, or a letter as defined by the Unicode general categories Lu, Ll, Lt, Lm, and Lo. Throws `AssertionError` if `radix` is not between `minRadix` and `maxRadix` See also `parse()`, `Float.format()` Since 1.3.1
`get` | Source Code `shared actual Boolean get(Integer index)` If the `index` is for an addressable bit, the value of that bit. Otherwise false. Refines `Binary.get`
`largerThan` | Source Code `shared actual Boolean largerThan(Integer other)` Determines if this value is strictly larger than the given value. Refines `Comparable.largerThan`
`leftLogicalShift` | Source Code `shared actual Integer leftLogicalShift(Integer shift)` If the given `shift` is in the range of addressable bits given by
    0..runtime.integerAddressableSize-1
shift the addressable bits to the left by `shift` positions, using zero extension to fill in the least significant bits. Otherwise shift the addressable bits to the left by
    shift.and(runtime.integerAddressableSize-1)
positions, using zero extension. Refines `Binary.leftLogicalShift` Aliases: `leftShift`
`leftShift` | See `leftLogicalShift()`
`minus` | Source Code `shared actual Integer minus(Integer other)` The difference between this number and the given number. Must produce the value `x + -y`. Refines `Invertible.minus`
`modulo` | Source Code `shared 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 or `0`. Since 1.2.0 Refines `Integral.modulo`
`neighbour` | Source Code `shared 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`. Refines `Enumerable.neighbour`
`notLargerThan` | Source Code `shared actual Boolean notLargerThan(Integer other)` Determines if this value is smaller than or equal to the given value. Refines `Comparable.notLargerThan`
`notSmallerThan` | Source Code `shared actual Boolean notSmallerThan(Integer other)` Determines if this value is larger than or equal to the given value. Refines `Comparable.notSmallerThan`
`offset` | Source Code `shared 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`. Refines `Enumerable.offset`
`offsetSign` | Source Code `shared actual Integer offsetSign(Integer other)` The sign of the offset from the given value. Refines `Enumerable.offsetSign`
`or` | Source Code `shared actual Integer or(Integer other)` Performs a logical inclusive OR operation. Refines `Binary.or`
`parse` | Source Code Numbers Basic types `shared Integer|ParseException parse(String string, Integer radix = ...)` The `Integer` value of the given string representation of an integer value in the base given by `radix`, or `null` if the string does not represent an integer in that base, or if the mathematical integer it represents is too large in magnitude to be represented by an instance of the class `Integer`. The syntax accepted by this function depends upon the given base: For base 10, the accepted syntax is the same as the syntax for an `Integer` literal in the Ceylon language except that it may optionally begin with a sign character (`+` or `-`) and may not contain grouping underscore characters. That is, an optional sign character, followed by a string of decimal digits, followed by an optional SI magnitude: `k`, `M`, `G`, `T`, or `P`. For other bases, the accepted syntax is an optional sign character, followed by a string of digits of the given base. The given `radix` specifies the base of the string representation. The list of available digits starts from `0` to `9`, followed by `a` to `z`. When parsing in a specific base, the first `radix` digits from the available digits list is used. This function is not case sensitive; `a` and `A` both correspond to the digit `a` whose decimal value is `10`. Integer: Base10 | BaseN Base10: Sign? Base10Digits Magnitude BaseN: Sign? BaseNDigits Sign: '+' | '-' Magnitude: 'k' | 'M' | 'G' | 'T' | 'P' Base10Digits: ('0'..'9')+ BaseNDigits: ('0'..'9'|'a'..'z'|'A'..'Z')+ Parameters: `string` The string representation to parse. `radix = 10` The base, between `minRadix` and `maxRadix` inclusive. Throws `AssertionError` if `radix` is not between `minRadix` and `maxRadix` See also `format()`, `Float.parse()` Since 1.3.1
`plus` | Source Code `shared 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. For any two instances `x` and `y` of a type that implements `Summable`, `x.plus(y)` may be written as:
    x + y
Refines `Summable.plus`
`plusInteger` | Source Code `shared actual Integer plusInteger(Integer integer)` The result of adding this number to the given `Integer`. Refines `Number.plusInteger`
`power` | Source Code `shared 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 `AssertionError` if the given power is negative Refines `Exponentiable.power`
`powerOfInteger` | Source Code `shared 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 `AssertionError` if the given power is negative Refines `Number.powerOfInteger`
`remainder` | Source Code `shared actual Integer remainder(Integer other)` The remainder, after dividing this number by the given number. The sign of the remainder depends upon the sign of this number, and of the argument divisor: if this dividend is positive, the remainder has the opposite sign as the divisor, or is `0`, if this dividend is negative, the remainder has the same sign as the divisor, or is `0`, or if this dividend is zero, the remainder is always `0`. Thus, in order to satisfy the identity `x == (x/y)*y + x%y`, division for an integral numeric type must round toward `0`, the additive identity. Refines `Integral.remainder`
`rightArithmeticShift` | Source Code `shared actual Integer rightArithmeticShift(Integer shift)` If the given `shift` is in the range of addressable bits given by
    0..runtime.integerAddressableSize-1
shift the addressable bits to the right by `shift` positions, using sign extension to fill in the most significant bits. Otherwise shift the addressable bits to the right by
    shift.and(runtime.integerAddressableSize-1)
positions, using sign extension. Refines `Binary.rightArithmeticShift`
`rightLogicalShift` | Source Code `shared actual Integer rightLogicalShift(Integer shift)` If the given `shift` is in the range of addressable bits given by
    0..runtime.integerAddressableSize-1
shift the addressable bits to the right by `shift` positions, using zero extension to fill in the most significant bits. Otherwise shift the addressable bits to the right by
    shift.and(runtime.integerAddressableSize-1)
positions, using zero extension. Refines `Binary.rightLogicalShift` Aliases: `rightShift`
`rightShift` | See `rightLogicalShift()`
`set` | Source Code `shared 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`
`smallerThan` | Source Code `shared actual Boolean smallerThan(Integer other)` Determines if this value is strictly smaller than the given value. Refines `Comparable.smallerThan`
`times` | Source Code `shared actual Integer times(Integer other)` The product of this number and the given number. Refines `Numeric.times`
`timesInteger` | Source Code `shared actual Integer timesInteger(Integer integer)` The result of multiplying this number by the given `Integer`. Refines `Number.timesInteger`
`xor` | Source Code `shared actual Integer xor(Integer other)` Performs a logical exclusive OR operation. Refines `Binary.xor`

Inherited Methods
Methods inherited from: `Object` `equals()`
Methods inherited from: `Binary<Other>` `and()`, `clear()`, `flip()`, `get()`, `leftLogicalShift()`, `or()`, `rightArithmeticShift()`, `rightLogicalShift()`, `set()`, `xor()`
Methods inherited from: `Comparable<Other>` `compare()`, `largerThan()`, `notLargerThan()`, `notSmallerThan()`, `smallerThan()`
Methods inherited from: `Enumerable<Other>` `neighbour()`, `offset()`, `offsetSign()`
Methods inherited from: `Exponentiable<This,Other>` `power()`
Methods inherited from: `Integral<Other>` `divides()`, `modulo()`, `remainder()`
Methods inherited from: `Invertible<Other>` `minus()`
Methods inherited from: `Number<Other>` `compare()`, `plusInteger()`, `powerOfInteger()`, `timesInteger()`
Methods inherited from: `Numeric<Other>` `divided()`, `times()`
Methods inherited from: `Summable<Other>` `plus()`