NAME

Math - constants and functions

SYNOPSIS

use Math;

printf "2.71828182845905 = %s\n", E;
printf "1.5707963267949  = %s\n", PI1_2;

printf "1 = %s\n", round(0.5);
printf "1 = %s\n", ceil(0.5);
printf "0 = %s\n", floor(0.5);

or 

use Math ();

printf "%s\n", Math::PI;
printf "%s\n", Math::round(0.5);

SEE ALSO

perlfunc

POSIX

Math::Complex, Math::Trig, Math::Quaternion

Math::Color, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

Constants

E

Euler's constant, e, approximately 2.718

LN10

Natural logarithm of 10, approximately 2.302

LN2

Natural logarithm of 2, approximately 0.693

PI

Ratio of the circumference of a circle to its diameter, approximately 3.1415

PI1_4

L</PI> * 1/4

PI1_2

L</PI> * 1/2

PI2

L</PI> * 2

SQRT1_2

square root of 1/2, approximately 0.707

SQRT2

square root of 2, approximately 1.414

Functions

Note number, number1, number2, base, and exponent indicate any expression with a scalar value.

abs(number)

Returns the absolute value of number

acos(number)

Returns the arc cosine (in radians) of number

asin(number)

Returns the arc sine (in radians) of number

atan(number)

Returns the arc tangent (in radians) of number

ceil(number)

Returns the least integer greater than or equal to number

cos(number)

Returns the cosine of number where number is expressed in radians

exp(number)

Returns e, to the power of number (i.e. enumber)

even(number)

Returns 1 if number is even otherwise 0

floor(number)

Returns the greatest integer less than or equal to its argument

log(number)

Returns the natural logarithm (base e) of number

log10(number)

Returns the logarithm (base 10) of number

min(number1, number2)

Returns the lesser of number1 and number2

max(number1, number2)

Returns the greater of number1 and number2

minmax(min, number, max)

minmax(number, min, max)

Returns number between or equal min and max

odd(number)

Returns 1 if number is odd otherwise 0

pow(base, exponent)

Returns base to the exponent power (i.e. base exponent)

$base ** $exponent == pow($base, $exponent);

pro(number, number1, number2, ...)

Returns the product of its arguments

pro(1,2,3) == 1 * 2 * 3;
my $product = pro(@array);

random()

Returns a pseudo-random number between 0 and 1.

random(number)

Returns a pseudo-random number between 0 and number.

random(number1, number2)

Returns a pseudo-random number between number1 and number2.

round(number)

Returns the value of number rounded to the nearest integer

round(number1, digits)

round(0.123456, 2) == 0.12;

round(50, -2)   == 100;
round(5, -1)    == 10;
round(0.5)      == 1;
round(0.05, 1)  == 0.1;
round(0.005, 2) == 0.01;

sig(number)

Returns 1 if number is greater 0 otherwise -1

sin(number)

Returns the sine of number where number is expressed in radians

sqrt(number)

Returns the square root of its argument

sum(number, number1, number2, ...)

Returns the sum of its arguments

sum(1..3) == 1 + 2 + 3;
my $sum = sum(@array);

tan(number)

Returns the tangent of number, where number is expressed in radians

SEE ALSO

perlfunc

POSIX

Math::Complex, Math::Trig, Math::Quaternion

Math::Color, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

BUGS & SUGGESTIONS

If you run into a miscalculation, need some sort of feature or an additional holiday, or if you know of any new changes to the funky math, please drop the author a note.

ARRANGED BY

Holger Seelig  E<holger.seelig@yahoo.de>

COPYRIGHT

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.