2.12. Calculating More Trigonometric FunctionsProblemYou want to calculate values for trigonometric functions like sine, tangent, or arc-cosine. Solution
Perl provides only
sub tan {
my $theta = shift;
return sin($theta)/cos($theta);
}
The POSIX module provides a wider range of trig functions: use POSIX; $y = acos(3.7); The Math::Trig module provides a complete set of functions and supports operations on or resulting in complex numbers: use Math::Trig; $y = acos(3.7); Discussion
The
eval {
$y = tan($pi/2);
} or return undef;
See Also
The ![]() Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|