package base

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

derived operations common to various integer modules

Parameters

module X : T

Signature

val (%) : X.t -> X.t -> X.t
val (/%) : X.t -> X.t -> X.t
val (//) : X.t -> X.t -> float
include 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.

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
OCaml

Innovation. Community. Security.