module BatNumber:A common interface for numbers.sig
..end
exception 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
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 : |
This is presented as record to permit lightweight typeclass-style
computation.
module type Numeric =sig
..end
module type Bounded =sig
..end
module type Discrete =sig
..end