github ↗
docs menu

Module Dtype.Value

Arithmetic and comparison on values, as on numbers: a `Bool counts as 0 or 1, an operation on two integers gives an exact integer, and one that involves a float gives a float, in which an integer that rounds past the greatest double is the infinity of its sign. The operators compare an integer and a float exactly, without rounding the integer, and a comparison with NaN is false, except <>, which is true.

#type t = value

The type for values.

#val of_int : int -> t

of_int n is `Int n.

#val to_float : t -> float

to_float v is v as a float: 0. or 1. for a `Bool, and an integer rounded to nearest, ties to even, or to the infinity of its sign if it rounds past the greatest double.

#val to_z : t -> Bigint.t

to_z v is v as an integer: 0 or 1 for a `Bool, and a float rounded towards zero.

Raises Invalid_argument if v is an infinity or a NaN.

#val to_int : t -> int

to_int v is to_z v as an int.

Raises Invalid_argument if v is an infinity or a NaN, or if to_z v does not fit an int.

#val to_bool : t -> bool

to_bool v is true iff v is not zero: a NaN is true.

#val compare : t -> t -> int

compare v0 v1 is a total order on values by magnitude, where NaN is less than every other value and equal to itself. Values of equal magnitude compare equal whatever their kind, so `Bool true, `Int 1 and `Float 1. are equal.

#val (=) : t -> t -> bool

v0 = v1 is true iff v0 and v1 have the same magnitude.

#val (<>) : t -> t -> bool

v0 <> v1 is not (v0 = v1).

#val (<) : t -> t -> bool

v0 < v1 is true iff v0's magnitude is less than v1's.

#val (<=) : t -> t -> bool

v0 <= v1 is v0 < v1 || v0 = v1.

#val (>) : t -> t -> bool

v0 > v1 is v1 < v0.

#val (>=) : t -> t -> bool

v0 >= v1 is v1 <= v0.

#val min : t -> t -> t

min v0 v1 is v1 if v1 < v0, and v0 otherwise.

#val max : t -> t -> t

max v0 v1 is v1 if v1 > v0, and v0 otherwise.

#val (~-) : t -> t

-v is the negation of v.

#val (+) : t -> t -> t

v0 + v1 is the sum of v0 and v1.

#val (-) : t -> t -> t

v0 - v1 is the difference of v0 and v1.

#val (*) : t -> t -> t

v0 * v1 is the product of v0 and v1.

#val (//) : t -> t -> t

v0 // v1 is the quotient of v0 by v1 rounded down.

Raises Division_by_zero if v1 is zero.

#val (%) : t -> t -> t

v0 % v1 is v0 - (v0 // v1) * v1, of the sign of v1 when it is not zero: a float remainder is exact.

Raises Division_by_zero if v1 is zero.