[src] dec2flt:: rawfp
: internal routines only exposed for testing
Bit fiddling on positive IEEE 754 floats. Negative numbers aren't and needn't be handled. Normal floating point numbers have a canonical representation as (frac, exp) such that the value is 2exp * (1 + sum(frac[N-i] / 2i)) where N is the number of bits. Subnormals are slightly different and weird, but the same principle applies.
Here, however, we represent them as (sig, k) with f positive, such that the value is f * 2e. Besides making the "hidden bit" explicit, this changes the exponent by the so-called mantissa shift.
Put another way, normally floats are written as (1) but here they are written as (2):
1.101100...11 * 2^m
1101100...11 * 2^n
We call (1) the fractional representation and (2) the integral representation.
Many functions in this module only handle normal numbers. The dec2flt routines conservatively take the universally-correct slow path (Algorithm M) for very small and very large numbers. That algorithm needs only next_float() which does handle subnormals and zeros.
A helper trait to avoid duplicating basically all the conversion code for
Approximate a bignum with an Fp. Rounds within 0.5 ULP with half-to-even.
Construct the subnormal. A mantissa of 0 is allowed and constructs zero.
Convert an Fp to the closest f64. Only handles number that fit into a normalized f64.
Find the largest floating point number strictly smaller than the argument. Does not handle subnormals, zero, or exponent underflow.
Round the 64-bit significand to 53 bit with half-to-even. Does not handle exponent overflow.