Scala Tutorial Scala References

Scala - Math asin() Method



The Scala Math asin() method returns arc sine of a value. The return value will be in the range -𝜋/2 through 𝜋/2. In special cases it returns the following:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

Note: asin() is the inverse of sin().

Syntax

def asin(x: Double): Double = scala.lang.Math.asin(x)

Parameters

x Specify the value.

Return Value

Returns the arc sine of the value.

Exception

NA.

Example:

In the example below, asin() method is used to find out the arc sine of a given value.

import scala.math._

object MainObject {
  def main(args: Array[String]) {
    println(s"asin(-1) = ${asin(-1)}");   
    println(s"asin(0.5) = ${asin(0.5)}"); 
    println(s"asin(0) = ${asin(0)}"); 
    println(s"asin(0.5) = ${asin(0.5)}");
    println(s"asin(1) = ${asin(1)}");
    println(s"asin(Double.NaN) = ${asin(Double.NaN)}"); 
    println(s"asin(2) = ${asin(2)}");
    println("asin(Double.PositiveInfinity) = "
            + asin(Double.PositiveInfinity));
  }
}

The output of the above code will be:

asin(-1) = -1.5707963267948966
asin(0.5) = 0.5235987755982989
asin(0) = 0.0
asin(0.5) = 0.5235987755982989
asin(1) = 1.5707963267948966
asin(Double.NaN) = NaN
asin(2) = NaN
asin(Double.PositiveInfinity) = NaN

❮ Scala - Math Methods

5