expm1

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

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce a more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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
}
actual inline fun expm1(x: Double): Double(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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
}
actual inline fun expm1(x: Double): Double(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.2

See also

function.

function.

Samples

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
}
actual external fun expm1(x: Double): Double(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.3

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.3

See also

function.

function.

Samples

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
}
actual fun expm1(x: Double): Double(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.8

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.8

See also

function.

function.

Samples

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
}
actual fun expm1(x: Double): Double(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.8

See also

function.

function.

Samples

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(source)

Computes exp(x) - 1.

This function can be implemented to produce more precise result for x near zero.

Special cases:

  • expm1(NaN) is NaN

  • expm1(+Inf) is +Inf

  • expm1(-Inf) is -1.0

Since Kotlin

1.8

See also

function.

function.

Samples

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
}