Perl Math - atan() Function

The Perl Math atan() function returns arc tangent of a value. The returned value will be in the range -𝜋/2 through 𝜋/2. In special cases it returns the following:

• If the argument is NaN, then the result is NaN.

atan(x)

Parameters

 x Specify the value.

Return Value

Returns the arc tangent of the value.

Example:

In the example below, atan() function is used to find out the arc tangent of a given value.

use Math::Trig;

print("atan(-2) = ".atan(-2)."\n");
print("atan(-1) = ".atan(-1)."\n");
print("atan(0) = ".atan(0)."\n");
print("atan(1) = ".atan(1)."\n");
print("atan(2) = ".atan(2)."\n");
print("atan(NaN) = ".atan(NaN)."\n");

The output of the above code will be:

atan(-2) = -1.10714871779409
atan(-1) = -0.785398163397448
atan(0) = 0
atan(1) = 0.785398163397448
atan(2) = 1.10714871779409
atan(NaN) = NaN

This function can also be used to calculate arc tangent of a complex number z. It is a function on complex plane, and has two branch cuts:

• Extends from 1i along the imaginary axis to ∞i, continuous from the right.
• Extends from -1i along the imaginary axis to -∞i, continuous from the left.

Mathematically, it can be expressed as: Example:

In the example below, atan() function is used to find out the complex arc tangent of a given complex number.

use Math::Complex;

\$z1 = 2 + 2*i;
\$z2 = 2;
\$z3 = 2*i;
print("atan(\$z1) = ".atan(\$z1)."\n");
print("atan(\$z2) = ".atan(\$z2)."\n");
print("atan(\$z3) = ".atan(\$z3)."\n");

The output of the above code will be:

atan(2+2i) = 1.31122326967164+0.238877861256859i
atan(2) = 1.10714871779409
atan(2i) = -1.5707963267949+0.549306144334055i

❮ Perl Math Functions

5