NAME
Weed::Math - constants and functions
SYNOPSIS
use Weed::Math ':all';
use Weed::Math ':constants';
use Weed::Math ':functions';
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", X3DMath::PI;
printf "%s\n", X3DMath::round(0.5);
SEE ALSO
perlfunc Perl built-in functions
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 or atan2( 0, -1 ).
PI1_2 == PI * 1/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
atan2(number1, number2)
perls atan2
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
fmod(number, number)
POSIX fmod
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
clamp(number, min, max)
Returns number between or equal min and max
odd(number)
Returns 1 if number is odd otherwise 0
pro(number, number1, number2, ...)
Returns the product of its arguments
pro(1,2,3) == 1 * 2 * 3;
my $product = pro(@array);
pow
Computes $x raised to the power $exponent .
$ret = POSIX::pow( $x, $exponent );
You can also use the ** operator, see perlop.
random
Returns a pseudo-random number between 0 and 1.
$ret = random();
Returns a pseudo-random number between 0 and $number1.
$ret = random($number1);
Returns a pseudo-random number between number1 and number2.
$ret = random($number1, $number2);
round
Returns the value of $number rounded to the nearest integer
$ret = round($number);
Returns the value of $number rounded to the nearest float point number.
$ret = round($number, $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.
Returns -1 if number is lesser 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
x(number, base=10)
Returns the digital_root of number to base
SEE ALSO
perlfunc Perl built-in functions
BUGS & SUGGESTIONS
If you run into a miscalculation please drop the author a note.
ARRANGED BY
HOOO@cpan.org
COPYRIGHT
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.