< Perl Programming < Keywords

The code
prints the cosine of the angle of 30 degrees:
The cos keyword
cos is the trigonometric function cose that assumes that X is in radians.
Syntax
cos(X)
Examples

*PI = \3.1415926535;
$a = 30; # in degrees
$cos = cos($a/180*$PI);
print "cos(" . $a . "°) = " . $cos . "\n";
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.