Page
Library
Module
Module type
Parameter
Class
Class type
Source
Floatml.F128SourceIEEE 754 binary128, quadruple precision. The bit pattern is a (low, high) pair of 64-bit words.
A concrete floating-point value (every bit pattern, NaNs included).
Total width in bits (eb + sb): 16, 32, 64 or 128.
Width of the exponent field (eb): 5, 8, 11 or 15.
Width of the significand (sb), counting the hidden bit: 11, 24, 53 or 113. Note this is one more than the number of stored mantissa bits.
Parse a floating-point literal, correctly rounded to nearest-ties-to-even (IEEE 754 convertFromDecimalCharacter).
Accepted: an optionally signed decimal literal with optional fraction and exponent ("3.5", "1e-10", ".5", "+1.0"), an optionally signed hexadecimal literal ("0x1.8p1"), or one of "inf", "nan" and "snan" with an optional -. Leading or trailing whitespace is not accepted, and neither is any trailing text.
Round an OCaml float (binary64) to this precision, ties to even. Exact for F64 and F128.
Round an arbitrary-precision integer to this precision, ties to even. Unlike int2float the argument is a mathematical integer rather than the contents of a bit-vector, so it is not reduced to any width: a magnitude too large for the format gives an infinity. Zero gives +0.
of_z (Z.of_int 200) is 200., where int2float (Z.of_int 200) Int8 m ~signed:true is -56. — the same 200 read as the eight bits of a signed bit-vector.
Reinterpret a raw interchange-format bit pattern as a float. Only the low eb+sb bits are used, so for F16 — whose bits is a full-width int — the argument is narrowed to 16 bits and to_bits does not return it unchanged.
Nearest OCaml float (binary64) to t, for display. Lossy for F128 and exact for the smaller formats.
Each of these is exactly representable at every precision.
The canonical quiet NaN — the one every operation here yields when it produces a NaN, so equal nan (div zero zero) holds. Note this is not of_float Float.nan: OCaml's Float.nan carries a payload of 1.
Arithmetic rounds to nearest-ties-to-even (the IEEE 754 default mode).
IEEE 754 remainder: x - y*n where n is the integer nearest x/y (ties to even). This is not C fmod; e.g. rem (-5.) 3. = 1..
C fmod — and so Rust's % on floats, and LLVM frem: the remainder x - y*n where n is x/y truncated toward zero. Distinct from rem, which rounds x/y to nearest: fmod (-5.) 3. = -2. where rem (-5.) 3. = 1..
IEEE 754 minNum. If one argument is NaN the other is returned. On +0 and -0 the first argument is returned, so min is deterministic but not commutative on zeros; minimum is.
copy_sign x y is x carrying the sign bit of y (IEEE 754 copySign, Rust's copysign). Applies to NaN like any other value.
IEEE 754-2019 minimum: like min, but NaN propagates and -0 is treated as smaller than +0, which makes it commutative everywhere.
IEEE 754 nextUp: the least value greater than t, one bit pattern away. next_up neg_infinity is the most negative finite value and next_up infinity is infinity; NaN maps to NaN.
IEEE 754 roundToIntegral: round to an integral value in the given direction, preserving the format.
IEEE 754 semantics: NaN is unordered (all comparisons with it are false), and +0 = -0.
Alias for bits_equal. With compare and hash this is the total, structural triple, for use as a hash-table or Map key. It is not eq: equal nan nan is true and equal zero neg_zero is false.
Bitwise equality: two values are equal iff their bit patterns match (so bits_equal nan nan can hold, and bits_equal +0 -0 does not).
The IEEE 754 totalOrder predicate as a comparison returning -1, 0 or 1: a genuine total order on bit patterns, suitable as a Map/Set key. It is not lt/eq: NaNs are ordered rather than unordered (-NaN below -inf, +NaN above +inf), and -0 sorts below +0. So compare x y = 0 holds exactly when bits_equal does, not when eq does.
A negative non-NaN value, -0 included. This is not IEEE 754 isSignMinus, which is true for a negative NaN.
IEEE 754 convertToInteger in the given direction: round to a signed or unsigned integer of the given width. None if t is NaN or infinite, or if the rounded value is out of range for the target type.
IEEE 754 convertFromInt: round an integer, read at the given width and signedness, to a float.
Total: the argument is the bit-vector's contents, so it is first reduced modulo 2^width and then read at that width. int2float (Z.of_int 200) Int8 m ~signed:true is therefore -56., and int2float Z.minus_one Int8 m ~signed:false is 255..
All three produce the same exact decimal: enough digits that of_string reads the value back unchanged, at every precision. Infinities print as "+Inf" and "-Inf", and any NaN as "NaN" — all of which of_string accepts, though a NaN payload does not survive the round trip.