Spec-Zone.ru › Kotlin 2

floorDiv

kotlin-stdlib/kotlin/floorDiv

Начиная с Kotlin: 1.5

inline fun Byte.floorDiv(other: Byte): Int
inline fun Byte.floorDiv(other: Short): Int
inline fun Byte.floorDiv(other: Int): Int
inline fun Byte.floorDiv(other: Long): Long
inline fun Short.floorDiv(other: Byte): Int
inline fun Short.floorDiv(other: Short): Int
inline fun Short.floorDiv(other: Int): Int
inline fun Short.floorDiv(other: Long): Long
inline fun Int.floorDiv(other: Byte): Int
inline fun Int.floorDiv(other: Short): Int
inline fun Int.floorDiv(other: Int): Int
inline fun Int.floorDiv(other: Long): Long
inline fun Long.floorDiv(other: Byte): Long
inline fun Long.floorDiv(other: Short): Long
inline fun Long.floorDiv(other: Int): Long
inline fun Long.floorDiv(other: Long): Long

Делит это значение на другое значение, округляя результат до целого в сторону отрицательной бесконечности.

Примеры

import kotlin.test.assertFailsWith

fun main() { 
   //sampleStart 
   // Regular integer division (/) truncates toward zero
println((-7) / 3) // -2
// floorDiv rounds toward negative infinity
println((-7).floorDiv(3)) // -3
println(7.floorDiv(3)) // 2
println(7.floorDiv(-3)) // -3

// Dividing by zero throws, just like the / operator
// 1.floorDiv(0) // 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/floor-div.html

Spec-Zone.ru

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