Module Base__.Int_math.Make

derived operations common to various integer modules

Parameters

X : T

Signature

val (%) : X.t ‑> X.t ‑> X.t
val (/%) : X.t ‑> X.t ‑> X.t
val (//) : X.t ‑> X.t ‑> float
include Base__.Int_intf.Round with type t := X.t
type t

round rounds an int to a multiple of a given to_multiple_of argument, according to a direction dir, with default dir being `Nearest. round will raise if to_multiple_of <= 0.

       | `Down    | rounds toward Int.neg_infinity                          |
       | `Up      | rounds toward Int.infinity                              |
       | `Nearest | rounds to the nearest multiple, or `Up in case of a tie |
       | `Zero    | rounds toward zero                                      |

Here are some examples for round ~to_multiple_of:10 for each direction:

       | `Down    | {10 .. 19} --> 10 | { 0 ... 9} --> 0 | {-10 ... -1} --> -10 |
       | `Up      | { 1 .. 10} --> 10 | {-9 ... 0} --> 0 | {-19 .. -10} --> -10 |
       | `Zero    | {10 .. 19} --> 10 | {-9 ... 9} --> 0 | {-19 .. -10} --> -10 |
       | `Nearest | { 5 .. 14} --> 10 | {-5 ... 4} --> 0 | {-15 ... -6} --> -10 |

For convenience and performance, there are variants of round with dir hard-coded. If you are writing performance-critical code you should use these.

val round : ?⁠dir:[ `Zero | `Nearest | `Up | `Down ] ‑> t ‑> to_multiple_of:t ‑> t
val round_towards_zero : t ‑> to_multiple_of:t ‑> t
val round_down : t ‑> to_multiple_of:t ‑> t
val round_up : t ‑> to_multiple_of:t ‑> t
val round_nearest : t ‑> to_multiple_of:t ‑> t