What is tanh() in Perl?
The tanh() function in Perl returns a number’s hyperbolic tangent in radians.
The following illustration shows the mathematical representation of the tanh() function.
Syntax
tanh(num)
Parameter
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)
Return value
tanh() returns the hyperbolic tangent of a number (in radians) that is sent as a parameter.
- If the value of
numis , then the returned value isNaN not a number NaN. - If the value of
numis positive infinity, then the returned value is1. - If the value of
numis negative infinity, then the returned value is-1.
Code
#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";