equal to infinity
equal to infinity
equal to neg_infinity
equal to neg_infinity
See Robust_compare
The difference between 1.0 and the smallest exactly representable floating-point number greater than 1.0. That is:
epsilon_float = (one_ulp `Up 1.0) -. 1.0
This gives the relative accuracy of type t
, in the sense that for numbers on the
order of x
, the roundoff error is on the order of x *. float_epsilon
.
See also: http://en.wikipedia.org/wiki/Machine_epsilon
min_positive_subnormal_value = 2 ** -1074
min_positive_normal_value = 2 ** -1022
An order-preserving bijection between all floats except for nans, and all int64s
with absolute value smaller than or equal to 2**63 - 2**52
.
Note both 0. and -0. map to 0L.
returns nan
if the absolute value of the argument is too large
returns nan
if the absolute value of the argument is too large
includes positive and negative Float.infinity
Like to_string
, but guaranteed to be round-trippable.
It usually yields as few significant digits as possible. That is, it won't print
3.14
as 3.1400000000000001243
. The only exception is that occasionally it will
output 17 significant digits when the number can be represented with just 16 (but
not 15 or less) of them.
Pretty print float, for example to_string_hum ~decimals:3 1234.1999 = "1_234.200"
to_string_hum ~decimals:3 ~strip_zero:true 1234.1999 = "1_234.2"
. No delimiters
are inserted to the right of the decimal.
int_pow x n
computes x ** float n
via repeated squaring. It is generally much
faster than **
.
Note that int_pow x 0
always returns 1.
, even if x = nan
. This
coincides with x ** 0.
and is intentional.
For n >= 0
the result is identical to an n-fold product of x
with itself under
*.
, with a certain placement of parentheses. For n < 0
the result is identical
to int_pow (1. /. x) (-n)
.
The error will be on the order of |n|
ulps, essentially the same as if you
perturbed x
by up to a ulp and then exponentiated exactly.
Benchmarks show a factor of 5-10 speedup (relative to **
) for exponents up to
about 1000 (approximately 10ns vs. 70ns). For larger exponents the advantage is
smaller but persists into the trillions. For a recent or more detailed comparison
run the benchmarks.
Depending on context, calling this function might or might not allocate 2 minor
words. Even if called in a way that causes allocation, it still appears faster than
**
.
return the Class.t. Excluding nan the floating-point "number line" looks like:
t Class.t example ^ neg_infinity Infinite neg_infinity | neg normals Normal -3.14 | neg subnormals Subnormal -.2. ** -1023. | (-/+) zero Zero 0. | pos subnormals Subnormal 2. ** -1023. | pos normals Normal 3.14 v infinity Infinite infinity
is_finite t
returns true
iff classify t
is in Normal; Subnormal; Zero;
.
(Formerly sign
) Uses robust comparison (so sufficiently small numbers are mapped
to Zero
). Also maps nan to Zero
. Using this function is weakly discouraged.
The sign of a float. Both -0.
and 0.
map to Zero
. Raises on nan. All other
values map to Neg
or Pos
.
These functions construct and destruct 64-bit floating point numbers based on their IEEE representation with sign bit, 11-bit non-negative (biased) exponent, and 52-bit non-negative mantissa (or significand). See wikipedia for details of the encoding: http://en.wikipedia.org/wiki/Double-precision_floating-point_format.
In particular, if 1 <= exponent <= 2046, then:
create_ieee_exn ~negative:false ~exponent ~mantissa
= 2 ** (exponent - 1023) * (1 + (2 ** -52) * mantissa)
gen_between ~nan ~lower_bound ~upper_bound
creates a Quickcheck generator
producing t
values that are either finite numbers satisfying lower_bound
and
upper_bound
, or NaN values satisfying the nan
distribution. Raises an exception
if no values satisfy lower_bound
and upper_bound
. ~nan:Without
produces no
NaN values, ~nan:With_single
produces only the single NaN value Float.nan
, and
~nan:With_all
produces all valid IEEE NaN values.
pretty-print a float using no more than five characters, using abberviations k, m, g, t.
if on_negative
is not set to `Normal
then the resulting is never over four
chars but upon negative number we either:
"<0"
order_of_magnitude_difference a b
by how many orders of magnitude do a
and b
differ?
The return value is non-negative.
examples:
Unsafe modules and functors that still fully expose the representation for extensibility.