The tanh()
function returns the hyperbolic tangent of a number. To be more specific, it returns the hyperbolic tangent of a number in radians
.
Figure 1 shows the mathematical representation of the tanh()
function.
The
scala.math._
header file is required for this function.
Double tanh(Double number)
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 )
tanh()
returns the
- If the parameter value is positive infinity, then it returns 1.
- If the parameter value is negative infinity, then it returns -1.
- If the parameter value is NaN, then it returns NaN.
import scala.math._object Main extends App {//positive number in radiansprintln(s"The value of tanh(2.3) = ${tanh(2.3)}");// negative number in radiansprintln(s"The value of tanh(-2.3) = ${tanh(-2.3)}");//converting the degrees angle into radians and then applying tanh()// degrees = 45.0// PI = 3.14159265// result first converts degrees to radians then apply tanhprintln(s"The value of tanh(45.0) = ${tanh(45.0 * (Pi / 180.0))}");//error outputsprintln(s"The value of tanh(Double.PositiveInfinity) = ${tanh(Double.PositiveInfinity)}");println(s"The value of tanh(Double.NegativeInfinity) = ${tanh(Double.NegativeInfinity)}");println(s"The value of tanh(Double.NaN) = ${tanh(Double.NaN)}");}