tan

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}
actual inline fun tan(x: Double): Double(source)

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}
actual inline fun tan(x: Double): Double(source)

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}
actual external fun tan(x: Double): Double(source)

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}
actual fun tan(x: Double): Double(source)

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}
actual fun tan(x: Double): Double(source)

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-10

println(tan(0.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI / 4) - 1.0).absoluteValue < epsilon is ${(tan(PI / 4) - 1.0).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI / 4) - -1.0).absoluteValue < epsilon is ${(tan(-PI / 4) - -1.0).absoluteValue < epsilon}") // true

// special cases
println(tan(Double.NaN)) // NaN
println(tan(Double.POSITIVE_INFINITY)) // NaN
println(tan(Double.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}

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

Computes the tangent of the angle x given in radians.

Special cases:

  • tan(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   val epsilon = 1e-6f

println(tan(0.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// tan(π/4) = 1.0
println("(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon is ${(tan(PI.toFloat() / 4) - 1.0f).absoluteValue < epsilon}") // true
// tan(-π/4) = -1.0
println("(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon is ${(tan(-PI.toFloat() / 4) - -1.0f).absoluteValue < epsilon}") // true

// special cases
println(tan(Float.NaN)) // NaN
println(tan(Float.POSITIVE_INFINITY)) // NaN
println(tan(Float.NEGATIVE_INFINITY)) // NaN 
   //sampleEnd
}