February 2012
Intermediate to advanced
1184 pages
37h 17m
English
cos EXPR
cosThis function returns the cosine of
EXPR (expressed in radians). For example, the
following script will print a cosine table of angles measured in
degrees:
# Here's the lazy way of getting degrees–to–radians
$pi = atan2(1,1) * 4;
$pi_over_180 = $pi/180;
# Print table
for ($deg = 0; $deg <= 90; $deg++) {
printf "%3d %7.5f\n", $deg, cos($deg * $pi_over_180);
}For the inverse cosine operation, use the acos function from the Math::Trig or POSIX modules, or else use this relation:
sub acos { atan2( sqrt(1 – $_[0] * $_[0]), $_[0] ) }Read now
Unlock full access