The toDegrees()
function in Scala converts a radian value to degrees.
Figure 1 below shows a mathematical representation of the toDegrees()
function:
Following module is required for this function:
import scala.math._
Double toDegrees(Double number)
The toDegrees()
function takes a
The toDegrees()
function then converts the radian value sent as a parameter to degrees.
- If the parameter value is positive infinity, then it returns positive infinity.
- If the parameter value is negative infinity, then it returns negative infinity.
- If the parameter value is NaN, then it returns
NaN
.
The following code shows how to use toDegrees()
in scala.
import scala.math._object Main extends App {//piprintln(s"The value of toDegrees(Pi) = ${toDegrees(Pi)}");//pi/2println(s"The value of toDegrees(Pi/2) = ${toDegrees(Pi/2)}");//pi/4println(s"The value of toDegrees(Pi/4) = ${toDegrees(Pi/4)}");//0println(s"The value of toDegrees(0) = ${toDegrees(0)}");//-piprintln(s"The value of toDegrees(-Pi) = ${toDegrees(-Pi)}");//-pi/2println(s"The value of toDegrees(-Pi/2) = ${toDegrees(-Pi/2)}");//-pi/4println(s"The value of toDegrees(-Pi/4) = ${toDegrees(-Pi/4)}");//error outputsprintln(s"The value of toDegrees(Double.PositiveInfinity) = ${toDegrees(Double.PositiveInfinity)}");println(s"The value of toDegrees(Double.NegativeInfinity) = ${toDegrees(Double.NegativeInfinity)}");println(s"The value of toDegrees(Double.NaN) = ${toDegrees(Double.NaN)}");}