module BatNumber:sig
..end
A common interface for numbers.
exception Overflow
Arithmetic overflow.
This kind of exception is raised by "safe" numeric modules whenever the number which should be returned is too large to be represented.
Non-"safe" numeric modules will return a result which depends on
the internal representation. For instance, with module Int
,
max_num + 1
returns min_num
. By opposition, with module
Safe_int
, max_num + 1
raises Overflow
.
exception NaN
Not a Number
This kind of exception is raised by "safe" modules whenever the number which should be returned is not a number.
For instance, with module Safe_float
, 0.0 / 0.0
raises NaN
.
By opposition, with module Float
, 0.0 / 0.0
does not interrupt
computation and returns a special value nan
.
type 'a
numeric = {
|
zero : |
|
one : |
|
neg : |
|
succ : |
|
pred : |
|
abs : |
|
add : |
|
sub : |
|
mul : |
|
div : |
|
modulo : |
|
pow : |
|
compare : |
|
of_int : |
|
to_int : |
|
of_string : |
|
to_string : |
|
of_float : |
|
to_float : |
}
The smallest set of operations supported by every set of numbers.
This is presented as record to permit lightweight typeclass-style computation.
module type Infix =sig
..end
The infix operators available with any type of numbers
module type Compare =sig
..end
And if you are ready to drop generic comparison operators, then you can open this one as well
module type RefOps =sig
..end
Reference operators ala C.
module type Numeric =sig
..end
The full set of operations of a type of numbers
module type Bounded =sig
..end
module type Discrete =sig
..end