package core

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

Module Core.PercentSource

A scale factor, not bounded between 0% and 100%, represented as a float.

Sourcetype t = private Base.Float.t

Exposing that this is a float allows for more optimization. E.g. compiler can optimize some local refs and not box them.

include Ppx_hash_lib.Hashable.S with type t := t
Sourceval hash_fold_t : Base.Hash.state -> t -> Base.Hash.state

of_string and t_of_sexp disallow nan, inf, etc.

include Interfaces.Stringable with type t := t
Sourceval of_string : string -> t
Sourceval to_string : t -> string

Sexps are of the form 5bp or 0.05% or 0.0005x.

Warning: equal (t) (t_of_sexp (sexp_of_t t)) is not guaranteed. Multiple serialization round-trips may cause multiple small drifts.

include Interfaces.Sexpable with type t := t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
include Interfaces.Binable with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
Sourceval bin_size_t : t Bin_prot.Size.sizer
Sourceval bin_write_t : t Bin_prot.Write.writer
Sourceval bin_read_t : t Bin_prot.Read.reader
Sourceval __bin_read_t__ : (int -> t) Bin_prot.Read.reader

This function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.

Sourceval bin_shape_t : Bin_prot.Shape.t
include Interfaces.Comparable_binable 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
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int

compare t1 t2 returns 0 if t1 is equal to t2, a negative integer if t1 is less than t2, and a positive integer if t1 is greater than t2.

Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval 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.

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

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

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

Sourceval clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
Sourcetype comparator_witness
include Comparable.With_zero with type t := t
include Base.Comparable.With_zero with type t := t
Sourceval is_positive : t -> bool
Sourceval is_non_negative : t -> bool
Sourceval is_negative : t -> bool
Sourceval is_non_positive : t -> bool
Sourceval validate_lbound : min:t Maybe_bound.t -> t Validate.check
Sourceval validate_ubound : max:t Maybe_bound.t -> t Validate.check
Sourceval validate_bound : min:t Maybe_bound.t -> max:t Maybe_bound.t -> t Validate.check
Sourceval validate_positive : t Validate.check
Sourceval validate_non_negative : t Validate.check
Sourceval validate_negative : t Validate.check
Sourceval validate_non_positive : t Validate.check
include Robustly_comparable.S with type t := t
Sourceval (>=.) : t -> t -> bool
Sourceval (<=.) : t -> t -> bool
Sourceval (=.) : t -> t -> bool
Sourceval (>.) : t -> t -> bool
Sourceval (<.) : t -> t -> bool
Sourceval (<>.) : t -> t -> bool
Sourceval robustly_compare : t -> t -> int
include Quickcheckable.S with type t := t
Sourceval quickcheck_generator : t Base_quickcheck.Generator.t
Sourceval quickcheck_observer : t Base_quickcheck.Observer.t
Sourceval quickcheck_shrinker : t Base_quickcheck.Shrinker.t
Sourcemodule Option : sig ... end

The value nan cannot be represented as an Option.t

Sourceval (*) : t -> t -> t
Sourceval (+) : t -> t -> t
Sourceval (-) : t -> t -> t
Sourceval (/) : t -> t -> t
Sourceval (//) : t -> t -> Base.Float.t
Sourceval zero : t
Sourceval neg : t -> t
Sourceval abs : t -> t
Sourceval is_zero : t -> Base.Bool.t
Sourceval is_nan : t -> Base.Bool.t
Sourceval is_inf : t -> Base.Bool.t

apply t x multiplies the percent t by x, returning a float.

Sourceval scale : t -> Base.Float.t -> t

scale t x scales the percent t by x, returning a new t.

Sourceval of_mult : Base.Float.t -> t

of_mult 5. is 5x = 500% = 50_000bp

Sourceval to_mult : t -> Base.Float.t
Sourceval of_percentage : Base.Float.t -> t

of_percentage 5. is 5% = 0.05x = 500bp

Sourceval to_percentage : t -> Base.Float.t
Sourceval of_bp : Base.Float.t -> t

of_bp 5. is 5bp = 0.05% = 0.0005x

Sourceval to_bp : t -> Base.Float.t
Sourceval of_bp_int : Base.Int.t -> t
Sourceval to_bp_int : t -> Base.Int.t

rounds down

Sourceval round_significant : t -> significant_digits:Base.Int.t -> t

0.0123456% ~significant_digits:4 is 1.235bp

Sourceval round_decimal_mult : t -> decimal_digits:Base.Int.t -> t

0.0123456% ~decimal_digits:4 is 0.0001 = 1bp

Sourceval round_decimal_percentage : t -> decimal_digits:Base.Int.t -> t

0.0123456% ~decimal_digits:4 is 0.0123% = 1.23bp

Sourceval round_decimal_bp : t -> decimal_digits:Base.Int.t -> t

0.0123456% ~decimal_digits:4 is 1.2346bp

Sourceval t_of_sexp_allow_nan_and_inf : Sexp.t -> t
Sourceval of_string_allow_nan_and_inf : Base.String.t -> t
Sourcemodule Format : sig ... end

A Format.t tells Percent.format how to render a floating-point value as a string, like a printf conversion specification.

Sourceval format : t -> Format.t -> Base.String.t
Sourceval validate : t -> Validate.t
Sourceval sign : t -> Sign.t
  • deprecated [since 2016-01] Replace [sign] with [sign_exn]
Sourceval sign_exn : t -> Sign.t

The sign of a Percent.t. Both -0. and 0. map to Zero. Raises on nan. All other values map to Neg or Pos.

Sourcemodule Stable : sig ... end
Sourcemodule Always_percentage : sig ... end

Does not format small values as "3bp" or large ones as "2x"; always uses percentages ("0.0003%" or "200%"). The standard of_sexp can read these just fine.

OCaml

Innovation. Community. Security.