Perl Newbies

  1. Perl
  2. Functions
  3. here

cos function - calculate the cosine value

cos function calculates the cosine value. The angle is specified by arc degree method using π (pi function).

use Math::Trig 'pi';

cos(pi/3);

The pi function is defined in Math::Trig module.

cos function programming example

The following is a cos function programming example.

use strict;
use warnings;
use Math::Trig 'pi';

# cos(60°) = 1/2;
print "cos(π/3) = " . cos(pi/3) . "\n";

Other trigonometric functions

Perl also has sin function in core functions.

The following article explains how to use other trigonometric functions such as tangent.

Menu