derived operations common to various integer modules
include Base__.Int_intf.Round with type t := X.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.