package batteries

  1. Overview
  2. Docs
A community-maintained standard library extension

Install

dune-project
 Dependency

Authors

Maintainers

Sources

batteries-3.10.0.tar.gz
md5=b7f3b99f12f21b1da6b6aa13d993206d
sha512=8b7f2479eb0271bcfd9168887c1e4a9a815c512eab3ee61b150fc4dfa9ec803e4f73115155f20b3017e4a822148d0e6d1c1e8e5f96790fd691b419dd39a908a2

doc/batteries.unthreaded/BatNumber/index.html

Module BatNumberSource

A common interface for numbers.

  • author Gabriel Scherer
  • author David Teller
Sourceexception 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.

Sourceexception 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.

Sourcetype 'a numeric = {
  1. zero : 'a;
  2. one : 'a;
  3. neg : 'a -> 'a;
  4. succ : 'a -> 'a;
  5. pred : 'a -> 'a;
  6. abs : 'a -> 'a;
  7. add : 'a -> 'a -> 'a;
  8. sub : 'a -> 'a -> 'a;
  9. mul : 'a -> 'a -> 'a;
  10. div : 'a -> 'a -> 'a;
  11. modulo : 'a -> 'a -> 'a;
  12. pow : 'a -> 'a -> 'a;
  13. compare : 'a -> 'a -> int;
  14. of_int : int -> 'a;
  15. to_int : 'a -> int;
  16. of_string : string -> 'a;
  17. to_string : 'a -> string;
  18. of_float : float -> 'a;
  19. 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.

Sourcemodule type Infix = sig ... end

The infix operators available with any type of numbers

Sourcemodule type Compare = sig ... end

And if you are ready to drop generic comparison operators, then you can open this one as well

Sourcemodule type RefOps = sig ... end

Reference operators ala C. Mutates a reference value. x -= y is the same as x := !x - y.

Sourcemodule type Numeric = sig ... end

The full set of operations of a type of numbers

Sourcemodule type Bounded = sig ... end
Sourcemodule type Discrete = sig ... end