Core.Byte_units
SourceConversions between units of measure that are based on bytes (like kilobytes, megabytes, gigabytes, and words).
t
's are created with of_bytes_float_exn
, of_words_float_exn
, of_kilobytes
, of_megabytes
, etc.
Note: in this module, kilobytes, Megabytes, etc. are defined as powers of 1024:
include Comparable.S_plain with type t := t
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
ascending
is identical to compare
. descending x y = ascending y x
. These are intended to be mnemonic when used like List.sort ~compare:ascending
and List.sort ~cmp:descending
, since they cause the list to be sorted in ascending or descending order, respectively.
clamp_exn t ~min ~max
returns t'
, the closest value to t
such that between t' ~low:min ~high:max
is true.
Raises if not (min <= max)
.
module Map :
Map.S_plain
with type Key.t = t
with type Key.comparator_witness = comparator_witness
module Set :
Set.S_plain
with type Elt.t = t
with type Elt.comparator_witness = comparator_witness
This is a deprecated alias for of_bytes_float_exn
.
This will raise if and only if the argument can not be represented as a Byte_units.t
. Specifically this is if the argument is outside of [-2^62,2^62).
This will raise if and only if the argument can not be represented as a Byte_units.t
. Specifically this is if the argument is outside of [-2^62,2^62),
create of Byte_units
based on the number of kilobytes. N.B. This will raise if the value is outside of [-2^52,2^52).
create of Byte_units
based on the number of Megabytes. N.B. This will raise if the value is outside of [-2^42,2^42).
create of Byte_units
based on the number of Gigabytes. N.B. This will raise if the value is outside of [-2^32,2^32).
create of Byte_units
based on the number of Terabytes. N.B. This will raise if the value is outside of [-2^22,2^22).
create of Byte_units
based on the number of Petabytes. N.B. This will raise if the value is outside of [-2^12,2^12).
create of Byte_units
based on the number of Exabytes. N.B. This will raise if the value is outside of [-4,4).
Do not use, consider using of_words_int
instead. Alias for of_words_float_exn
.
create of Byte_units
based on the number of machine words.
Create of Byte_units
based on the number of machine words. On 64-bit platforms this will raise if the value is outside of [-2^59,2^59). On 32-bit platforms (including JS) this will raise if the value is outside of [-2^60,2^60).
to_string_hum t
returns a string representation of t
. This will use the largest unit that will not make the translated value be below 1.
For example Byte_units.to_string_hum (Byte_units.of_bytes_int 1000)
gives 1000B
, but Byte_units.to_string_hum (Byte_units.of_bytes_int 1500)
gives 1.46484K
.
This is a deprecated alias for bytes_float
.
This will raise if and only if the value of this Byte_units.t
can not be represented as an int. This can only happen on platforms where int
is less than 63 bits, specifically JS and 32-bit OCaml where this will raise if the number of bytes is outside of [-2^30,2^30).
Do not use, consider using words_int_exn
instead. Alias for words_float
In JS and on 32-bit OCaml this will raise if and only if the number of bytes is outside of [-2^32,2^32).
scale t mul
scale the measure t
by mul
include Quickcheck.S_range with type t := t
gen_incl lower_bound upper_bound
produces values between lower_bound
and upper_bound
, inclusive. It uses an ad hoc distribution that stresses boundary conditions more often than a uniform distribution, while still able to produce any value in the range. Raises if lower_bound > upper_bound
.
gen_uniform_incl lower_bound upper_bound
produces a generator for values uniformly distributed between lower_bound
and upper_bound
, inclusive. Raises if lower_bound > upper_bound
.