Spec-Zone.ru › Kotlin 2

exp

kotlin-stdlib/kotlin.math/exp

Требования к платформе и версии: Common (1.2), Wasm-JS (1.8), Wasm-WASI (1.8)

expect fun exp(x: Double): Double

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Double.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0).firstFiveDigits()) // 2.71828
println(exp(2.0).firstFiveDigits()) // 7.38905
println(exp(-1.0).firstFiveDigits()) // 0.36787

// special cases
println(exp(Double.NaN)) // NaN
println(exp(Double.POSITIVE_INFINITY)) // Infinity
println(exp(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

expect fun exp(x: Float): Float

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Float.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0f).firstFiveDigits()) // 2.71828
println(exp(2.0f).firstFiveDigits()) // 7.38905
println(exp(-1.0f).firstFiveDigits()) // 0.36787

// special cases
println(exp(Float.NaN)) // NaN
println(exp(Float.POSITIVE_INFINITY)) // Infinity
println(exp(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

Требования к платформе и версии: JS (1.2), JVM (1.2)

actual inline fun exp(x: Double): Double

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Double.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0).firstFiveDigits()) // 2.71828
println(exp(2.0).firstFiveDigits()) // 7.38905
println(exp(-1.0).firstFiveDigits()) // 0.36787

// special cases
println(exp(Double.NaN)) // NaN
println(exp(Double.POSITIVE_INFINITY)) // Infinity
println(exp(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual inline fun exp(x: Float): Float

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Float.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0f).firstFiveDigits()) // 2.71828
println(exp(2.0f).firstFiveDigits()) // 7.38905
println(exp(-1.0f).firstFiveDigits()) // 0.36787

// special cases
println(exp(Float.NaN)) // NaN
println(exp(Float.POSITIVE_INFINITY)) // Infinity
println(exp(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

Требования к платформе и версии: Native (1.3)

actual external fun exp(x: Double): Double

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Double.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0).firstFiveDigits()) // 2.71828
println(exp(2.0).firstFiveDigits()) // 7.38905
println(exp(-1.0).firstFiveDigits()) // 0.36787

// special cases
println(exp(Double.NaN)) // NaN
println(exp(Double.POSITIVE_INFINITY)) // Infinity
println(exp(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual external fun exp(x: Float): Float

Вычисляет число Эйлера e в степени значения x.

Особые случаи:

  • exp(NaN) равно NaN

  • exp(+Inf) равно +Inf

  • exp(-Inf) равно 0.0

Примеры

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

fun main() { 
   //sampleStart 
   fun Float.firstFiveDigits(): String = toString().substring(0, 7)

println(exp(1.0f).firstFiveDigits()) // 2.71828
println(exp(2.0f).firstFiveDigits()) // 7.38905
println(exp(-1.0f).firstFiveDigits()) // 0.36787

// special cases
println(exp(Float.NaN)) // NaN
println(exp(Float.POSITIVE_INFINITY)) // Infinity
println(exp(Float.NEGATIVE_INFINITY)) // 0.0 
   //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.math/exp.html

Spec-Zone.ru

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