What is Math.sinh() in Scala?

Share

The sinh() function returns the hyperbolic sine of a number. To be more specific, it returns the hyperbolic sine of a number in radians.

The figure below shows the mathematical representation of the sinh() function.

Figure 1: Mathematical representation of the hyperbolic sine function

The scala.math._ header file is required for this function.

Syntax

Double sinh(Double number)

Parameter

This function requires a number that represents an angle in radians as a parameter.

You can use the following formula to convert degrees to radians.

radians = degrees * ( Pi / 180 )

Return value

sinh() returns the hyperbolic sine of a numberin radians that is sent as a parameter.

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

Example

import scala.math._
object Main extends App {
//positive number in radians
println(s"The value of sinh(2.3) = ${sinh(2.3)}");
// negative number in radians
println(s"The value of sinh(-2.3) = ${sinh(-2.3)}");
//converting the degrees angle into radians and then applying sinh()
// degrees = 45.0
// PI = 3.14159265
// result first converts degrees to radians then apply sinh
println(s"The value of sinh(45.0) = ${sinh(45.0 * (Pi / 180.0))}");
//error outputs
println(s"The value of sinh(Double.PositiveInfinity) = ${sinh(Double.PositiveInfinity)}");
println(s"The value of sinh(Double.NegativeInfinity) = ${sinh(Double.NegativeInfinity)}");
println(s"The value of sinh(Double.NaN) = ${sinh(Double.NaN)}");
}