base

Full standard library replacement for OCaml
IN THIS PACKAGE
Module Base . Int_math . Make

Parameters

module X : Make_arg

Signature

val (%) : X.t -> X.t -> X.t
val (/%) : X.t -> X.t -> X.t
val (//) : X.t -> X.t -> float

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. If the result overflows (too far positive or too far negative), round returns an incorrect result.

       | `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 ] -> X.t -> to_multiple_of:X.t -> X.t
val round_towards_zero : X.t -> to_multiple_of:X.t -> X.t
val round_down : X.t -> to_multiple_of:X.t -> X.t
val round_up : X.t -> to_multiple_of:X.t -> X.t
val round_nearest : X.t -> to_multiple_of:X.t -> X.t