Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

perl
math
cosine
hyperbolic
communitycreator

What is cosh() in Perl?

harris910

The cosh() function calculates the hyperbolic cosine of a number in radians.

The following illustration shows the mathematical representation of the cosh() function.

Mathematical representation of hyperbolic cosine function

Syntax

cosh(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

This function returns the hyperbolic cosine of a number (in radians) sent as a parameter.

  • If the value of num is NaNnot a number then the return value is NaN.

  • If the value of num is positive/negative infinity, then the return value is positive infinity.

Code

#this header for deg2rad() function
use Math::Trig;

#Positive number in radians
$a = cosh(2.3);
print "cosh(2.3): $a \n";

#negative number in radians
$b = cosh(-2.3);
print "cosh(-2.3): $b \n";

#converting the degrees angle into radians and then applying cosh()
#degrees = 180
$rad = deg2rad(180);
$c = cosh($rad);
print "cosh($rad): $c \n";

#Inf values
$d = cosh(Inf);
print "cosh(Inf): $d \n";

$e = cosh(-Inf);
print "cosh(-Inf): $e \n";

#NaN value
$f = cosh(NaN);
print "cosh(NaN): $f \n";

RELATED TAGS

perl
math
cosine
hyperbolic
communitycreator
RELATED COURSES

View all Courses

Keep Exploring