BigInteger

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns a BigInteger whose value is the absolute value of this BigInteger.

Link copied to clipboard
abstract val bitCount: Int

Returns the number of bits in the two's complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.

Link copied to clipboard
abstract val bitLength: Int

Returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. (Computes (ceil(log2(this < 0 ? -this : this+1))).)

Link copied to clipboard
abstract val signum: Int

Returns the _signum function of this BigInteger.

Functions

Link copied to clipboard
open fun and(other: Int): BigInteger
open fun and(other: Long): BigInteger

abstract fun and(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this & val). (This method returns a negative BigInteger if and only if this and val are both negative.)

Link copied to clipboard
open fun andNot(other: Int): BigInteger
open fun andNot(other: Long): BigInteger

abstract fun andNot(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this & ~val). This method, which is equivalent to and(val.not()), is provided as a convenience for masking operations. (This method returns a negative BigInteger if and only if this is negative and other is positive.)

Link copied to clipboard
abstract fun clearBit(n: Int): BigInteger

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit cleared. (Computes (this & ~(1<<n)).)

Link copied to clipboard
abstract operator override fun compareTo(other: BigInteger): Int

Compares this BigInteger with the specified BigInteger. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y)<op>0), where <op> is one of the six comparison operators.

Link copied to clipboard
open operator fun div(other: Int): BigInteger
open operator fun div(other: Long): BigInteger

abstract operator fun div(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this / val).

Link copied to clipboard
open fun divideAndRemainder(other: Int): Array<out BigInteger>
open fun divideAndRemainder(other: Long): Array<out BigInteger>

abstract fun divideAndRemainder(other: BigInteger): Array<out BigInteger>

Returns an array of two BigIntegers containing (this / val) followed by (this % val).

Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean

Compares this BigInteger with the specified Object for equality.

Link copied to clipboard
abstract fun flipBit(n: Int): BigInteger

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped. (Computes (this ^ (1<<n)).)

Link copied to clipboard
open fun gcd(other: Int): BigInteger
open fun gcd(other: Long): BigInteger

abstract fun gcd(other: BigInteger): BigInteger

Returns a BigInteger whose value is the greatest common divisor of absoluteValue(this) and absoluteValue(val). Returns 0 if this == 0 && val == 0.

Link copied to clipboard
abstract operator fun get(n: Int): Boolean
Link copied to clipboard
abstract override fun hashCode(): Int

Returns the hash code for this BigInteger.

Link copied to clipboard
abstract fun isProbablePrime(certainty: Int): Boolean

Returns true if this BigInteger is probably prime, false if it's definitely composite. If certainty is 0, true is returned.

Link copied to clipboard
abstract fun max(other: BigInteger): BigInteger

Returns the maximum of this BigInteger and other.

Link copied to clipboard
abstract fun min(other: BigInteger): BigInteger

Returns the minimum of this BigInteger and other.

Link copied to clipboard
open operator fun minus(other: Int): BigInteger
open operator fun minus(other: Long): BigInteger

abstract operator fun minus(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this - val).

Link copied to clipboard
open fun modInverse(modulus: Int): BigInteger
open fun modInverse(modulus: Long): BigInteger

abstract fun modInverse(modulus: BigInteger): BigInteger

Returns a BigInteger whose value is (this-1 rem m).

Link copied to clipboard
abstract fun modPow(exponent: BigInteger, modulus: BigInteger): BigInteger

Returns a BigInteger whose value is (this<sup>exponent</sup> rem m). (Unlike pow, this method permits negative exponents.)

Link copied to clipboard

Returns the first integer greater than this BigInteger that is probably prime. The probability that the number returned by this method is composite does not exceed 2-100. This method will never skip over a prime when searching: if it returns p, there is no prime q such that this < q < p.

Link copied to clipboard
abstract operator fun not(): BigInteger

Returns a BigInteger whose value is (~this). (This method returns a negative value if and only if this BigInteger is non-negative.)

Link copied to clipboard
open fun or(other: Int): BigInteger
open fun or(other: Long): BigInteger

abstract fun or(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this | val). (This method returns a negative BigInteger if and only if either this or val is negative.)

Link copied to clipboard
open operator fun plus(other: Int): BigInteger
open operator fun plus(other: Long): BigInteger

abstract operator fun plus(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this + val).

Link copied to clipboard
abstract infix fun pow(exponent: Int): BigInteger

Returns a BigInteger whose value is (this<sup>exponent</sup>). Note that exponent is an integer rather than a BigInteger.

Link copied to clipboard
open operator fun rangeTo(endInclusive: Int): BigIntegerRange
open operator fun rangeTo(endInclusive: Long): BigIntegerRange
open operator fun rangeTo(endInclusive: BigInteger): BigIntegerRange
Link copied to clipboard
open operator fun rem(modulus: Int): BigInteger
open operator fun rem(modulus: Long): BigInteger

abstract operator fun rem(modulus: BigInteger): BigInteger

Returns a BigInteger whose value is (this rem m). This method differs from remainder in that it always returns a non-negative BigInteger.

Link copied to clipboard
open fun remainder(other: Int): BigInteger
open fun remainder(other: Long): BigInteger

abstract fun remainder(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this % val).

Link copied to clipboard
abstract operator fun set(n: Int, b: Boolean): BigInteger
Link copied to clipboard
abstract fun setBit(n: Int): BigInteger

Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit set. (Computes (this | (1<<n)).)

Link copied to clipboard
abstract infix fun shl(n: Int): BigInteger

Returns a BigInteger whose value is (this << n). The shift distance, n, may be negative, in which case this method performs a right shift. (Computes floor(this * 2<sup>n</sup>).)

Link copied to clipboard
abstract infix fun shr(n: Int): BigInteger

Returns a BigInteger whose value is (this >> n). Sign extension is performed. The shift distance, n, may be negative, in which case this method performs a left shift. (Computes floor(this / 2<sup>n</sup>).)

Link copied to clipboard
abstract fun sqrt(): BigInteger

Returns the integer square root of this BigInteger. The integer square root of the corresponding mathematical integer n is the largest mathematical integer s such that s*s <= n. It is equal to the value of floor(sqrt(n)), where sqrt(n) denotes the real square root of n treated as a real. Note that the integer square root will be less than the real square root if the latter is not representable as an integral value.

Link copied to clipboard
abstract fun sqrtAndRemainder(): Array<out BigInteger>

Returns an array of two BigIntegers containing the integer square root s of this and its remainder this - s*s, respectively.

Link copied to clipboard
abstract fun testBit(n: Int): Boolean

Returns true if and only if the designated bit is set. (Computes ((this & (1<<n)) != 0).)

Link copied to clipboard
open operator fun times(other: Int): BigInteger
open operator fun times(other: Long): BigInteger

abstract operator fun times(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this * val).

Link copied to clipboard
abstract fun toByte(): Byte
Link copied to clipboard
abstract fun toByteArray(): ByteArray

Returns a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element. The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit, which is (ceil((this.bitLength() + 1)/8)). (This representation is compatible with the byte array constructor.)

Link copied to clipboard
abstract fun toByteExact(): Byte

Converts this BigInteger to a byte, checking for lost information. If the value of this BigInteger is out of the range of the byte type, then an ArithmeticException is thrown.

Link copied to clipboard
abstract fun toChar(): Char
Link copied to clipboard
abstract fun toDouble(): Double
Link copied to clipboard
abstract fun toFloat(): Float
Link copied to clipboard
abstract fun toInt(): Int

Converts this BigInteger to an int. This conversion is analogous to a narrowing primitive conversion from long to int as defined in The Java Language Specification: if this BigInteger is too big to fit in an int, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.

Link copied to clipboard
abstract fun toIntExact(): Int

Converts this BigInteger to an int, checking for lost information. If the value of this BigInteger is out of the range of the int type, then an ArithmeticException is thrown.

Link copied to clipboard
Link copied to clipboard
abstract fun toLong(): Long

Converts this BigInteger to a long. This conversion is analogous to a narrowing primitive conversion from long to int as defined in The Java Language Specification: if this BigInteger is too big to fit in a long, only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.

Link copied to clipboard
abstract fun toLongExact(): Long

Converts this BigInteger to a long, checking for lost information. If the value of this BigInteger is out of the range of the long type, then an ArithmeticException is thrown.

Link copied to clipboard
abstract fun toShort(): Short
Link copied to clipboard
abstract fun toShortExact(): Short

Converts this BigInteger to a short, checking for lost information. If the value of this BigInteger is out of the range of the short type, then an ArithmeticException is thrown.

Link copied to clipboard
abstract override fun toString(): String

Returns the decimal String representation of this BigInteger. The digit-to-character mapping provided by Character.forDigit is used, and a subtract sign is prepended if appropriate. (This representation is compatible with the string constructor, and allows for String concatenation with Java's + operator.)

abstract fun toString(radix: Int): String

Returns the String representation of this BigInteger in the given radix. If the radix is outside the range from CHAR_MIN_RADIX to CHAR_MAX_RADIX inclusive, it will default to 10 (as is the case for Int.toString). The digit-to-character mapping provided by Character.forDigit is used, and a subtract sign is prepended if appropriate. (This representation is compatible with the String constructor.)

Link copied to clipboard
abstract operator fun unaryMinus(): BigInteger

Returns a BigInteger whose value is (-this).

Link copied to clipboard
abstract operator fun unaryPlus(): BigInteger
Link copied to clipboard
open fun xor(other: Int): BigInteger
open fun xor(other: Long): BigInteger

abstract fun xor(other: BigInteger): BigInteger

Returns a BigInteger whose value is (this ^ val). (This method returns a negative BigInteger if and only if exactly one of this and val are negative.)