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

117 Views Asked by At

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
2

There are 2 best solutions below

1
On BEST ANSWER

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
0
On

Because atan2 is a builtin function, like sin or cos. Or print.