Module core::num::dec2flt::rawfp [] [src]

Unstable (dec2flt)

: 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. 1.101100...11 * 2^m
  2. 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.


use prelude::v1::*;
use u32;
use cmp::Ordering::{Less, Equal, Greater};
use ops::{Mul, Div, Neg};
use fmt::{Debug, LowerExp};
use mem::transmute;
use num::diy_float::Fp;
use num::FpCategory::{Infinite, Zero, Subnormal, Normal, Nan};
use num::Float;
use num::dec2flt::num::{self, Big};
use num::dec2flt::table;


Unpacked [Unstable]


RawFloat [Unstable]

A helper trait to avoid duplicating basically all the conversion code for f32 and f64.


big_to_fp [Unstable]

Approximate a bignum with an Fp. Rounds within 0.5 ULP with half-to-even.

encode_normal [Unstable]

Inverse of RawFloat::unpack() for normalized numbers. Panics if the significand or exponent are not valid for normalized numbers.

encode_subnormal [Unstable]

Construct the subnormal. A mantissa of 0 is allowed and constructs zero.

fp_to_float [Unstable]

Convert an Fp to the closest f64. Only handles number that fit into a normalized f64.

next_float [Unstable]
prev_float [Unstable]

Find the largest floating point number strictly smaller than the argument. Does not handle subnormals, zero, or exponent underflow.

round_normal [Unstable]

Round the 64-bit significand to 53 bit with half-to-even. Does not handle exponent overflow.