Module Float_uSource

Sourcetype t = float#

Utilities for unboxed floats. This module is mostly a copy of Base's Float module, but with much functionality missing because it can't yet be implemented for unboxed floats or unboxed types generally.

Sourceval globalize : t @ local -> t
include Ppx_quickcheck_runtime.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 Boxed = Core.Float

These definitions are available. They're included from O below.

  external box : float# -> (float[@local_opt]) = "%box_float"
  external unbox : (float[@local_opt]) -> float# = "%unbox_float"

Synonyms for box and unbox.

Sourceval to_float : float# -> float @@ portable
Sourceval of_float : float -> float# @@ portable

Validation

validate_lbound, validate_ubound, and validate_bound always fail if class is Nan or Infinite. The other validation functions still fail on Nan, but permit Infinite values of the correct sign.

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
Sourceval validate_ordinary : t Core.Validate.check @@ portable

validate_ordinary fails if class is Nan or Infinite.

Inlined from Identifiable, which comprises Sexpable, Stringable, Comparable, and Pretty_printer

Inlined from Sexpable

Sourceval sexp_of_t : t -> Core.Sexp.t @@ portable
Sourceval t_of_sexp : Core.Sexp.t -> t @@ portable
Sourceval t_sexp_grammar : t Sexplib0.Sexp_grammar.t @@ portable

For bin_io

include Core.Bin_prot.Binable.S__local with type t := t
include Bin_prot.Binable.S_only_functions__local with type t := t
include sig ... end
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__ : t Bin_prot.Read.vtag_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

For hash

include Ppx_hash_lib.Hashable.S with type t := t

From Typerep

Sourceval typerep_of_t : t Core.Typerep.t @@ portable
Sourceval typename_of_t : t Typerep_lib.Typename.t @@ portable

Inlined from Comparable

Sourceval equal : t -> t -> bool @@ portable [@@zero_alloc]
Sourceval compare : t -> t -> int @@ portable [@@zero_alloc]

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.

max and min will return nan if either argument is nan.

Sourceval min : t -> t -> t @@ portable [@@zero_alloc]
Sourceval max : t -> t -> t @@ portable [@@zero_alloc]
Sourceval ascending : t -> t -> int @@ portable [@@zero_alloc]

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 @@ portable [@@zero_alloc]
Sourceval between : t -> low:t -> high:t -> bool @@ portable [@@zero_alloc]

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

Sourceval clamp_exn : t -> min:t -> max:t -> t @@ portable [@@zero_alloc]

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

Inlined from Pretty_printer

Sourceval pp : Core.Formatter.t -> t -> unit @@ portable

Inlined from Invariant

Sourceval invariant : float# -> unit @@ portable

Constants

Sourceval nan : t @@ portable
Sourceval infinity : t @@ portable
Sourceval neg_infinity : t @@ portable
Sourceval max_value : t @@ portable

Equal to infinity.

Sourceval min_value : t @@ portable

Equal to neg_infinity.

Sourceval zero : t @@ portable
Sourceval one : t @@ portable
Sourceval minus_one : t @@ portable
Sourceval pi : t @@ portable

The constant pi.

Sourceval sqrt_pi : t @@ portable

The constant sqrt(pi).

Sourceval sqrt_2pi : t @@ portable

The constant sqrt(2 * pi).

Sourceval euler_gamma_constant : t @@ portable

Euler-Mascheroni constant (γ).

Sourceval epsilon_float : t @@ portable

The difference between 1.0 and the smallest exactly representable floating-point number greater than 1.0. That is:

epsilon_float = (one_ulp `Up 1.0) -. 1.0

This gives the relative accuracy of type t, in the sense that for numbers on the order of x, the roundoff error is on the order of x *. float_epsilon.

See also: Machine epsilon.

Sourceval max_finite_value : t @@ portable
Sourceval min_positive_subnormal_value : t @@ portable
Sourceval min_positive_normal_value : t @@ portable

Rounding and integer conversion

Sourceval to_int64_preserve_order : t -> int64 option @@ portable

An order-preserving bijection between all floats except for nans, and all int64s with absolute value smaller than or equal to 2**63 - 2**52. Note both 0. and -0. map to 0L.

Sourceval to_int64_preserve_order_exn : t -> int64 @@ portable
Sourceval of_int64_preserve_order : int64 -> t @@ portable

Returns nan if the absolute value of the argument is too large.

Sourceval one_ulp : [ `Up | `Down ] -> t -> t @@ portable

The next or previous representable float. ULP stands for "unit of least precision", and is the spacing between floating point numbers. Both one_ulp `Up infinity and one_ulp `Down neg_infinity return a nan.

Sourceval to_int : t -> int @@ portable [@@zero_alloc]
Sourceval to_int_unchecked : t -> int @@ portable [@@zero_alloc]
Sourceval truncate : t -> int @@ portable
Sourceval of_int63 : Core.Int63.t -> t @@ portable [@@zero_alloc]
Sourceval of_int64 : int64 -> t @@ portable
Sourceval to_int64 : t -> int64 @@ portable
Sourceval to_float32_u : t -> float32# @@ portable [@@zero_alloc]
Sourceval of_float32_u : float32# -> t @@ portable [@@zero_alloc]
Sourceval round : ?dir:[ `Zero | `Nearest | `Up | `Down ] @ local -> t -> t @@ portable

round rounds a float to an integer float. iround{,_exn} rounds a float to an int. Both round according to a direction dir, with default dir being `Nearest.

  | `Down    | rounds toward Float.neg_infinity                             |
  | `Up      | rounds toward Float.infinity                                 |
  | `Nearest | rounds to the nearest int ("round half-integers up")         |
  | `Zero    | rounds toward zero                                           |

iround_exn raises when trying to handle nan or trying to handle a float outside the range [float min_int, float max_int).

Here are some examples for round for each direction:

  | `Down    | [-2.,-1.)   to -2. | [-1.,0.)   to -1. | [0.,1.) to 0., [1.,2.) to 1. |
  | `Up      | (-2.,-1.]   to -1. | (-1.,0.]   to -0. | (0.,1.] to 1., (1.,2.] to 2. |
  | `Zero    | (-2.,-1.]   to -1. | (-1.,1.)   to 0.  | [1.,2.) to 1.                |
  | `Nearest | [-1.5,-0.5) to -1. | [-0.5,0.5) to 0.  | [0.5,1.5) to 1.              |

For convenience, versions of these functions with the dir argument hard-coded are provided. If you are writing performance-critical code you should use the versions with the hard-coded arguments (e.g. iround_down_exn). The _exn ones are the fastest.

The following properties hold:

  • of_int (iround_*_exn i) = i for any float i that is an integer with min_int <= i <= max_int.
  • round_* i = i for any float i that is an integer.
  • iround_*_exn (of_int i) = i for any int i with -2**52 <= i <= 2**52.
Sourceval iround : ?dir:[ `Zero | `Nearest | `Up | `Down ] @ local -> t -> int option @@ portable
Sourceval iround_exn : ?dir:[ `Zero | `Nearest | `Up | `Down ] @ local -> t -> int @@ portable
Sourceval round_towards_zero : t -> t @@ portable [@@zero_alloc]
Sourceval round_down : t -> t @@ portable [@@zero_alloc]
Sourceval round_up : t -> t @@ portable [@@zero_alloc]
Sourceval round_nearest : t -> t @@ portable [@@zero_alloc]

Rounds half integers up.

Sourceval round_nearest_half_to_even : t -> t @@ portable [@@zero_alloc]

Rounds half integers to the even integer.

Sourceval iround_towards_zero : t -> int option @@ portable
Sourceval iround_down : t -> int option @@ portable
Sourceval iround_up : t -> int option @@ portable
Sourceval iround_nearest : t -> int option @@ portable
Sourceval iround_towards_zero_or_null : t -> int or_null @@ portable [@@zero_alloc]
Sourceval iround_down_or_null : t -> int or_null @@ portable [@@zero_alloc]
Sourceval iround_up_or_null : t -> int or_null @@ portable [@@zero_alloc]
Sourceval iround_nearest_or_null : t -> int or_null @@ portable [@@zero_alloc]
Sourceval iround_towards_zero_exn : t -> int @@ portable [@@zero_alloc]
Sourceval iround_down_exn : t -> int @@ portable [@@zero_alloc]
Sourceval iround_up_exn : t -> int @@ portable [@@zero_alloc]
Sourceval iround_nearest_exn : t -> int @@ portable [@@zero_alloc]
Sourceval int63_round_down_exn : t -> Core.Int63.t @@ portable
Sourceval int63_round_up_exn : t -> Core.Int63.t @@ portable
Sourceval int63_round_nearest_exn : t -> Core.Int63.t @@ portable [@@zero_alloc]
Sourceval iround_lbound : t @@ portable
Sourceval iround_ubound : t @@ portable
Sourceval int63_round_lbound : t @@ portable
Sourceval int63_round_ubound : t @@ portable
Sourceval round_significant : t -> significant_digits:int -> t @@ portable

round_significant x ~significant_digits:n rounds to the nearest number with n significant digits. More precisely: it returns the representable float closest to x rounded to n significant digits. It is meant to be equivalent to sprintf "%.*g" n x |> Float.of_string but faster (10x-15x). Exact ties are resolved as round-to-even.

However, it might in rare cases break the contract above.

It might in some cases appear as if it violates the round-to-even rule:

  let x = 4.36083208835
  let z = 4.3608320883;;

  assert (z = fast_approx_round_significant x ~sf:11)

But in this case so does sprintf, since x as a float is slightly under-represented:

  sprintf "%.11g" x = "4.3608320883";;
  sprintf "%.30g" x = "4.36083208834999958014577714493"

More importantly, round_significant might sometimes give a different result than sprintf ... |> Float.of_string because it round-trips through an integer. For example, the decimal fraction 0.009375 is slightly under-represented as a float:

  sprintf "%.17g" 0.009375 = "0.0093749999999999997"

But:

  0.009375 *. 1e5 = 937.5

Therefore:

  round_significant 0.009375 ~significant_digits:3 = 0.00938

whereas:

  sprintf "%.3g" 0.009375 = "0.00937"

In general we believe (and have tested on numerous examples) that the following holds for all x:

  let s = sprintf "%.*g" significant_digits x |> Float.of_string in
  s = round_significant ~significant_digits x
  || s = round_significant ~significant_digits (one_ulp `Up x)
  || s = round_significant ~significant_digits (one_ulp `Down x)

Also, for float representations of decimal fractions (like 0.009375), round_significant is more likely to give the "desired" result than sprintf ... |> of_string (that is, the result of rounding the decimal fraction, rather than its float representation). But it's not guaranteed either--see the 4.36083208835 example above.

Sourceval round_decimal : t -> decimal_digits:int -> t @@ portable

round_decimal x ~decimal_digits:n rounds x to the nearest 10**(-n). For positive n it is meant to be equivalent to sprintf "%.*f" n x |> Float.of_string, but faster.

All the considerations mentioned in round_significant apply (both functions use the same code path).

Tests

Sourceval is_nan : t -> bool @@ portable [@@zero_alloc]
Sourceval is_inf : t -> bool @@ portable [@@zero_alloc]

A float is infinite when it is either infinity or neg_infinity.

Sourceval is_finite : t -> bool @@ portable [@@zero_alloc]

A float is finite when neither is_nan nor is_inf is true.

Sourceval is_integer : t -> bool @@ portable [@@zero_alloc]

is_integer x is true if and only if x is an integer.

is_positive, is_non_negative, is_negative, and is_non_positive return false if t is nan.

Sourceval is_positive : t @ local -> bool @@ portable [@@zero_alloc]
Sourceval is_non_negative : t @ local -> bool @@ portable [@@zero_alloc]
Sourceval is_negative : t @ local -> bool @@ portable [@@zero_alloc]
Sourceval is_non_positive : t @ local -> bool @@ portable [@@zero_alloc]

Arithmetic

min_inan and max_inan return, respectively, the min and max of the two given values, except when one of the values is a nan, in which case the other is returned. (Returns nan if both arguments are nan.)

Sourceval min_inan : t -> t -> t @@ portable
Sourceval max_inan : t -> t -> t @@ portable
Sourceval mod_float : t -> t -> t @@ portable

mod_float x y returns a result with the same sign as x. It returns nan if y is 0. It is basically

  let mod_float x y = x -. (float (truncate (x /. y)) *. y)

not

  let mod_float x y = x -. (floor (x /. y) *. y)

and therefore resembles mod on integers more than %.

Sourceval add : t -> t -> t @@ portable [@@zero_alloc]

Ordinary functions for arithmetic operations

These are for modules that inherit from t, since the infix operators are more convenient.

Sourceval sub : t -> t -> t @@ portable [@@zero_alloc]
Sourceval scale : t -> t -> t @@ portable [@@zero_alloc]
Sourcemodule O : sig ... end

A sub-module designed to be opened to make working with floats more convenient.

Sourceval unbox : float -> float#
Sourceval box : float# -> float
Sourceval (+) : t -> t -> t [@@zero_alloc strict]
Sourceval (-) : t -> t -> t [@@zero_alloc strict]
Sourceval (*) : t -> t -> t [@@zero_alloc strict]
Sourceval (/) : t -> t -> t [@@zero_alloc strict]
Sourceval (%) : t -> t -> t

In analogy to Int.( % ), ( % ):

  • always produces non-negative (or NaN) result
  • raises when given a negative modulus.

Like the other infix operators, NaNs in mean NaNs out.

Other cases: (a % Infinity) = a when 0 <= a < Infinity, (a % Infinity) = Infinity when -Infinity < a < 0, (+/- Infinity % a) = NaN, (a % 0) = NaN.

Sourceval (**) : t -> t -> t [@@zero_alloc strict]
Sourceval (~-) : t -> t [@@zero_alloc strict]
Sourceval (>=) : t -> t -> bool [@@zero_alloc strict]
Sourceval (<=) : t -> t -> bool [@@zero_alloc strict]
Sourceval (=) : t -> t -> bool [@@zero_alloc strict]
Sourceval (>) : t -> t -> bool [@@zero_alloc strict]
Sourceval (<) : t -> t -> bool [@@zero_alloc strict]
Sourceval (<>) : t -> t -> bool [@@zero_alloc strict]
Sourceval abs : t -> t [@@zero_alloc strict]
Sourceval neg : t -> t [@@zero_alloc strict]
Sourceval of_int : int -> t [@@zero_alloc strict]

Note that this doesn't round trip in either direction. For example, Float.to_int (Float.of_int max_int) <> max_int.

Sourcemodule O_dot : sig ... end

Similar to O, except that operators are suffixed with a dot, allowing one to have both int and float operators in scope simultaneously.

String conversions

Sourceval to_string : t -> string @@ portable

to_string x builds a string s representing the float x that guarantees the round trip, that is such that Float_u.equal x (Float_u.of_string s).

It usually yields as few significant digits as possible. That is, it won't print 3.14 as 3.1400000000000001243. The only exception is that occasionally it will output 17 significant digits when the number can be represented with just 16 (but not 15 or less) of them.

Sourceval of_string : string @ local -> t @@ portable

of_string is inverse to to_string.

Sourceval to_string_hum : ?delimiter:char -> ?decimals:int -> ?strip_zero:bool -> ?explicit_plus:bool -> t -> string @@ portable

Pretty print float, for example to_string_hum ~decimals:3 1234.1999 = "1_234.200" to_string_hum ~decimals:3 ~strip_zero:true 1234.1999 = "1_234.2" . No delimiters are inserted to the right of the decimal.

Sourceval to_padded_compact_string : t -> string @@ portable

Produce a lossy compact string representation of the float. The float is scaled by an appropriate power of 1000 and rendered with one digit after the decimal point, except that the decimal point is written as '.', 'k', 'm', 'g', 't', or 'p' to indicate the scale factor. (However, if the digit after the "decimal" point is 0, it is suppressed.)

The smallest scale factor that allows the number to be rendered with at most 3 digits to the left of the decimal is used. If the number is too large for this format (i.e., the absolute value is at least 999.95e15), scientific notation is used instead. E.g.:

  • to_padded_compact_string (-0.01) = "-0 "
  • to_padded_compact_string 1.89 = "1.9"
  • to_padded_compact_string 999_949.99 = "999k9"
  • to_padded_compact_string 999_950. = "1m "

In the case where the digit after the "decimal", or the "decimal" itself is omitted, the numbers are padded on the right with spaces to ensure the last two columns of the string always correspond to the decimal and the digit afterward (except in the case of scientific notation, where the exponent is the right-most element in the string and could take up to four characters).

  • to_padded_compact_string 1. = "1 "
  • to_padded_compact_string 1.e6 = "1m "
  • to_padded_compact_string 1.e16 = "1.e+16"
  • to_padded_compact_string max_finite_value = "1.8e+308"

Numbers in the range -.05 < x < .05 are rendered as "0 " or "-0 ".

Other cases:

  • to_padded_compact_string nan = "nan "
  • to_padded_compact_string infinity = "inf "
  • to_padded_compact_string neg_infinity = "-inf "

Exact ties are resolved to even in the decimal:

  • to_padded_compact_string 3.25 = "3.2"
  • to_padded_compact_string 3.75 = "3.8"
  • to_padded_compact_string 33_250. = "33k2"
  • to_padded_compact_string 33_350. = "33k4"

to_padded_compact_string is defined in terms of to_padded_compact_string_custom below as

  let to_padded_compact_string t =
    to_padded_compact_string_custom
      t
      ?prefix:None
      ~kilo:"k"
      ~mega:"m"
      ~giga:"g"
      ~tera:"t"
      ~peta:"p"
      ()
  ;;
Sourceval to_padded_compact_string_custom : t -> ?prefix:string -> kilo:string -> mega:string -> giga:string -> tera:string -> ?peta:string -> unit -> string @@ portable

Similar to to_padded_compact_string but allows the user to provide different abbreviations. This can be useful to display currency values, e.g. $1mm3, where prefix="$", mega="mm".

Exponents and trigonometry

Sourceval int_pow : t -> int -> t @@ portable

int_pow x n computes x ** float n via repeated squaring. It is generally much faster than **.

Note that int_pow x 0 always returns 1., even if x = nan. This coincides with x ** 0. and is intentional.

For n >= 0 the result is identical to an n-fold product of x with itself under *., with a certain placement of parentheses. For n < 0 the result is identical to int_pow (1. /. x) (-n).

The error will be on the order of |n| ulps, essentially the same as if you perturbed x by up to a ulp and then exponentiated exactly.

Benchmarks show a factor of 5-10 speedup (relative to **) for exponents up to about 1000 (approximately 10ns vs. 70ns). For larger exponents the advantage is smaller but persists into the trillions. For a recent or more detailed comparison, run the benchmarks.

Depending on context, calling this function might or might not allocate 2 minor words. Even if called in a way that causes allocation, it still appears to be faster than **.

Sourceval square : t -> t @@ portable [@@zero_alloc]

square x returns x *. x.

Sourceval ldexp : t -> int -> t @@ portable [@@zero_alloc]

ldexp x n returns x *. 2 ** n

Sourceval log10 : t -> t @@ portable [@@zero_alloc]

Base 10 logarithm.

Sourceval log2 : t -> t @@ portable [@@zero_alloc]

Base 2 logarithm.

Sourceval expm1 : t -> t @@ portable [@@zero_alloc]

expm1 x computes exp x -. 1.0, giving numerically-accurate results even if x is close to 0.0.

Sourceval log1p : t -> t @@ portable [@@zero_alloc]

log1p x computes log(1.0 +. x) (natural logarithm), giving numerically-accurate results even if x is close to 0.0.

Sourceval copysign : t -> t -> t @@ portable [@@zero_alloc]

copysign x y returns a float whose absolute value is that of x and whose sign is that of y. If x is nan, returns nan. If y is nan, returns either x or -. x, but it is not specified which.

Sourceval cos : t -> t @@ portable [@@zero_alloc]

Cosine. Argument is in radians.

Sourceval sin : t -> t @@ portable [@@zero_alloc]

Sine. Argument is in radians.

Sourceval tan : t -> t @@ portable [@@zero_alloc]

Tangent. Argument is in radians.

Sourceval acos : t -> t @@ portable [@@zero_alloc]

Arc cosine. The argument must fall within the range [-1.0, 1.0]. Result is in radians and is between 0.0 and pi.

Sourceval asin : t -> t @@ portable [@@zero_alloc]

Arc sine. The argument must fall within the range [-1.0, 1.0]. Result is in radians and is between -pi/2 and pi/2.

Sourceval atan : t -> t @@ portable [@@zero_alloc]

Arc tangent. Result is in radians and is between -pi/2 and pi/2.

Sourceval atan2 : t -> t -> t @@ portable [@@zero_alloc]

atan2 y x returns the arc tangent of y /. x. The signs of x and y are used to determine the quadrant of the result. Result is in radians and is between -pi and pi.

Sourceval hypot : t -> t -> t @@ portable [@@zero_alloc]

hypot x y returns sqrt(x *. x + y *. y), that is, the length of the hypotenuse of a right-angled triangle with sides of length x and y, or, equivalently, the distance of the point (x,y) to origin.

Sourceval cosh : t -> t @@ portable [@@zero_alloc]

Hyperbolic cosine. Argument is in radians.

Sourceval sinh : t -> t @@ portable [@@zero_alloc]

Hyperbolic sine. Argument is in radians.

Sourceval tanh : t -> t @@ portable [@@zero_alloc]

Hyperbolic tangent. Argument is in radians.

Sourceval acosh : t -> t @@ portable [@@zero_alloc]

Hyperbolic arc cosine. The argument must fall within the range [1.0, inf]. Result is in radians and is between 0.0 and inf.

Sourceval asinh : t -> t @@ portable [@@zero_alloc]

Hyperbolic arc sine. The argument and result range over the entire real line. Result is in radians.

Sourceval atanh : t -> t @@ portable [@@zero_alloc]

Hyperbolic arc tangent. The argument must fall within the range [-1.0, 1.0]. Result is in radians and ranges over the entire real line.

Sourceval sqrt : t -> t @@ portable [@@zero_alloc]

Square root.

Sourceval cbrt : t -> t @@ portable

Cube root.

Sourceval exp : t -> t @@ portable [@@zero_alloc]

Exponential.

Sourceval log : t -> t @@ portable [@@zero_alloc]

Natural logarithm.

Classification and representation

Sourcemodule Class = Base.Float.Class

Excluding nan the floating-point "number line" looks like:

Sourceval classify : t -> Class.t @@ portable [@@zero_alloc]
Sourceval sign : t -> Core.Sign.t @@ portable
  • deprecated [since 2016-01] Replace [sign] with [robust_sign] or [sign_exn]
Sourceval sign_exn : t -> Core.Sign.t @@ portable [@@zero_alloc]

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

Sourceval sign_or_nan : t -> Core.Sign_or_nan.t @@ portable [@@zero_alloc]

The sign of a float, with support for NaN. Both -0. and 0. map to Zero. All NaN values map to Nan. All other values map to Neg or Pos.

These functions construct and destruct 64-bit floating point numbers based on their IEEE representation with a sign bit, an 11-bit non-negative (biased) exponent, and a 52-bit non-negative mantissa (or significand). See Wikipedia for details of the encoding.

In particular, if 1 <= exponent <= 2046, then:

  create_ieee_exn ~negative:false ~exponent ~mantissa
  = (2 ** (exponent - 1023)) * (1 + ((2 ** -52) * mantissa))
Sourceval create_ieee_exn : negative:bool -> exponent:int -> mantissa:Core.Int63.t -> t @@ portable
Sourceval ieee_negative : t -> bool @@ portable
Sourceval ieee_exponent : t -> int @@ portable
Sourceval ieee_mantissa : t -> Core.Int63.t @@ portable
Sourceval select : bool -> t -> t -> t @@ portable [@@zero_alloc]

Branchless, as Bool.select.

Sourceval first_non_nan : t -> t -> t @@ portable [@@zero_alloc]

Branchless.

Sourceval to_bits : t -> int64# @@ portable
Sourceval of_bits : int64# -> t @@ portable

Arrays

module type Array_getters_and_setters := sig ... end
Sourcemodule type Array = sig ... end
Sourcemodule Array : sig ... end

The Array module provides some helpers that wrap common operations on floatarrays with appropriate boxing or unboxing to work with float#.

Sourcemodule Polymorphic_array_helpers : Array_getters_and_setters with type t := float array and type elt := float#

The Polymorphic_array_helpers module provides some helpers that wrap common operations on float arrays with appropriate boxing or unboxing to work with float#.

Sourcemodule type Ref = sig ... end
Sourcemodule Ref : sig ... end

The moral equivalent of t option implemented in-place with is_none as is_nan.

By design, we can do math on this type and propagate NaN (none) status.

Sourcemodule Option : sig ... end
Sourcemodule Stable : sig ... end