package batteries
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=1bcb27dfbd130eb057561196ef851649
sha512=2a56611b09a5f1cba6457539f8b6bc87a5f2a5454b36cdb39f6e0d6a5dac6db179aab1ba87c74dd49cc41df31a9a96feb349028ea41df7371ecb47f4d9dfafc4
doc/batteries.unthreaded/BatFloat/Safe_float/index.html
Module BatFloat.Safe_float
Operations on floating-point numbers, with exceptions raised in case of error.
The operations implemented in this module are the same as the operations implemented in module Float, with the exception that no operation returns nan, infinity or neg_infinity. In case of overflow, instead of returning infinity or neg_infinity, operations raise exception Number.Overflow. In case of nan, operations raise exception Number.NaN.
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.
For more precision, see The Wikipedia entry on standard IEEE 754.
@documents Safe_float
The type of floating-point numbers.
Floating-point numbers are the default representation of real numbers by OCaml.
Usual operations
Add 1. to a floating number. Note that, as per IEEE 754, if x is a large enough float number, succ x might be equal to x, due to rounding.
Subtract 1. from a floating number. Note that, as per IEEE 754, if x is a large enough float number, pred x might be equal to x, due to rounding.
val operations : t BatNumber.numericOperations specific to floating-point numbers
See atan2.
See atan2.
See atan2.
See atan2.
See atan2.
See atan2.
See tanh.
See tanh.
See floor.
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.
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.
Operations on the internal representation of floating-point numbers
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.
type fpkind = Pervasives.fpclass = Classes of floating point numbers
The five classes of floating-point numbers, as determined by the classify function.
val classify : float -> fpkindReturn the class of the given floating-point number: normal, subnormal, zero, infinite, or not a number.
Boilerplate code
val print : 'a BatInnerIO.output -> t -> unitPrinting