MDK::Common::Math - miscellaneous math functions
use MDK::Common::Math qw(:all);
the well-known constant
is the number even or odd?
sqr(3) gives 9
sqr(3)
9
returns a value in { -1, 0, 1 }
round(1.2) gives 1, round(1.6) gives 2
round(1.2)
1
round(1.6)
2
returns the number rounded up to the modulo: round_up(11,10) gives 20
round_up(11,10)
20
returns the number rounded down to the modulo: round_down(11,10) gives 10
round_down(11,10)
10
integer division (which is lacking in perl). In array context, also returns the remainder: ($a, $b) = divide(10,3) gives $a is 3 and $b is 1
($a, $b) = divide(10,3)
$a is 3
$b is 1
returns the minimum/maximum number in the list
is there a true value in the list?
are all values true in the list?
returns the sum/product of all the element in the list
factorial(4) gives 24 (4*3*2)
factorial(4)
24
the following functions are provided, but not exported:
factorize(40) gives ([2,3], [5,1]) as 40 = 2^3 + 5^1
factorize(40)
([2,3], [5,1])
decimal2fraction(1.3333333333) gives (4, 3) ($PRECISION is used to decide which precision to use)
decimal2fraction(1.3333333333)
(4, 3)
Solves the a*x2+b*x+c=0 polynomial: poly2(1,0,-1) gives (1, -1)
poly2(1,0,-1)
(1, -1)
A(n,p)
C(n,p)
MDK::Common
To install MDK::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MDK::Common
CPAN shell
perl -MCPAN -e shell install MDK::Common
For more information on module installation, please visit the detailed CPAN module installation guide.