Module Core_kernel.Byte_units

Conversions 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:

type t
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val create : [ `Bytes | `Kilobytes | `Megabytes | `Gigabytes | `Words ] -> Base.Float.t -> t
include Comparable.S_plain with type t := t
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
include Base.Comparisons.Infix with type t := t
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (=) : t -> t -> bool
val (>) : t -> t -> bool
val (<) : t -> t -> bool
val (<>) : t -> t -> bool
val equal : t -> t -> bool
val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int

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.

val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool

between t ~low ~high means low <= t <= high

val clamp_exn : t -> min:t -> max:t -> t

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).

val clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
type comparator_witness
val validate_lbound : min:t Base.Maybe_bound.t -> t Base.Validate.check
val validate_ubound : max:t Base.Maybe_bound.t -> t Base.Validate.check
val validate_bound : min:t Base.Maybe_bound.t -> max:t Base.Maybe_bound.t -> t Base.Validate.check
include Hashable.S_plain with type t := t
include Hashable.Common with type t := t
val compare : t -> t -> Base.Int.t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
val hashable : t Hashtbl.Hashable.t
module Table : Hashtbl.S_plain with type key = t
module Hash_set : Hash_set.S_plain with type elt = t
module Hash_queue : Hash_queue.S with type key = t
include Base.Stringable.S with type t := t
val of_string : string -> t
val to_string : t -> string
val of_bytes : Base.Float.t -> t

This is a deprecated alias for of_bytes_float_exn.

val of_bytes_int : Base.Int.t -> t
val of_bytes_int63 : Int63.t -> t
val of_bytes_int64_exn : Int64.t -> t

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).

val of_bytes_float_exn : Base.Float.t -> t

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),

val of_kilobytes : Base.Float.t -> t

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).

val of_megabytes : Base.Float.t -> t

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).

val of_gigabytes : Base.Float.t -> t

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).

val of_terabytes : Base.Float.t -> t

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).

val of_petabytes : Base.Float.t -> t

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).

val of_exabytes : Base.Float.t -> t

create of Byte_units based on the number of Exabytes. N.B. This will raise if the value is outside of [-4,4).

val of_words : Base.Float.t -> t

Do not use, consider using of_words_int instead. Alias for of_words_float_exn.

val of_words_int : Base.Int.t -> t

create of Byte_units based on the number of machine words.

val of_words_float_exn : Base.Float.t -> t

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).

val to_string_hum : t -> Base.String.t

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.

val to_string_short : t -> Base.String.t

to_string_short is like to_string_hum but will attempt to only show 4 significant digits.

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.46K.

val bytes : t -> Base.Float.t

This is a deprecated alias for bytes_float.

val bytes_int_exn : t -> Base.Int.t

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).

val bytes_int63 : t -> Int63.t
val bytes_int64 : t -> Int64.t
val bytes_float : t -> Base.Float.t
val kilobytes : t -> Base.Float.t
val megabytes : t -> Base.Float.t
val gigabytes : t -> Base.Float.t
val terabytes : t -> Base.Float.t
val petabytes : t -> Base.Float.t
val exabytes : t -> Base.Float.t
val words : t -> Base.Float.t

Do not use, consider using words_int_exn instead. Alias for words_float

val words_int_exn : t -> Base.Int.t

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).

val words_float : t -> Base.Float.t
val zero : t
val scale : t -> Base.Float.t -> t

scale t mul scale the measure t by mul

val arg_type : t Command.Arg_type.t
module Infix : sig ... end
include module type of Infix
val (-) : t -> t -> t
val (+) : t -> t -> t
val (/) : t -> Base.Float.t -> t

( / ) t mul scales t by 1/mul

val (//) : t -> t -> Base.Float.t

( // ) t1 t2 returns the ratio of t1 to t2

module Stable : sig ... end