Trait ieee754::Ieee754 [] [src]

pub trait Ieee754: Copy + PartialEq + PartialOrd {
    type Bits;
    type Exponent;
    type Signif;
    fn next(self) -> Self;
    fn prev(self) -> Self;
    fn bits(self) -> Self::Bits;
    fn from_bits(x: Self::Bits) -> Self;
    fn exponent_bias(self) -> Self::Exponent;
    fn decompose(self) -> (bool, Self::Exponent, Self::Signif);
    fn recompose(sign: bool, expn: Self::Exponent, signif: Self::Signif) -> Self;

    fn upto(self, lim: Self) -> Iter<Self> { ... }
}

Types that are IEEE754 floating point numbers.

Associated Types

type Bits

A type that represents the raw bits of Self.

type Exponent

A type large enough to store the exponent of Self.

type Signif

A type large enough to store the significand of Self.

Required Methods

fn next(self) -> Self

Return the next value after self.

Calling this on NaN will yield nonsense.

fn prev(self) -> Self

Return the previous value before self.

Calling this on NaN will yield nonsense.

fn bits(self) -> Self::Bits

View self as a collection of bits.

fn from_bits(x: Self::Bits) -> Self

View a collections of bits as a floating point number.

fn exponent_bias(self) -> Self::Exponent

Get the bias of the stored exponent.

fn decompose(self) -> (bool, Self::Exponent, Self::Signif)

Break self into the three constituent parts of an IEEE754 float.

The exponent returned is the raw bits, use exponent_bias to compute the offset required.

fn recompose(sign: bool, expn: Self::Exponent, signif: Self::Signif) -> Self

Create a Self out of the three constituent parts of an IEEE754 float.

The exponent should be the raw bits, use exponent_bias to compute the offset required.

Provided Methods

fn upto(self, lim: Self) -> Iter<Self>

Iterate over each value of T in [self, lim].

Panics

Panics if self > lim, or if either are NaN.

Example

use ieee754::Ieee754;

// there are 840 single-precision floats in between 1.0 and 1.0001
// (inclusive).
assert_eq!(1_f32.upto(1.0001).count(), 840);

Implementors