Package-level declarations

Types

Link copied to clipboard

An exact signed 128-bit integer.

Link copied to clipboard
enum class Rounding : Enum<Rounding>

Which way a quotient that is not whole moves to land on an integer.

Link copied to clipboard
class WideSum

A running Int128 sum that changes in place, for a loop that would otherwise allocate a new Int128 for every term.

Functions

Link copied to clipboard
fun compareProducts(a: Long, b: Long, c: Long, d: Long): Int

The sign of a·b − c·d: negative, zero or positive as a·b is below, equal to or above c·d. Exact for every input, so comparing two fractions a/c and d/b with positive denominators by cross-multiplying can no longer throw or wrap.

Link copied to clipboard
fun Long.minusOrNull(other: Long): Long?

this - other, or null when the exact difference does not fit in a Long. See plusOrNull.

Link copied to clipboard
fun mulDiv(a: Long, b: Long, divisor: Long, rounding: Rounding): Long?

a · b / divisor, rounded as rounding says, or null when the rounded result does not fit in a Long.

fun mulDiv(a: Int128, b: Long, divisor: Long, rounding: Rounding): Int128?

a · b / divisor for a 128-bit a, rounded as rounding says, or null when the rounded result does not fit in an Int128.

Link copied to clipboard

-this, or null for Long.MIN_VALUE, the one Long whose negation does not fit.

Link copied to clipboard
fun Long.plusOrNull(other: Long): Long?

Long arithmetic that answers null instead of wrapping.

Link copied to clipboard
fun Long.timesOrNull(other: Long): Long?

this * other, or null when the exact product does not fit in a Long. See plusOrNull.

Link copied to clipboard
fun Long.timesWide(other: Long): Int128

The exact product of two Longs. It never overflows: the widest product, Long.MIN_VALUE², is 2¹²⁶.