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, and any operation with nan as argument returns nan as result.
Round the given float to an integer value. floor f returns the greatest integer value less than or equal to f. ceil f returns the least integer value greater than or equal to f.
round x rounds x to the nearest integral floating-point (the nearest of floor x and ceil x). In case the fraction of x is exactly 0.5, we round away from 0. : round 1.5 is 2. but round (-3.5) is -4..
round_to_string ~digits:d x will return a string representation of x -- in base 10 -- rounded to d digits after the decimal point. By default, digits is 0, we round to the nearest integer.
This is strictly a convenience function for simple end-user printing and you should not rely on its behavior. One possible implementation is to rely on C `sprintf` internally, which means:
no guarantee is given on the round-at-half behavior; it may not be consistent with round or round_to_int
round_to_string ~digits:0 3. may return "3" instead of "3." as string_of_float would
no guarantee is given on the behavior for abusively high number of digits precision; for example round_to_string ~digits:max_int x may return the empty string.
is_finite f returns true if f is not nan or +/- infinity, false otherwise.
since 2.0
Constants
Special float constants. It may not be safe to compare directly with these, as they have multiple internal representations. Instead use the is_special, is_nan, etc. tests
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. As for floating-point comparisons, =, <, <=, > and >= return false and <> returns true if one or both of their arguments is nan.
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 <= x < 1.0.