What is atan() in Perl?

The atan() function (also called the arc tangent function) returns the inverse tangent of a number.

To be more specific, it returns the inverse tangent of a number in radians.

Figure 1 below shows the mathematical representation of the atan() function.

Figure 1: Mathematical representation of inverse tangent function

Figure 2 shows the visual representation of the atan() function.

Figure 2: Visual representation of inverse tangent function

Methodology

To convert radians to degrees, use the following function.


rad2deg(angleInRadians)

Syntax


atan(num)

Parameter

This function requires a number as a parameter.

Return value

atan() will return the inverse tangent of a number (in radians) that is sent as a parameter.

The return value lies in the interval of [-pi/2,pi/2] radians.

Code

#this header for rad2deg() function
use Math::Trig;
#Positive number in radians
$a = atan(0.5);
print "atan(0.5): $a Radians\n";
#negative number in radians
$b = atan(-0.5);
print "atan(-0.5): $b Radians\n";
#applying atan() and then converting the result in radians to degrees
#radians = 1.0
$c = rad2deg(atan(1.0));
print "atan(1.0): $c Degrees\n";

Free Resources