The tanh()
function in Perl returns a number’s hyperbolic tangent in radians.
The following illustration shows the mathematical representation of the tanh()
function.
tanh(num)
This function requires a number that represents an angle in radians as a parameter.
To convert degrees to radians, use the following function in Perl.
deg2rad(angleInDegrees)
tanh()
returns the hyperbolic tangent of a number (in radians) that is sent as a parameter.
num
is NaN
.num
is positive infinity, then the returned value is 1
.num
is negative infinity, then the returned value is -1
.#this header for deg2rad() functionuse Math::Trig;#Positive number in radians$a = tanh(2.3);print "tanh(2.3): $a \n";#negative number in radians$b = tanh(-2.3);print "tanh(-2.3): $b \n";#converting the degrees angle into radians and then applying tanh()#degrees = 45$rad = deg2rad(45);$c = tanh($rad);print "tanh($rad): $c \n";#Inf values$d = tanh(Inf);print "tanh(Inf): $d \n";$e = tanh(-Inf);print "tanh(-Inf): $e \n";#NaN value$f = tanh(NaN);print "tanh(NaN): $f \n";