mod

inline fun mod(other: UByte): UByte(source)
inline fun mod(other: UShort): UShort(source)
inline fun mod(other: UInt): UInt(source)
inline fun mod(other: ULong): ULong(source)

Calculates the remainder of flooring division of this value (dividend) by the other value (divisor).

The result is always less than the divisor.

For unsigned types, the remainders of flooring division and truncating division are the same.

Since Kotlin

1.5

Samples

import kotlin.test.assertFailsWith

fun main() { 
   //sampleStart 
   // Unsigned types have no negative values, so mod produces the
// same result as the % operator
println(7u.mod(3u)) // 1
println(7u % 3u) // 1

// A zero divisor throws
// 1u.mod(0u) // will fail with ArithmeticException 
   //sampleEnd
}