Scala Tutorial Scala References

Scala - Math sinh() Method



The Scala Math sinh() method returns hyperbolic sine of a value. The hyperbolic sine of x is defined as:

sinh

where e is an Euler's number.

In special cases it returns the following:

  • If the argument is NaN, then the result is NaN.
  • If the argument is positive infinity, then the result is Infinity.
  • If the argument is negative infinity, then the result is -Infinity.
  • If the argument is zero, then the result is a zero.

Syntax

def sinh(x: Double): Double = scala.lang.Math.sinh(x)

Parameters

x Specify the value.

Return Value

Returns the hyperbolic sine of a value.

Exception

NA.

Example:

In the example below, sinh() method is used to find out the hyperbolic sine of a value.

import scala.math._

object MainObject {
  def main(args: Array[String]) {
    println(s"sinh(-1) = ${sinh(-1)}");   
    println(s"sinh(0) = ${sinh(0)}"); 
    println(s"sinh(1) = ${sinh(1)}"); 
    println(s"sinh(2) = ${sinh(2)}"); 
    println(s"sinh(Double.NaN) = ${sinh(Double.NaN)}"); 
    println("sinh(Double.PositiveInfinity) = "
            + sinh(Double.PositiveInfinity));
    println("sinh(Double.NegativeInfinity) = "
            + sinh(Double.NegativeInfinity));
  }
}

The output of the above code will be:

sinh(-1) = -1.1752011936438014
sinh(0) = 0.0
sinh(1) = 1.1752011936438014
sinh(2) = 3.626860407847019
sinh(Double.NaN) = NaN
sinh(Double.PositiveInfinity) = Infinity
sinh(Double.NegativeInfinity) = -Infinity

❮ Scala - Math Methods