timesWide

fun Long.timesWide(other: Long): Int128

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

Samples

val a = Long.MAX_VALUE / 3
val b = 7L
val c = Long.MAX_VALUE / 5
val d = 11L
// a/b > c/d exactly when a·d > c·b; both products overflow a Long, neither overflows an Int128.
assertTrue(a.timesWide(d) > c.timesWide(b))
assertTrue(compareProducts(a, d, c, b) > 0)