# Module Batteries.Number

    module Number: BatNumber

    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 : `'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.

    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

###### Utilities

    module type NUMERIC_BASE = sig .. end

The smallest set of operations supported by every set of numbers
Automated definition of infix operators for a given numeric type, so that you can open it without poluting your namespace. (apart from the type bat__infix_t)

    module MakeInfix: functor (Base : NUMERIC_BASE) -> Infix  with type bat__infix_t = Base.t

Automated definition of infix comparison operators for a given numeric type, so that you can open it only when you mean it. (apart from the type bat__compare_t)

    module MakeCompare: functor (Base : NUMERIC_BASE) -> Compare  with type bat__compare_t = Base.t

    module MakeRefOps: functor (Base : NUMERIC_BASE) -> RefOps  with type bat__refops_t = Base.t

Automated definition of reference operators for a given numeric type
Automated definition of operators for a given numeric type. You will only need this if you develop your own numeric modules.

    module MakeNumeric: functor (Base : NUMERIC_BASE) -> Numeric  with type t = Base.t

    val generic_pow : zero:'a ->
           one:'a ->
           div_two:('a -> 'a) ->
           mod_two:('a -> 'a) -> mul:('a -> 'a -> 'a) -> 'a -> 'a -> 'a