Math::Trig - trigonometric functions
use Math::Trig;
$x = tan(0.9);
$y = acos(3.7);
$z = asin(2.4);
$halfpi = pi/2;
$rad = deg2rad(120);
# Import constants pi2, pip2, pip4 (2*pi, pi/2, pi/4).
use Math::Trig ':pi';
# Import the conversions between cartesian/spherical/cylindrical.
use Math::Trig ':radial';
# Import the great circle formulas.
use Math::Trig ':great_circle';
Math::Trig defines many trigonometric functions not defined by the core Perl which defines only the sin() and cos(). The constant pi is also defined as are a few convenience functions for angle conversions, and great circle formulas for spherical movement.
The tangent
The cofunctions of the sine, cosine, and tangent (cosec/csc and cotan/cot are aliases)
csc, cosec, sec, sec, cot, cotan
The arcus (also known as the inverse) functions of the sine, cosine, and tangent
asin, acos, atan
The principal value of the arc tangent of y/x
atan2(y, x)
The arcus cofunctions of the sine, cosine, and tangent (acosec/acsc and acotan/acot are aliases). Note that atan2(0, 0) is not well-defined.
acsc, acosec, asec, acot, acotan
The hyperbolic sine, cosine, and tangent
sinh, cosh, tanh
The cofunctions of the hyperbolic sine, cosine, and tangent (cosech/csch and cotanh/coth are aliases)
csch, cosech, sech, coth, cotanh
The area (also known as the inverse) functions of the hyperbolic sine, cosine, and tangent
asinh, acosh, atanh
The area cofunctions of the hyperbolic sine, cosine, and tangent (acsch/acosech and acoth/acotanh are aliases)
acsch, acosech, asech, acoth, acotanh
The trigonometric constant pi and some of handy multiples of it are also defined.
pi, pi2, pi4, pip2, pip4
The following functions
acoth
acsc
acsch
asec
asech
atanh
cot
coth
csc
csch
sec
sech
tan
tanh
cannot be computed for all arguments because that would mean dividing by zero or taking logarithm of zero. These situations cause fatal runtime errors looking like this
cot(0): Division by zero.
(Because in the definition of cot(0), the divisor sin(0) is 0)
Died at ...
or
atanh(-1): Logarithm of zero.
Died at...
For the csc, cot, asec, acsc, acot, csch, coth, asech, acsch, the argument cannot be 0 (zero). For the atanh, acoth, the argument cannot be 1 (one). For the atanh, acoth, the argument cannot be -1 (minus one). For the tan, sec, tanh, sech, the argument cannot be pi/2 + k * pi, where k is any integer.
Note that atan2(0, 0) is not well-defined.
Please note that some of the trigonometric functions can break out from the real axis into the complex plane. For example asin(2) has no definition for plain real numbers but it has definition for complex numbers.
In Perl terms this means that supplying the usual Perl numbers (also known as scalars, please see perldata) as input for the trigonometric functions might produce as output results that no more are simple real numbers: instead they are complex numbers.
The Math::Trig handles this by using the Math::Complex package which knows how to handle complex numbers, please see Math::Complex for more information. In practice you need not to worry about getting complex numbers as results because the Math::Complex takes care of details like for example how to display complex numbers. For example:
print asin(2), "\n";
should produce something like this (take or leave few last decimals):
1.5707963267949-1.31695789692482i
That is, a complex number with the real part of approximately 1.571 and the imaginary part of approximately -1.317.