A collection of common operations on integer numbers.
Most operations make no assumption on the precision of integers.
Operation bitNot is necessarily an exception.
Author: Sergio Antoy
Version: March 20, 2006
| Exported names: |
Functions:
abs
| binomial
| bitAnd
| bitNot
| bitOr
| bitTrunc
| bitXor
| even
| factorial
| ilog
| isqrt
| max3
| maxlist
| min3
| minlist
| odd
| pow
| Summary of exported functions: |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
| Imported modules: |
| Exported datatypes: |
| Exported functions: |
:: Int -> Int -> Int
The value of pow a b is a
raised to the power of b.
Fails if b < 0.
Executes in O(log b) steps.
Example call: (pow a b)
a
- The base.
b
- The exponent.
:: Int -> Int
The value of ilog n is the floor of the logarithm
in the base 10 of n.
Fails if n <= 0.
For positive integers, the returned value is
1 less the number of digits in the decimal representation of n.
Example call: (ilog n)
n
- The argument.
:: Int -> Int
The value of isqrt n is the floor
of the square root of n.
Fails if n < 0.
Executes in O(log n) steps, but there must be a better way.
Example call: (isqrt n)
n
- The argument.
:: Int -> Int
The value of factorial n is the factorial of n.
Fails if n < 0.
Example call: (factorial n)
n
- The argument.
:: Int -> Int -> Int
The value of binomial n m is
n*(n-1)*...*(n-m+1)/m*(m-1)*...1
Fails if m <= 0 or n < m.
Example call: (binomial n m)
n
- Argument.
m
- Argument.
:: Int -> Int
The value of abs n is the absolute value of n.
Example call: (abs n)
n
- The argument.
:: a -> a -> a -> a
Returns the maximum of the three arguments.
Example call: (max3 n m p)
n
- Argument.
m
- Argument.
p
- Argument.
:: a -> a -> a -> a
Returns the minimum of the three arguments.
Example call: (min3 n m p)
n
- Argument.
m
- Argument.
p
- Argument.
:: [a] -> a
Returns the maximum of a list of integer values.
Fails if the list is empty.
Example call: (maxlist l)
l
- The list of values.
:: [a] -> a
Returns the minimum of a list of integer values.
Fails if the list is empty.
Example call: (minlist l)
l
- The list of values.
:: Int -> Int -> Int
The value of bitTrunc n m is the value of the n
least significant bits of m.
Example call: (bitTrunc n m)
n
- Argument.
m
- Argument.
:: Int -> Int -> Int
Returns the bitwise AND of the two arguments.
Example call: (bitAnd n m)
n
- Argument.
m
- Argument.
:: Int -> Int -> Int
Returns the bitwise inclusive OR of the two arguments.
Example call: (bitOr n m)
n
- Argument.
m
- Argument.
:: Int -> Int
Returns the bitwise NOT of the argument.
Since integers have unlimited precision,
only the 32 least significant bits are computed.
Example call: (bitNot n)
n
- Argument.
:: Int -> Int -> Int
Returns the bitwise exclusive OR of the two arguments.
Example call: (bitXor n m)
n
- Argument.
m
- Argument.
:: Int -> Bool
Returns whether an integer is even
Example call: (even n)
n
- Argument.
:: Int -> Bool
Returns whether an integer is odd
Example call: (odd n)
n
- Argument.