What is Math.toRadians() in Scala?

The toRadians() function in Scala converts a value in degrees to an equal value in radians.

The image below shows the mathematical representation of the toRadians() function.

Mathematical representation of the toRadians() function

The following module is required for this function:

import scala.math._

Syntax


Double toRadians(Double number)

Parameters

The toRadians() function takes a numberdegree value as a parameter.

Return value

The toRadians() function converts the degree value sent as a parameter to a value in radians.

  • If the parameter value is PositiveInfinity, then toRadians() returns positive infinity.
  • If the parameter value is NegativeInfinity, then toRadians() returns negative infinity.
  • If the parameter value is NaN, then toRadians() returns NaN.

Code

import scala.math._
object Main extends App {
//The radians value of 180
println(s"The value of toRadians(180) = ${toRadians(180)}");
//The radians value of 0
println(s"The value of toRadians(0) = ${toRadians(0)}");
//The radians value of -180
println(s"The value of toRadians(-180) = ${toRadians(-180)}");
//Error output ~ The radians value of Infinity
println(s"The value of toRadians(Double.PositiveInfinity) = ${toRadians(Double.PositiveInfinity)}");
//Error output ~ The radians value of -Infinity
println(s"The value of toRadians(Double.NegativeInfinity) = ${toRadians(Double.NegativeInfinity)}");
//Error output ~ The radians value of NaN
println(s"The value of toRadians(Double.NaN) = ${toRadians(Double.NaN)}");
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources