Stdlib.Float(3)
πΈ NAME πΈ
okay so bestie, this is Stdlib.Float(3) β an OCaml library page β and the NAME is Stdlib.Float, which is literally just no description. iconic of it to serve absolute mystery. π
π Module π
the module vibe is exactly this:
Module Float : (module Stdlib__Float)
β¨ Documentation β¨
val zero : floatβ the floating-point number0. β¨ Since 4.08val one : floatβ the floating-point1. β¨ Since 4.08val minus_one : floatβ the floating-point-1. β¨ Since 4.08val neg : float -> floatβ unary negation.val add : float -> float -> floatβ floating-point addition.val sub : float -> float -> floatβ floating-point subtraction.val mul : float -> float -> floatβ floating-point multiplication.val div : float -> float -> floatβ floating-point division.val fma : float -> float -> float -> floatβfma x y zreturnsx * 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 thefmais costly, make sure that you are using hardwarefmasupport if performance matters. Since 4.08val rem : float -> float -> floatβrem a breturns the remainder ofawith respect tob. The returned value isa -. n *. b, wherenis the quotienta /. brounded towards zero to an integer.val succ : float -> floatβsucc xreturns the floating point number right afterx, i.e., the smallest floating-point number greater thanx. See alsoFloat.next_after. β¨ Since 4.08val pred : float -> floatβpred xreturns the floating-point number right beforex, i.e., the greatest floating-point number smaller thanx. See alsoFloat.next_after. β¨ Since 4.08val abs : float -> floatβabs freturns the absolute value off.val infinity : floatβ positive infinity.val neg_infinity : floatβ negative infinity.val nan : floatβ a special floating-point value denoting the result of an undefined operation such as0.0 /. 0.0. Stands for 'not a number'. Any floating-point operation withnanas argument returnsnanas result, unless otherwise specified in IEEE 754 standard. As for floating-point comparisons,=,<,<=,>, and>=returnfalseand<>returnstrueif one or both of their arguments isnan.nanisquiet_nansince 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.1val quiet_nan : floatβ quiet NaN. β¨ Since 5.1val pi : floatβ the constantpi.val max_float : floatβ the largest positive finite value of typefloat.val min_float : floatβ the smallest positive, non-zero, non-denormalized value of typefloat.val epsilon : floatβ the difference between1.0and the smallest exactly representable floating-point number greater than1.0.val is_finite : float -> boolβis_finite xistrueif and only ifxis finite, i.e., not infinite and notFloat.nan. β¨ Since 4.08val is_infinite : float -> boolβis_infinite xistrueif and only ifxisFloat.infinityorFloat.neg_infinity. β¨ Since 4.08val is_nan : float -> boolβis_nan xistrueif and only ifxis not a number (seeFloat.nan). β¨ Since 4.08val is_integer : float -> boolβis_integer xistrueif and only ifxis an integer. β¨ Since 4.08val of_int : int -> floatβ convert an integer to floating-point.val to_int : float -> intβ truncate the given floating-point number to an integer. The result is unspecified if the argument isnanor falls outside the range of representable integers.val of_string : string -> floatβ convert the given string to a float. The string is read in decimal (by default) or in hexadecimal (marked by0xor0X). The format of decimal floating-point numbers is[-] dd.ddd (e|E) [+|-] dd, wheredstands for a decimal digit. The format of hexadecimal floating-point numbers is[-] 0(x|X) hh.hhh (p|P) [+|-] dd, wherehstands for an hexadecimal digit anddfor 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. RaisesFailureif the given string is not a valid representation of a float.val of_string_opt : string -> float optionβ same asof_string, but returnsNoneinstead of raising.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, seePrintf. This function is an alias forstring_of_float.type fpclassβ the five classes of floating-point numbers, as determined by theFloat.classify_floatfunction. the type itself is literally:
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.val pow : float -> float -> floatβ exponentiation.val sqrt : float -> floatβ square root.val cbrt : float -> floatβ cube root. β¨ Since 4.13val exp : float -> floatβ exponential.val exp2 : float -> floatβ base 2 exponential function. β¨ Since 4.13val log : float -> floatβ natural logarithm.val log10 : float -> floatβ base 10 logarithm.val log2 : float -> floatβ base 2 logarithm. β¨ Since 4.13val expm1 : float -> floatβexpm1 xcomputesexp x -. 1.0, giving numerically-accurate results even ifxis close to0.0.val log1p : float -> floatβlog1p xcomputeslog(1.0 +. x)(natural logarithm), giving numerically-accurate results even ifxis close to0.0.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 between0.0andpi.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/2andpi/2.val atan : float -> floatβ arc tangent. Result is in radians and is between-pi/2andpi/2.val atan2 : float -> float -> floatβatan2 y xreturns the arc tangent ofy /. x. The signs ofxandyare used to determine the quadrant of the result. Result is in radians and is between-piandpi.val hypot : float -> float -> floatβhypot x yreturnssqrt(x *. x +. y *. y), that is, the length of the hypotenuse of a right-angled triangle with sides of lengthxandy, or, equivalently, the distance of the point(x,y)to origin. If one ofxoryis infinite, returnsinfinityeven if the other isnan.val cosh : float -> floatβ hyperbolic cosine.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 between0.0andinf. β¨ Since 4.13val asinh : float -> floatβ hyperbolic arc sine. The argument and result range over the entire real line. Result is in radians. β¨ Since 4.13val 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.13val erf : float -> floatβ error function. The argument ranges over the entire real line. The result is always within[-1.0, 1.0]. β¨ Since 4.13val 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.13val trunc : float -> floatβtrunc xroundsxto the nearest integer whose absolute value is less than or equal tox. β¨ Since 4.08val round : float -> floatβround xroundsxto the nearest integer with ties (fractional values of0.5) rounded away from zero, regardless of the current rounding direction. Ifxis an integer,+0.,-0.,nan, or infinite,xitself 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.08val ceil : float -> floatβ round above to an integer value.ceil freturns the least integer value greater than or equal tof. The result is returned as a float.val floor : float -> floatβ round below to an integer value.floor freturns the greatest integer value less than or equal tof. The result is returned as a float.val next_after : float -> float -> floatβnext_after x yreturns the next representable floating-point value followingxin the direction ofy. More precisely, ifyis greater (resp. less) thanx, it returns the smallest (resp. largest) representable number greater (resp. less) thanx. Ifxequalsy, the function returnsy. Ifxoryisnan, ananis returned. Note thatnext_after max_float infinity = infinityand thatnext_after 0. infinityis the smallest denormalized positive number. Ifxis the smallest denormalized positive number,next_after x 0. = 0. β¨ Since 4.08val copy_sign : float -> float -> floatβcopy_sign x yreturns a float whose absolute value is that ofxand whose sign is that ofy. Ifxisnan, returnsnan. Ifyisnan, returns eitherxor-. x, but it is not specified which.val sign_bit : float -> boolβsign_bit xistrueif and only if the sign bit ofxis set. For examplesign_bit 1.andsign_bit 0.arefalsewhilesign_bit (-1.)andsign_bit (-0.)aretrue. β¨ Since 4.08val frexp : float -> float * intfrexpβfrexp fhands you back the pair of the significant and the exponent off. π Whenfis zero, the significantxand the exponentnoffare both equal to zero. Whenfis non-zero, they're defined byf = x *. 2 ** nand0.5 <= abs x < 1.0. iconic math, no notes β¨val ldexp : float -> int -> floatβldexp x ngives youx *. 2 ** n. that's it, that's the whole vibe π¦val modf : float -> float * floatβmodf freturns the pair of the fractional and integral part off. split it like a friendship bracelet πtype t = floatβ literally just an alias for the type of floating-point numbers. doing the same job under a cuter name, iykyk πval compare : t -> t -> intβcompare x yreturns0ifxis equal toy, a negative integer ifxis less thany, and a positive integer ifxis greater thany. ok now the important part πcomparetreatsnanas equal to itself and less than any other float value. that treatment ofnanis what makescomparedefine a total ordering relation β the whole thing stays consistent, periodt πval equal : t -> t -> boolβ theequalfunction for floating-point numbers, compared usingFloat.compare. that's the method it's committed to π«Άval min : t -> t -> tβmin x yreturns the minimum ofxandy. it returnsnanwhenxoryisnan. and as a bonus:min (-0.) (+0.) = -0.π
Since 4.08
val max : float -> float -> floatβmax x yreturns the maximum ofxandy. it returnsnanwhenxoryisnan. and moreovermax (-0.) (+0.) = +0.π«
Since 4.08
val min_max : float -> float -> float * floatβmin_max x yis(min x y, max x y), just more efficient. two birds, one call, ate π
Since 4.08
val min_num : t -> t -> tβmin_num x yreturns the minimum ofxandytreatingnanas missing values. if bothxandyarenan,nanis returned. moreovermin_num (-0.) (+0.) = -0.πΈ
Since 4.08
val max_num : t -> t -> tβmax_num x yreturns the maximum ofxandytreatingnanas missing values. if bothxandyarenan,nanis returned. moreovermax_num (-0.) (+0.) = +0.π₯
Since 4.08
val min_max_num : float -> float -> float * floatβmin_max_num x yis(min_num x y, max_num x y), just more efficient. and note these little gems in particular:min_max_num x nan = (x, x)andmin_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 asHashtbl.seeded_hash. the whole point is that it lets this module be passed as an argument to the functorHashtbl.MakeSeeded. passing modules around like notes in class fr fr π
Since 5.1
val hash : t -> intβ an unseeded hash function for floats, with the same output value asHashtbl.hash. this one lets this module be passed as an argument to the functorHashtbl.Make. same energy, no seed πmodule Array : sig endβ Float arrays with packed representation. fancy storage, minimal drama π§module ArrayLabels : sig endβ Float arrays with packed representation (labeled functions). same slay, but with labels π
that's the whole page bestie, we made it to the end π«Ά this little masterpiece was served up by OCamldoc, dated 2026-06-22, and it lives at Stdlib.Float(3) in the section-3 lineup β go forth and float responsibly πβ¨
π¦ 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