The asin()
function, also called the arc sine function, returns the inverse sine of a number. To be more specific, it returns the inverse sine of a number in radians.
The image below shows the mathematical representation of the asin()
function.
The
scala.math._
header file is required for this function.
To convert degrees to radians, use the formula below:
radians = degrees * ( Pi / 180 )
Double asin(Double number)
This function requires a number as a parameter. The parameter must be a double value between -1 and 1.
asin()
returns the inverse sine of the number (in radians) that is sent as a parameter. The return value lies in the interval [-pi/2, pi/2]
radians.
If the parameter value is an error value, i.e., greater than one or less than one, infinity, or NaN
, then asin()
returns NaN
.
import scala.math._object Main extends App {//positive number in radiansprintln(s"The value of asin(0.5) = ${asin(0.5)} Radians");// negative number in radiansprintln(s"The value of asin(-0.5) = ${asin(-0.5)} Radians");//applying asin() and then converting the result in radians to degrees// radians = 0.5// PI = 3.14159265println(s"The value of asin(0.5) = ${asin(0.5) * (180 / Pi)} Degrees");//error outputsprintln(s"The value of asin(Double.PositiveInfinity) = ${asin(Double.PositiveInfinity)}");println(s"The value of asin(Double.NegativeInfinity) = ${asin(Double.NegativeInfinity)}");println(s"The value of asin(Double.NaN) = ${asin(Double.NaN)}");println(s"The value of asin(2) = ${asin(2)}");println(s"The value of asin(-2) = ${asin(-2)}");}