package decimal

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Settings that control precision, rounding mode, exceptional behaviour, etc.

type round =
  1. | Down
    (*

    Round towards 0; truncate.

    *)
  2. | Up
    (*

    Round away from 0.

    *)
  3. | Half_up
    (*

    Round up if last significant digit is >= 5, else round down.

    *)
  4. | Half_down
    (*

    Round up if last significant digit is > 5, else round down.

    *)
  5. | Half_even
    (*

    Round up if last significant digit is > 5 or next-to-last significant digit is odd, else round down.

    *)
  6. | Ceiling
    (*

    Round up if last significant digit is > 0, else no change.

    *)
  7. | Floor
    (*

    Round down if last significant digit is > 0, else no change.

    *)
  8. | Zero_five_up
    (*

    Round zero or five away from 0.

    *)
val string_of_round : round -> string
type t

Controls, precision, rounding, traps (exception handling), etc. settings.

val default : t Stdlib.ref

default is a reference to the default thread-local context.

val make : ?prec:int -> ?round:round -> ?e_max:int -> ?e_min:int -> ?capitals:bool -> ?clamp:bool -> unit -> t

make ?prec ?round ?e_max ?e_min ?capitals ?clamp () is a new context value with the given settings and the following traps configured:

  • conversion_syntax
  • invalid_operation
  • div_by_zero
  • overflow

These may be overridden by using Signal.set (Context.traps context) id bool, or setting a new default context.

val copy : orig:t -> ?prec:int -> ?round:round -> ?e_max:int -> ?e_min:int -> ?capitals:bool -> ?clamp:bool -> ?traps:Signal.array -> ?flags:Signal.array -> unit -> t

copy ~orig ?prec ?round ?e_max ?e_min ?capitals ?clamp ?traps ?flags is a deep copy of orig with the given settings. The optional settings default to the same values as those in orig.

val prec : t -> int
val round : t -> round
val e_max : t -> int
val e_min : t -> int
val capitals : t -> bool
val clamp : t -> bool
val traps : t -> Signal.array

traps t is the set of traps for context t. Traps may be set to true or false using Signal.set; a trap set to true raises a runtime exception when its signal is raised. One that's set to false causes the relevant calculation to silently handle the condition and return a result value (typically, NaN).

val flags : t -> Signal.array

flags t is the set of flags for context t. Flags are set to true during a calculation in a context t, when the calculation encounters a condition that triggers the flag. E.g., overflow.

val e_tiny : t -> int

e_tiny t is e_min t - prec t + 1, the minimum allowable exponent of context t.

val e_top : t -> int

e_top t is the maximum exponent of context t.

val pp : Stdlib.Format.formatter -> t -> unit

pp f t pretty-prints the context t.

OCaml

Innovation. Community. Security.