perlperl-core

Why do I not have to use "use Math::Trig" for atan2 and the like?


Why don't I have to use use Math::Trig; in my Perl program to call atan2()?

According to documentation, atan2() is not part of the "Perl Core".

I have Perl 5.18.4. I looked at the list of standard Perl modules, and I DO see Math::Trig listed, but I still thought that the "use" statement was required. Admittedly, my Perl knowledge is only about 6 months old at this point. So, a simple answer would be a quote from an official Perl document. Or, maybe there is something else going on here that I don't understand.

Here is an example of what I am talking about.

#!/usr/bin/perl
use strict;
use warnings;
$value = atan2(1, 1) * 4;
print "$value\n";

Output:

  3.14159265358979

Solution

  • You don't need to use Math::Trig; because atan2 is a built-in function. You can also see this from your command line:

    perldoc -f atan2