FloatLayout structv0.1.0

Source
The shape of one binary interchange format: where its fields are and what they mean.
pub struct FloatLayout {
    pub precision: uint;
    // private fields
}

Fields

NameTypeDescription
precisionuintThe significand precision, counting the leading bit whether or not it is stored.

Associated functions

Extended80

pub func Extended80() -> FloatLayout

The x87 extended format: sixty-four significand bits with the integer bit written out, in eighty bits.

Returns: the layout of x87's 80-bit extended format

Source

Binary128

pub func Binary128() -> FloatLayout

IEEE binary128: a hundred and thirteen bits of precision.

Returns: the layout of IEEE 754 binary128

Source

Binary256

pub func Binary256() -> FloatLayout

IEEE binary256: two hundred and thirty-seven bits of precision.

Returns: the layout of IEEE 754 binary256

Source

Binary512

pub func Binary512() -> FloatLayout

IEEE binary512: four hundred and eighty-nine bits of precision.

Returns: the layout of IEEE 754 binary512

Source

Methods

SignificandFieldBits

pub func SignificandFieldBits(self: &FloatLayout) -> uint

How many bits the stored significand field has: the precision, less the leading bit unless it is written.

Returns: how many bits the stored significand field occupies

Source

MinimumExponent

pub func MinimumExponent(self: &FloatLayout) -> int

The smallest exponent a normal value has, as the power of two its integer significand is scaled by.

Returns: the smallest exponent a normal value can have

Source

MaximumExponent

pub func MaximumExponent(self: &FloatLayout) -> int

The largest exponent a finite value has, on the same scale.

Returns: the largest exponent a finite value can have

Source

DecimalDigits

pub func DecimalDigits(self: &FloatLayout) -> uint

How many decimal digits the shortest exact rendering can need: one more than the precision is worth.

Returns: how many decimal digits round-trip through this format

Source

WideClass

pub enum WideClass: int32 {
    Zero = 0,
    Subnormal = 1,
    Normal = 2,
    Infinity = 3,
    NaN = 4
}

What kind of value a bit pattern holds.

Source

Cases

NameValueDescription
Zero0Zero of either sign.
Subnormal1A value below the normal range, with no leading bit.
Normal2An ordinary finite value.
Infinity3Infinity of either sign.
NaN4Not a number, including the unnormal and pseudo encodings of the extended format.

UnpackedWide

pub struct UnpackedWide {
    pub class: WideClass;
    // private fields
}

A finite value taken apart: significand times two to the exponent.

Source

Fields

NameTypeDescription
classWideClassWhich kind of value this came from.

UnpackWide

pub func UnpackWide(
    bits: uint512,
    layout: &FloatLayout
) -> UnpackedWide

Takes a bit pattern apart under layout.

Source

Parameters

NameTypeDescription
bitsuint512the value's bit pattern
layout&FloatLayoutwhich wide floating-point format the bits are in

Returns: the sign, significand and exponent those bits hold

PackWide

pub func PackWide(
    negative: bool,
    significand: uint512,
    exponent: int,
    layout: &FloatLayout
) -> uint512

Puts a finite value back together under layout, which must already be within range and precision.

Source

Parameters

NameTypeDescription
negativeboolwhether the value is negative
significanduint512the significand
exponentintthe binary exponent
layout&FloatLayoutwhich wide floating-point format the bits are in

Returns: the bit pattern for that sign, significand and exponent

InfinityBits

pub func InfinityBits(
    negative: bool,
    layout: &FloatLayout
) -> uint512

The bits of infinity under layout.

Source

Parameters

NameTypeDescription
negativeboolwhether the value is negative
layout&FloatLayoutwhich wide floating-point format the bits are in

Returns: the bit pattern for an infinity of that sign

NanBits

pub func NanBits(layout: &FloatLayout) -> uint512

The bits of a quiet NaN under layout.

Source

Parameters

NameTypeDescription
layout&FloatLayoutwhich wide floating-point format the bits are in

Returns: the bit pattern for a quiet NaN

WriteWideFloat

pub func WriteWideFloat(
    allocator: Allocator,
    writer: &var TextWriter,
    spec: FormatSpec,
    bits: uint512,
    layout: &FloatLayout
) -> ! FormatError

Writes bits, read under layout, as text under spec.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhere the working storage comes from
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for
bitsuint512the value's bit pattern
layout&FloatLayoutwhich wide floating-point format the bits are in

Returns: success when the whole rendering was accepted