MAN page from Old RedHat 5.X perl-5.004-4.i386.rpm
Math::Trig
Section: Perl Programmers Reference Guide (3)
Updated: perl 5.004, patch 04
Index NAME
Math::Trig - trigonometric functions
SYNOPSIS
use Math::Trig; $x = tan(0.9); $y = acos(3.7); $z = asin(2.4); $halfpi = pi/2;
$rad = deg2rad(120);
DESCRIPTION
Math::Trig defines many trigonometric functions not defined by thecore Perl which defines only the
sin() and
cos(). The constant
pi is also defined as are a few convenience functions for angleconversions.
TRIGONOMETRIC FUNCTIONS
The tangent
tan
The cofunctions of the sine, cosine, and tangent (cosec/csc and cotan/cotare aliases)
csc cosec 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/acscand acotan/acot are aliases)
acsc acosec asec acot acotan
The hyperbolic sine, cosine, and tangent
sinh cosh tanh
The cofunctions of the hyperbolic sine, cosine, and tangent (cosech/cschand cotanh/coth are aliases)
csch cosech sech coth cotanh
The arcus (also known as the inverse) functions of the hyperbolicsine, cosine, and tangent
asinh acosh atanh
The arcus cofunctions of the hyperbolic sine, cosine, and tangent(acsch/acosech and acoth/acotanh are aliases)
acsch acosech asech acoth acotanh
The trigonometric constant
pi is also defined.
$pi2 = 2 * pi;
ERRORS DUE TO DIVISION BY ZERO
The following functions
tan sec csc cot asec acsc tanh sech csch coth atanh asech acsch acoth
cannot be computed for all arguments because that would mean dividingby zero or taking logarithm of zero. These situations cause fatalruntime 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.
SIMPLE (REAL) ARGUMENTS, COMPLEX RESULTS
Please note that some of the trigonometric functions can break outfrom the
real axis into the
complex plane. For example
asin(2) has no definition for plain real numbers but it hasdefinition for complex numbers.
In Perl terms this means that supplying the usual Perl numbers (alsoknown as scalars, please see the perldata manpage) as input for thetrigonometric functions might produce as output results that no moreare simple real numbers: instead they are complex numbers.
The Math::Trig handles this by using the Math::Complex packagewhich knows how to handle complex numbers, please see the Math::Complex manpagefor more information. In practice you need not to worry about gettingcomplex numbers as results because the Math::Complex takes care ofdetails 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.571and the imaginary part of approximately
-1.317.
ANGLE CONVERSIONS
(Plane, 2-dimensional) angles may be converted with the following functions.
$radians = deg2rad($degrees); $radians = grad2rad($gradians); $degrees = rad2deg($radians); $degrees = grad2deg($gradians); $gradians = deg2grad($degrees); $gradians = rad2grad($radians);
The full circle is 2
pi radians or
360 degrees or
400 gradians.
BUGS
Saying
use Math::Trig; exports many mathematical routines in thecaller environment and even overrides some (
sin,
cos). This isconstrued as a feature by the Authors, actually... ;-)
The code is not optimized for speed, especially because we useMath::Complex and thus go quite near complex numbers while doingthe computations even when the arguments are not. This, however,cannot be completely avoided if we want things like asin(2) to givean answer instead of giving a fatal runtime error.
AUTHORS
Jarkko Hietaniemi <
jhiAATTiki.fi> and Raphael Manfredi <
Raphael_ManfrediAATTgrenoble.hp.com>.
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- TRIGONOMETRIC FUNCTIONS
- ERRORS DUE TO DIVISION BY ZERO
- SIMPLE (REAL) ARGUMENTS, COMPLEX RESULTS
- ANGLE CONVERSIONS
- BUGS
- AUTHORS
This document was created byman2html,using the manual pages.