class BigInteger
source · line 9public class BigInteger internal constructor(private val storage: IntegerStorage) : Equals<BigInteger>, Compare<BigInteger>, Hash, ToString, Add<BigInteger, BigInteger>, Sub<BigInteger, BigInteger>, Mul<BigInteger, BigInteger>, Div<BigInteger, BigInteger>, Rem<BigInteger, BigInteger>, UnaryPlus<BigInteger>, UnaryMinus<BigInteger>, Increment<BigInteger>, Decrement<BigInteger>
- Supertype
Equals<BigInteger> - Supertype
Compare<BigInteger> - Supertype
Hash - Supertype
ToString - Supertype
Add<BigInteger, BigInteger> - Supertype
Sub<BigInteger, BigInteger> - Supertype
Mul<BigInteger, BigInteger> - Supertype
Div<BigInteger, BigInteger> - Supertype
Rem<BigInteger, BigInteger> - Supertype
UnaryPlus<BigInteger> - Supertype
UnaryMinus<BigInteger> - Supertype
Increment<BigInteger> - Supertype
Decrement<BigInteger>
An immutable arbitrary-precision signed integer with infinite two's-complement bit semantics.
Extensions
public fun BigInteger.toBigDecimal(): BigDecimal· scoop:scoop.math:0.1.0
function hash
source · line 28public override fun hash(): Long
- Overrides
hash
Hashes the mathematical integer.
function pow
source · line 64public fun pow(exponent: Long): BigInteger
Raises to a nonnegative exponent; a negative exponent throws, and 0^0 is one.
parameter exponent
source · line 64exponent: Long
property signum
source · line 22public val signum: Int
get: public read-only
The numeric sign: -1, 0, or 1.
getter get
source · line 22get(): Int
function toUIntExact
source · line 163public fun toUIntExact(): UInt
Converts exactly; an out-of-range value throws ArithmeticException.
function xor
source · line 106public infix fun xor(other: BigInteger): BigInteger
Applies infinite two's-complement XOR to both values.
parameter other
source · line 106other: BigInteger
function clearBit
source · line 92public fun clearBit(index: Long): BigInteger
Clears a nonnegative bit position in the infinite two's-complement representation.
parameter index
source · line 92index: Long
function toShort
source · line 126public fun toShort(): Short
Takes the low 16 bits and interprets them as Short.
function toString
source · line 30public override fun toString(): String
- Overrides
toString
Formats in decimal without redundant leading zeros.
function sqrtAndRemainder
source · line 68public fun sqrtAndRemainder(): (BigInteger, BigInteger)
Returns floor(sqrt(this)) and the exact nonnegative remainder.
function plus
source · line 35public override operator fun plus(other: BigInteger): BigInteger
- Overrides
plus
Returns the exact sum.
parameter other
source · line 35other: BigInteger
function divideAndRemainder
source · line 59public fun divideAndRemainder(other: BigInteger): (BigInteger, BigInteger)
Computes quotient and remainder together; the quotient truncates toward zero.
parameter other
source · line 59other: BigInteger
function toLong
source · line 140public fun toLong(): Long
Takes the low 64 bits and interprets them as Long.
function div
source · line 41public override operator fun div(other: BigInteger): BigInteger
- Overrides
div
Divides toward zero; a zero divisor throws ArithmeticException.
parameter other
source · line 41other: BigInteger
function toUByte
source · line 147public fun toUByte(): UByte
Takes the low 8 bits and interprets them as UByte.
function toDouble
source · line 117public fun toDouble(): Double
Rounds directly to binary64 with nearest-even rounding, allowing infinity.
function toShortExact
source · line 128public fun toShortExact(): Short
Converts exactly; an out-of-range value throws ArithmeticException.
function toByteArray
source · line 111public fun toByteArray(order: ByteOrder = ByteOrder.BigEndian): Array<Byte>
Returns an independent shortest signed two's-complement byte array; zero is one zero byte.
parameter order
source · line 111order: ByteOrder = ByteOrder.BigEndian
function shr
source · line 100public infix fun shr(distance: Long): BigInteger
Shifts arithmetically right; negative distances shift left.
parameter distance
source · line 100distance: Long
function compareTo
source · line 26public override operator fun compareTo(other: BigInteger): Long
- Overrides
compareTo
Returns -1, 0, or 1 in numerical order.
parameter other
source · line 26other: BigInteger
function unaryPlus
source · line 45public override operator fun unaryPlus(): BigInteger
- Overrides
unaryPlus
Returns this immutable value.
function nextProbablePrime
source · line 181public fun nextProbablePrime(random: Random, certainty: Int = 100): BigInteger
Finds the next larger positive probable prime using the explicit random source.
parameter random
source · line 181random: Random
parameter certainty
source · line 181certainty: Int = 100
function minus
source · line 37public override operator fun minus(other: BigInteger): BigInteger
- Overrides
minus
Returns the exact difference.
parameter other
source · line 37other: BigInteger
function max
source · line 57public fun max(other: BigInteger): BigInteger
Returns the larger value, retaining this instance on equality.
parameter other
source · line 57other: BigInteger
function gcd
source · line 73public fun gcd(other: BigInteger): BigInteger
Returns the nonnegative greatest common divisor, including gcd(0,0)=0.
parameter other
source · line 73other: BigInteger
function toString
source · line 32public fun toString(radix: Int): String
Formats in radix 2..36 with lowercase digits; an invalid radix throws.
parameter radix
source · line 32radix: Int
function min
source · line 55public fun min(other: BigInteger): BigInteger
Returns the smaller value, retaining this instance on equality.
parameter other
source · line 55other: BigInteger
function toFloat
source · line 115public fun toFloat(): Float
Rounds directly to binary32 with nearest-even rounding, allowing infinity.
function toLongExact
source · line 142public fun toLongExact(): Long
Converts exactly; an out-of-range value throws ArithmeticException.
function modInverse
source · line 79public fun modInverse(modulus: BigInteger): BigInteger
Returns the modular inverse, or throws for a nonpositive modulus or missing inverse.
parameter modulus
source · line 79modulus: BigInteger
function toUShort
source · line 154public fun toUShort(): UShort
Takes the low 16 bits and interprets them as UShort.
function abs
source · line 53public fun abs(): BigInteger
Returns the nonnegative magnitude.
constructor constructor
source · line 15constructor(value: Long)
Constructs the exact signed integer.
parameter value
source · line 15value: Long
function isProbablePrime
source · line 176public fun isProbablePrime(random: Random, certainty: Int = 100): Boolean
Tests primality; certainty must be positive, and the random source must supply independent uniform bits.
parameter random
source · line 176random: Random
parameter certainty
source · line 176certainty: Int = 100
function unaryMinus
source · line 47public override operator fun unaryMinus(): BigInteger
- Overrides
unaryMinus
Returns the exact negation.
function times
source · line 39public override operator fun times(other: BigInteger): BigInteger
- Overrides
times
Returns the exact product.
parameter other
source · line 39other: BigInteger
function toULong
source · line 168public fun toULong(): ULong
Takes the low 64 bits and interprets them as ULong.
constructor constructor
source · line 17constructor(value: ULong)
Constructs the exact unsigned integer, including values above Long.MAX_VALUE.
parameter value
source · line 17value: ULong
function bitCount
source · line 84public fun bitCount(): Long
Counts bits differing from the infinitely extended sign bit.
function toMagnitudeByteArray
source · line 113public fun toMagnitudeByteArray(order: ByteOrder = ByteOrder.BigEndian): Array<Byte>
Returns an independent shortest unsigned magnitude byte array; zero is one zero byte.
parameter order
source · line 113order: ByteOrder = ByteOrder.BigEndian
function rem
source · line 43public override operator fun rem(other: BigInteger): BigInteger
- Overrides
rem
Returns the remainder with this value's sign; a zero divisor throws.
parameter other
source · line 43other: BigInteger
function inv
source · line 96public fun inv(): BigInteger
Inverts every bit, including the infinitely extended sign.
function toUShortExact
source · line 156public fun toUShortExact(): UShort
Converts exactly; an out-of-range value throws ArithmeticException.
function mod
source · line 75public fun mod(modulus: BigInteger): BigInteger
Reduces into [0, modulus); a nonpositive modulus throws ArithmeticException.
parameter modulus
source · line 75modulus: BigInteger
function toUByteExact
source · line 149public fun toUByteExact(): UByte
Converts exactly; an out-of-range value throws ArithmeticException.
function bitLength
source · line 82public fun bitLength(): Long
Counts bits after removing redundant sign extension; zero and -1 have length zero.
function toInt
source · line 133public fun toInt(): Int
Takes the low 32 bits and interprets them as Int.
function toIntExact
source · line 135public fun toIntExact(): Int
Converts exactly; an out-of-range value throws ArithmeticException.
function andNot
source · line 108public infix fun andNot(other: BigInteger): BigInteger
Applies infinite two's-complement ANDNOT to both values.
parameter other
source · line 108other: BigInteger
function equals
source · line 24public override operator fun equals(other: BigInteger): Boolean
- Overrides
equals
Compares mathematical values.
parameter other
source · line 24other: BigInteger
function flipBit
source · line 94public fun flipBit(index: Long): BigInteger
Flips a nonnegative bit position in the infinite two's-complement representation.
parameter index
source · line 94index: Long
function toByte
source · line 119public fun toByte(): Byte
Takes the low 8 bits and interprets them as Byte.
function sqrt
source · line 66public fun sqrt(): BigInteger
Returns floor(sqrt(this)); negative values throw ArithmeticException.
function toUInt
source · line 161public fun toUInt(): UInt
Takes the low 32 bits and interprets them as UInt.
function setBit
source · line 90public fun setBit(index: Long): BigInteger
Sets a nonnegative bit position in the infinite two's-complement representation.
parameter index
source · line 90index: Long
function inc
source · line 49public override operator fun inc(): BigInteger
- Overrides
inc
Returns this value plus one.
function and
source · line 102public infix fun and(other: BigInteger): BigInteger
Applies infinite two's-complement AND to both values.
parameter other
source · line 102other: BigInteger
function shl
source · line 98public infix fun shl(distance: Long): BigInteger
Shifts left without masking the distance; negative distances shift right.
parameter distance
source · line 98distance: Long
function or
source · line 104public infix fun or(other: BigInteger): BigInteger
Applies infinite two's-complement OR to both values.
parameter other
source · line 104other: BigInteger
function lowestSetBit
source · line 86public fun lowestSetBit(): Long
Returns the lowest set bit, or -1 for zero.
function dec
source · line 51public override operator fun dec(): BigInteger
- Overrides
dec
Returns this value minus one.
function testBit
source · line 88public fun testBit(index: Long): Boolean
Tests a nonnegative bit position; a negative index throws IllegalArgumentException.
parameter index
source · line 88index: Long
function toByteExact
source · line 121public fun toByteExact(): Byte
Converts exactly; an out-of-range value throws ArithmeticException.
function modPow
source · line 77public fun modPow(exponent: BigInteger, modulus: BigInteger): BigInteger
Computes a modular power; negative exponents require a modular inverse.
parameter exponent
source · line 77exponent: BigInteger
parameter modulus
source · line 77modulus: BigInteger
function toULongExact
source · line 170public fun toULongExact(): ULong
Converts exactly; an out-of-range value throws ArithmeticException.