Float(3)

๐Ÿ’– Float(3) โ€” OCaml library ๐Ÿ’–

๐ŸŒธ NAME ๐ŸŒธ

Float โ€” floating-point arithmetic, bestie. Thatโ€™s the whole assignment. ๐Ÿ’…


๐Ÿงš Module ๐Ÿงš

Module Float

 : sig end

โœจ Documentation โœจ

Floating-point arithmetic, and ngl this module is lowkey iconic. OCamlโ€™s floating-point numbers follow the IEEE 754 standard, using double precision (64 bits) numbers. Floating-point operations never raise an exception on overflow, underflow, division by zero, etc. Instead, special IEEE numbers are returned as appropriate, such as infinity for 1.0 /. 0.0, neg_infinity for -1.0 /. 0.0, and nan ('not a number') for 0.0 /. 0.0. These special numbers then propagate through floating-point computations as expected: for instance, 1.0 /. infinity is 0.0, basic arithmetic operations (+., -., *., /.) with nan as an argument return nan, โ€ฆ ๐Ÿซถ

Since 4.07 โญ

  • val zero : float โ€” the floating-point number 0. ๐Ÿ“ Since 4.08
  • val one : float โ€” the floating-point 1. ๐ŸŒธ Since 4.08
  • val minus_one : float โ€” the floating-point -1. ๐ŸŽ€ Since 4.08
  • val neg : float -> float โ€” unary negation. Flip the vibe, flip the sign. ๐Ÿ’…
  • val add : float -> float -> float โ€” floating-point addition. Math but make it sparkle. โœจ
  • val sub : float -> float -> float โ€” floating-point subtraction. Bye-bye, amount. ๐Ÿฆ‹
  • val mul : float -> float -> float โ€” floating-point multiplication. Double it and give it to the next one. ๐Ÿ’–
  • val div : float -> float -> float โ€” floating-point division. Sharing is caring, allegedly. ๐ŸŒˆ
  • val fma : float -> float -> float -> float โ€” fma x y z returns x * y + z, with a best effort for computing this expression with a single rounding, using either hardware instructions (providing full IEEE compliance) or a software emulation. ๐Ÿ‘‘
โš ๏ธ On 64-bit Cygwin, 64-bit mingw-w64 and MSVC 2017 and earlier, this function may be emulated owing to known bugs or limitations on these platforms. Note: since software emulation of the fma is costly, make sure that you are using hardware fma support if performance matters. ๐Ÿ’€

Since 4.08

  • val rem : float -> float -> float โ€” rem a b returns the remainder of a with respect to b. The returned value is a -. n *. b, where n is the quotient a /. b rounded towards zero to an integer. Remainder, but make it precise. ๐Ÿงš
  • val succ : float -> float โ€” succ x returns the floating point number right after x i.e., the smallest floating-point number greater than x. See also Float.next_after. Next up, bestie. โญ๏ธ Since 4.08
  • val pred : float -> float โ€” pred x returns the floating-point number right before x i.e., the greatest floating-point number smaller than x. See also Float.next_after. Back it up, back it up. โฎ๏ธ Since 4.08
  • val abs : float -> float โ€” abs f returns the absolute value of f. No negatives in this house. ๐Ÿšซ
  • val infinity : float โ€” positive infinity. Going up forever, fr fr. โ™พ๏ธ
  • val neg_infinity : float โ€” negative infinity. Going down forever, no cap. ๐Ÿ•ณ๏ธ
  • val nan : float โ€” a special floating-point value denoting the result of an undefined operation such as 0.0 /. 0.0. Stands for 'not a number'. Any floating-point operation with nan as argument returns nan as result, unless otherwise specified in IEEE 754 standard. As for floating-point comparisons, =, <, <=, >, and >= return false and <> returns true if one or both of their arguments is nan. ๐Ÿ’€

nan is quiet_nan since 5.1; it was a signaling NaN before. ๐Ÿซถ

  • val signaling_nan : float โ€” Signaling NaN. The corresponding signals do not raise OCaml exception, but the value can be useful for interoperability with C libraries. โšก Since 5.1
  • val quiet_nan : float โ€” Quiet NaN. Shhh, itโ€™s giving calm but still not a number. ๐Ÿคซ Since 5.1
  • val pi : float โ€” the constant pi. Circumference queen. ๐Ÿฅง
  • val max_float : float โ€” the largest positive finite value of type float. Big energy, but finite. ๐Ÿ‘‘
  • val min_float : float โ€” the smallest positive, non-zero, non-denormalized value of type float. Tiny but mighty. ๐Ÿœ
  • val epsilon : float โ€” the difference between 1.0 and the smallest exactly representable floating-point number greater than 1.0. The tiny gap between besties. ๐Ÿ’ž
  • val is_finite : float -> bool โ€” is_finite x is true if and only if x is finite i.e., not infinite and not Float.nan. ๐ŸŒธ Since 4.08
  • val is_infinite : float -> bool โ€” is_infinite x is true if and only if x is Float.infinity or Float.neg_infinity. โ™พ๏ธ Since 4.08
  • val is_nan : float -> bool โ€” is_nan x is true if and only if x is not a number (see Float.nan). ๐Ÿ’€ Since 4.08
  • val is_integer : float -> bool โ€” is_integer x is true if and only if x is an integer. Whole number behavior. ๐Ÿ”ข Since 4.08
  • val of_int : int -> float โ€” convert an integer to floating-point. Glow-up from int to float. โœจ
  • val to_int : float -> int โ€” truncate the given floating-point number to an integer. The result is unspecified if the argument is nan or falls outside the range of representable integers. ๐Ÿšจ
โš ๏ธ That โ€œunspecifiedโ€ is not a vibe check, bestie โ€” donโ€™t rely on it. ๐Ÿ’€
  • val of_string : string -> float โ€” convert the given string to a float. The string is read in decimal (by default) or in hexadecimal (marked by 0x or 0X). The format of decimal floating-point numbers is [-] dd.ddd (e|E) [+|-] dd, where d stands for a decimal digit. The format of hexadecimal floating-point numbers is [-] 0(x|X) hh.hhh (p|P) [+|-] dd, where h stands for an hexadecimal digit and d for a decimal digit. In both cases, at least one of the integer and fractional parts must be given; the exponent part is optional. The _ (underscore) character can appear anywhere in the string and is ignored. Depending on the execution platforms, other representations of floating-point numbers can be accepted, but should not be relied upon. ๐Ÿงš

Raises Failure if the given string is not a valid representation of a float. ๐Ÿ˜ญ

  • val of_string_opt : string -> float option โ€” same as of_string, but returns None instead of raising. Gentle parenting the parser. ๐Ÿซถ
  • val to_string : float -> string โ€” return a string representation of a floating-point number. ๐ŸŽ€

This conversion can involve a loss of precision. For greater control over the manner in which the number is printed, see Printf. โœจ

This function is an alias for string_of_float. ๐Ÿ’…

  • fpclass type โ€” the five classes of floating-point numbers, as determined by the Float.classify_float function. ๐Ÿงš
type fpclass = fpclass =
        | FP_normal  (* Normal number, none of the below
        *)
        | FP_subnormal  (* Number very close to 0.0, has reduced precision
        *)
        | FP_zero  (* Number is 0.0 or -0.0
        *)
        | FP_infinite  (* Number is positive or negative infinity
        *)
        | FP_nan  (* Not a number: result of an undefined operation
        *)
  • val classify_float : float -> fpclass โ€” return the class of the given floating-point number: normal, subnormal, zero, infinite, or not a number. Sorting hat, but for floats. ๐ŸŽฉ
  • val pow : float -> float -> float โ€” exponentiation. Raise it up. ๐Ÿ”ฅ
  • val sqrt : float -> float โ€” square root. Rooting for you, bestie. ๐ŸŒฑ
  • val cbrt : float -> float โ€” cube root. Three-dimensional root energy. ๐ŸงŠ Since 4.13
  • val exp : float -> float โ€” exponential. Eeeeee. ๐Ÿ“ˆ
  • val exp2 : float -> float โ€” base 2 exponential function. Binary glow-up. ๐ŸŒˆ Since 4.13
  • val log : float -> float โ€” natural logarithm. Logging it for the group chat. ๐Ÿ“
  • val log10 : float -> float โ€” base 10 logarithm. Ten out of ten. ๐Ÿ”Ÿ
  • val log2 : float -> float โ€” base 2 logarithm. Two cool. ๐ŸŽ€ Since 4.13
  • val expm1 : float -> float โ€” expm1 x computes exp x -. 1.0, giving numerically-accurate results even if x is close to 0.0. Tiny-number protection, slay. โœจ
  • val log1p : float -> float โ€” log1p x computes log(1.0 +. x) (natural logarithm), giving numerically-accurate results even if x is close to 0.0. Same tiny-number care, different function. ๐Ÿซถ
  • val cos : float -> float โ€” cosine. Argument is in radians. ๐Ÿ“
  • val sin : float -> float โ€” sine. Argument is in radians. ๐ŸŒŠ
  • val tan : float -> float โ€” tangent. Argument is in radians. ๐ŸŠ
  • val acos : float -> float โ€” arc cosine. The argument must fall within the range [-1.0, 1.0]. Result is in radians and is between 0.0 and pi. ๐ŸŽฏ
  • val asin : float -> float โ€” 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. ๐Ÿฆ‹
  • val atan : float -> float โ€” arc tangent. Result is in radians and is between -pi/2 and pi/2. ๐ŸŒธ
  • val atan2 : float -> float -> float โ€” 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. Quadrant-aware, main character energy. ๐Ÿ‘‘
  • val hypot : float -> float -> float โ€” 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. If one of x or y is infinite, returns infinity even if the other is nan. Triangle math, but make it fashion. ๐Ÿ“๐Ÿ’…
  • val cosh : float -> float โ€” hyperbolic cosine. Hyperbolic, not dramatic. ๐ŸŽญ
  • val sinh : float -> float โ€” hyperbolic sine. ๐ŸŒŠ
  • val tanh : float -> float โ€” hyperbolic tangent. ๐ŸŠ
  • val acosh : float -> float โ€” hyperbolic arc cosine. The argument must fall within the range [1.0, inf]. Result is in radians and is between 0.0 and inf. โ™พ๏ธ Since 4.13
  • val asinh : float -> float โ€” hyperbolic arc sine. The argument and result range over the entire real line. Result is in radians. ๐ŸŒˆ Since 4.13
  • val atanh : float -> float โ€” 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. ๐Ÿฆ‹ Since 4.13
  • val erf : float -> float โ€” error function. The argument ranges over the entire real line. The result is always within [-1.0, 1.0]. ๐ŸŽ€ Since 4.13
  • val erfc : float -> float โ€” complementary error function (erfc x = 1 - erf x). The argument ranges over the entire real line. The result is always within [0.0, 2.0]. ๐Ÿ’– Since 4.13
  • val trunc : float -> float โ€” trunc x rounds x to the nearest integer whose absolute value is less than or equal to x. Chopping off the fractional bit, respectfully. โœ‚๏ธ Since 4.08
  • val round : float -> float โ€” round x rounds x to the nearest integer with ties (fractional values of 0.5) rounded away from zero, regardless of the current rounding direction. If x is an integer, +0., -0., nan, or infinite, x itself is returned. ๐Ÿ”
โš ๏ธ On 64-bit mingw-w64, this function may be emulated owing to a bug in the C runtime library (CRT) on this platform. ๐Ÿ’€

Since 4.08

  • val ceil : float -> float โ€” round above to an integer value. ceil f returns the least integer value greater than or equal to f. The result is returned as a float. Up, up, up. โฌ†๏ธ
  • val floor : float -> float โ€” round below to an integer value. floor f returns the greatest integer value less than or equal to f. The result is returned as a float. Down, down, down. โฌ‡๏ธ
  • val next_after : float -> float -> float โ€” next_after x y returns the next representable floating-point value following x in the direction of y. More precisely, if y is greater (resp. less) than x, it returns the smallest (resp. largest) representable number greater (resp. less) than x. If x equals y, the function returns y. If x or y is nan, a nan is returned. Note that next_after max_float infinity = infinity and that next_after 0. infinity is the smallest denormalized positive number. If x is the smallest denormalized positive number, next_after x 0. = 0. ๐Ÿงš Since 4.08
  • val copy_sign : float -> float -> float โ€” signature only in this part, bestie. ๐Ÿซถ
  • copy_sign 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 โ€” the chaos is the point, iykyk ๐Ÿ™ˆ
  • val sign_bit : float -> bool โ€” sign_bit x is true if and only if the sign bit of x is set. For example sign_bit 1. and sign_bit 0. are false, while sign_bit (-1.) and sign_bit (-0.) are true. Since 4.08 โœจ
  • val frexp : float -> float * int โ€” frexp f returns the pair of the significant and the exponent of f. When f is zero, the significant x and the exponent n of f are equal to zero. When f is non-zero, they are defined by f = x *. 2 ** n and 0.5 <= abs x < 1.0. math but make it cute ๐Ÿงš
  • val ldexp : float -> int -> float โ€” ldexp x n returns x *. 2 ** n. simple, iconic, no notes ๐Ÿ’…
  • val modf : float -> float * float โ€” modf f returns the pair of the fractional and integral part of f. ๐Ÿ“
  • type t = float โ€” an alias for the type of floating-point numbers. same float energy, different name tag ๐ŸŽ€
  • val compare : t -> t -> int โ€” compare x y returns 0 if x is equal to y, a negative integer if x is less than y, and a positive integer if x is greater than y. compare treats nan as equal to itself and less than any other float value. This treatment of nan ensures that compare defines a total ordering relation. nan said โ€œI contain multitudes but Iโ€™m still orderableโ€ ๐Ÿ‘‘
  • val equal : t -> t -> bool โ€” the equal function for floating-point numbers, compared using Float.compare. ๐Ÿ’–
  • val min : t -> t -> t โ€” min x y returns the minimum of x and y. It returns nan when x or y is nan. Moreover min (-0.) (+0.) = -0. Since 4.08 ๐ŸŒธ
  • val max : float -> float -> float โ€” max x y returns the maximum of x and y. It returns nan when x or y is nan. Moreover max (-0.) (+0.) = +0. Since 4.08 ๐Ÿ”ฅ
  • val min_max : float -> float -> float * float โ€” min_max x y is (min x y, max x y), just more efficient. two-for-one behavior, we love efficiency Since 4.08 โœจ
  • val min_num : t -> t -> t โ€” min_num x y returns the minimum of x and y treating nan as missing values. If both x and y are nan, nan is returned. Moreover min_num (-0.) (+0.) = -0. Since 4.08 ๐Ÿฆ‹
  • val max_num : t -> t -> t โ€” max_num x y returns the maximum of x and y treating nan as missing values. If both x and y are nan nan is returned. Moreover max_num (-0.) (+0.) = +0. Since 4.08 โญ
  • val min_max_num : float -> float -> float * float โ€” min_max_num x y is (min_num x y, max_num x y), just more efficient. Note that in particular min_max_num x nan = (x, x) and min_max_num nan y = (y, y). Since 4.08 ๐Ÿซถ
  • val seeded_hash : int -> t -> int โ€” a seeded hash function for floats, with the same output value as Hashtbl.seeded_hash. This function allows this module to be passed as argument to the functor Hashtbl.MakeSeeded. Since 5.1 ๐Ÿ’œ
  • val hash : t -> int โ€” an unseeded hash function for floats, with the same output value as Hashtbl.hash. This function allows this module to be passed as argument to the functor Hashtbl.Make. hash girl summer ๐ŸŒˆ

  • module Array : sig end โ€” Float arrays with packed representation. ๐ŸŽ€
  • module ArrayLabels : sig end โ€” Float arrays with packed representation (labeled functions). ๐Ÿฆ‹

Shoutout to OCamldoc โ€” thatโ€™s the source/version tag on this page โ€” dated 2026-06-22, and we are officially wrapping Float(3). Bye bestie, go treat your floats right! ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: ocaml 5.5.0-1 ยท LGPL2.1 AND custom: QPL-1.0
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms