-
The following is a list of the Perl numeric operators and an explanation of what they do.
Addition: "+" is plus.
For example, the line of code "4 + 5" returns 9.
Subtraction: "-" is minus.
For example, the line of code "11.3 - 4" returns 7.3.
Multiplication: "*" is times.
For example, the line of code "3 * 7" returns 21.
Division (floating point): "/" is divided by.
For example, the line of code "10 / 3" returns 3.33333....
Remainder: "%" is mod (returns the remainder after a number is divided by the divisor).
For example, the line of code "7 % 3" returns 1.
Exponents: "**" is to the power of.
For example, the line of code "2**3" returns 8. -
To find the square root of x: returnValue = sqrt (x);
To find the absolute value of x: returnValue = abs (x);
To find the natural (base e) logarithm of the x: returnValue = log (x); -
To find the sine of x (in radians): returnValue = sin (x);
To find the cosine of x (in radians): returnValue = cos (x); -
Additional math functions not provided by the basic Perl language can be imported from the Math::Trig module. To use this module, insert the following code into the beginning of your Perl program (just after #!/usr/bin/perl):
use Math::Trig; -
tan(x)--returns the tangent of x
acos(x)--returns the inverse cosine of x
asin(x)--returns the inverse sine of x
pi--returns the value of pi
deg2rad(x--converts the value of x (degrees) into radians
For example, the following code:
$returnValue = pi;
Results in:
The value of returnValue is equal to pi. -
The following functions are used to perform conversions between degrees, radians and gradians. (Note: A full circle = 2 pi radians = 360 degrees = 400 gradians.)
deg2rad(x)--converts the value of x (degrees) into radians
grad2rad(x)--converts the value of x (gradians) to radians
rad2deg(x)--converts the value of x (radians) to degrees
grad2deg(x)--converts the value of x (gradians) into degrees
deg2grad(x)--converts the value of x (degrees) into gradians
rad2grad(x)--converts the value of x (radians) to gradians










