ceil

expect fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

expect fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}
actual inline fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

actual inline fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}
actual inline fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

actual inline fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.2

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}
actual external fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.3

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

actual external fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.3

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}
actual fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.8

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

actual fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.8

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}
actual fun ceil(x: Double): Double(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.8

Return

the smallest double value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159)) // 4.0
println(ceil(-1.1)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0)) // 10.0
// Special cases
println(ceil(Double.NaN)) // NaN
println(ceil(Double.POSITIVE_INFINITY)) // Infinity
println(ceil(Double.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5)) // 3.0
println(ceil(3.5)) // 4.0
println(truncate(3.5)) // 3.0
println(round(3.5)) // 4.0
println(round(3.49)) // 3.0

println(floor(-3.5)) // -4.0
println(ceil(-3.5)) // -3.0
println(truncate(-3.5)) // -3.0
println(round(-3.5)) // -4.0
println(round(-3.49)) // -3.0 
   //sampleEnd
}

actual fun ceil(x: Float): Float(source)

Rounds the given value x to an integer towards positive infinity.

Special cases:

  • ceil(x) is x where x is NaN or +Inf or -Inf or already a mathematical integer.

Since Kotlin

1.8

Return

the smallest Float value that is greater than or equal to the given value x and is a mathematical integer.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(ceil(3.14159f)) // 4.0
println(ceil(-1.1f)) // -1.0
// 10.0 is already an "integer", so no rounding will take place
println(ceil(10.0f)) // 10.0
// Special cases
println(ceil(Float.NaN)) // NaN
println(ceil(Float.POSITIVE_INFINITY)) // Infinity
println(ceil(Float.NEGATIVE_INFINITY)) // -Infinity 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(floor(3.5f)) // 3.0
println(ceil(3.5f)) // 4.0
println(truncate(3.5f)) // 3.0
println(round(3.5f)) // 4.0
println(round(3.49f)) // 3.0

println(floor(-3.5f)) // -4.0
println(ceil(-3.5f)) // -3.0
println(truncate(-3.5f)) // -3.0
println(round(-3.5f)) // -4.0
println(round(-3.49f)) // -3.0 
   //sampleEnd
}