Spec-Zone.ru › Kotlin 2

expm1

kotlin-stdlib/kotlin.math/expm1

Платформы и требования к версии: Common (1.2)

expect fun expm1(x: Double): Double

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17) - 1.0) // 0.0
println(expm1(1e-17)) // 1e-17.toString()

// special cases
println(expm1(Double.NaN)) // NaN
println(expm1(Double.POSITIVE_INFINITY)) // Infinity
println(expm1(Double.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

expect fun expm1(x: Float): Float

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0f).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17f) - 1.0f) // 0.0
println(expm1(1e-17f)) // 1e-17f.toString()

// special cases
println(expm1(Float.NaN)) // NaN
println(expm1(Float.POSITIVE_INFINITY)) // Infinity
println(expm1(Float.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

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

actual inline fun expm1(x: Double): Double

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17) - 1.0) // 0.0
println(expm1(1e-17)) // 1e-17.toString()

// special cases
println(expm1(Double.NaN)) // NaN
println(expm1(Double.POSITIVE_INFINITY)) // Infinity
println(expm1(Double.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

actual inline fun expm1(x: Float): Float

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0f).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17f) - 1.0f) // 0.0
println(expm1(1e-17f)) // 1e-17f.toString()

// special cases
println(expm1(Float.NaN)) // NaN
println(expm1(Float.POSITIVE_INFINITY)) // Infinity
println(expm1(Float.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

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

actual external fun expm1(x: Double): Double

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17) - 1.0) // 0.0
println(expm1(1e-17)) // 1e-17.toString()

// special cases
println(expm1(Double.NaN)) // NaN
println(expm1(Double.POSITIVE_INFINITY)) // Infinity
println(expm1(Double.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

actual external fun expm1(x: Float): Float

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0f).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17f) - 1.0f) // 0.0
println(expm1(1e-17f)) // 1e-17f.toString()

// special cases
println(expm1(Float.NaN)) // NaN
println(expm1(Float.POSITIVE_INFINITY)) // Infinity
println(expm1(Float.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

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

actual fun expm1(x: Double): Double

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17) - 1.0) // 0.0
println(expm1(1e-17)) // 1e-17.toString()

// special cases
println(expm1(Double.NaN)) // NaN
println(expm1(Double.POSITIVE_INFINITY)) // Infinity
println(expm1(Double.NEGATIVE_INFINITY)) // -1.0 
   //sampleEnd
}

actual fun expm1(x: Float): Float

Вычисляет exp(x) - 1.

Эту функцию можно реализовать так, чтобы получать более точный результат для x вблизи нуля.

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

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

См. также

exp

функция.

ln1p

функция.

Примеры

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

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

println(expm1(1.0f).firstFiveDigits()) // 1.71828
// While it does not really matter for relatively large x values (like 1.0),
// the difference is getting more pronounced when x is getting closer to 0.0
println(exp(1e-17f) - 1.0f) // 0.0
println(expm1(1e-17f)) // 1e-17f.toString()

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

Spec-Zone.ru

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