The tan()
function in Perl calculates and returns the tangent of a number in radians.
The illustration below shows the mathematical representation of the tan()
function.
This
tan()
function only works for right-angled triangles.
tan(num)
This function requires a number that represents an angle in radians as a parameter.
To convert degrees to radians, use the following function in Perl.
deg2rad(angleInDegrees)
tan()
returns the tangent of a number that is set as a parameter.
NaN
.#this header for deg2rad() functionuse Math::Trig;#Positive number in radians$a = tan(2.3);print "tan(2.3): $a \n";#negative number in radians$b = tan(-2.3);print "tan(-2.3): $b \n";#converting the degrees angle into radians and then applying tan()#degrees = 45$rad = deg2rad(45);$c = tan($rad);print "tan($rad): $c \n";#infinite values$d = tan(Inf);print "tan(Inf): $d \n";$e = tan(-Inf);print "tan(-Inf): $e \n";#NaN value$f = tan(NaN);print "tan(NaN): $f \n";