package batteries
Install
Dune Dependency
Authors
Maintainers
Sources
md5=ea26b5c72e6731e59d856626049cca4d
sha512=55975b62c26f6db77433a3ac31f97af609fc6789bb62ac38b267249c78fd44ff37fe81901f1cf560857b9493a6046dd37b0d1c0234c66bd59e52843aac3ce6cb
doc/batteries.unthreaded/BatNumber/index.html
Module BatNumber
Source
A common interface for numbers.
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
.
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 : 'a;
one : 'a;
neg : 'a -> 'a;
succ : 'a -> 'a;
pred : 'a -> 'a;
abs : 'a -> 'a;
add : 'a -> 'a -> 'a;
sub : 'a -> 'a -> 'a;
mul : 'a -> 'a -> 'a;
div : 'a -> 'a -> 'a;
modulo : 'a -> 'a -> 'a;
pow : 'a -> 'a -> 'a;
compare : 'a -> 'a -> int;
of_int : int -> 'a;
to_int : 'a -> int;
of_string : string -> 'a;
to_string : 'a -> string;
of_float : float -> 'a;
to_float : 'a -> float;
}
The smallest set of operations supported by every set of numbers.
This is presented as record to permit lightweight typeclass-style computation.
And if you are ready to drop generic comparison operators, then you can open this one as well
Reference operators ala C. Mutates a reference value. x -= y
is the same as x := !x - y
.