Skip to content

k-libs/k-big-numbers

Repository files navigation

Big Numbers

k big numbers docs dokka ff69b4 big numbers

BigInt implementation.

Heavily based on Java’s BigInteger type.

Import

  implementation("io.k-libs:big-numbers:0.1.0")

Usage

Construction

// From String to BigInt
"0".toBigInt()
bigIntOf("0")

// From Byte to BigInt
0.toByte().toBigInt()
bigIntOf(0.toByte())

// From Short to BigInt
0.toShort().toBigInt()
bigIntOf(0.toShort())

// From Int to BigInt
0.toBigInt()
bigIntOf(0)

// From Long to BigInt
0L.toBigInt()
bigIntOf(0L)

// From UByte to BigInt
0.toUByte().toBigInt()
bigIntOf(0.toUByte())

// From UShort to BigInt
0.toUShort().toBigInt()
bigIntOf(0.toUShort())

// From UInt to BigInt
0u.toBigInt()
bigIntOf(0u)

// From ULong to BigInt
0uL.toBigInt()
bigIntOf(0uL)

Operations

val b1: BigInt
val b2: BigInt
var b3: BigInt

// Addition
b3 = b1 + b2
b3 = b1 + 2

// Subtraction
b3 = b1 - b2
b3 = b1 - 2

// Multiplication
b3 = b1 * b2
b3 = b1 * 2

// Division
b3 = b1 / b2
b3 = b1 / 2

// Modulus
b3 = b1 % b2
b3 = b1 % 2

// Exponent
b3 = b1 pow 2

// Negate
b3 = -b1

// Bit Shift
b3 = b1 shl 2
b3 = b2 shr 3

// Bitwise AND
b3 = b1 and b2
b3 = b1 and 2

// Bitwise OR
b3 = b1 or b2
b3 = b1 or 2

// Bitwise XOR
b3 = b1 xor b2
b3 = b1 xor 2

// Bitwise AND NOT
b3 = b1 andNot b2
b3 = b1 andNot 2

// Bitwise NOT
b3 = b1.inv()

// Absolute Value
b3 = b1.abs()

// Pow 2
b3 = b1.square()

Version History

Version Docs Description

v0.1.0

Dokka

Initial Release