The atan()
function, also called the arc tangent function, returns the inverse tangent of a number. To be more specific, it returns the inverse tangent of a number in radians.
The image below shows the mathematical representation of the atan()
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 atan(Double number)
This function requires a number as a parameter.
atan()
returns the inverse tangent 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 NaN
, then atan()
returns NaN
.
import scala.math._object Main extends App {//positive number in radiansprintln(s"The value of atan(0.5) = ${atan(0.5)} Radians");println(s"The value of atan(2) = ${atan(2)} Radians");println(s"The value of atan(Double.PositiveInfinity) = ${atan(Double.PositiveInfinity)} Radians");// negative number in radiansprintln(s"The value of atan(-0.5) = ${atan(-0.5)} Radians");println(s"The value of atan(-2) = ${atan(-2)} Radians");println(s"The value of atan(Double.NegativeInfinity) = ${atan(Double.NegativeInfinity)} Radians");//applying atan() and then converting the result in radians to degrees// radians = 1.0// PI = 3.14159265println(s"The value of atan(1) = ${atan(1) * (180 / Pi)} Degrees");//error outputsprintln(s"The value of atan(Double.NaN) = ${atan(Double.NaN)}");}