Spec-Zone.ru › Kotlin 2

mod

kotlin-stdlib/kotlin/UInt/mod

Начиная с Kotlin: 1.5

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

Вычисляет остаток от деления с округлением вниз этого значения (делимого) на другое значение (делитель).

Результат всегда меньше делителя.

Для беззнаковых типов остатки от деления с округлением вниз и деления с усечением совпадают.

Примеры

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
}

© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-int/mod.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API