FloatLayout structv0.1.0
pub struct FloatLayout {
pub precision: uint;
// private fields
}
Fields
| Name | Type | Description |
|---|---|---|
precision | uint | The 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
Binary128
pub func Binary128() -> FloatLayout
IEEE binary128: a hundred and thirteen bits of precision.
Returns: the layout of IEEE 754 binary128
Binary256
pub func Binary256() -> FloatLayout
IEEE binary256: two hundred and thirty-seven bits of precision.
Returns: the layout of IEEE 754 binary256
Binary512
pub func Binary512() -> FloatLayout
IEEE binary512: four hundred and eighty-nine bits of precision.
Returns: the layout of IEEE 754 binary512
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
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
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
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
Related
WideClass
pub enum WideClass: int32 {
Zero = 0,
Subnormal = 1,
Normal = 2,
Infinity = 3,
NaN = 4
}
What kind of value a bit pattern holds.
Cases
| Name | Value | Description |
|---|---|---|
Zero | 0 | Zero of either sign. |
Subnormal | 1 | A value below the normal range, with no leading bit. |
Normal | 2 | An ordinary finite value. |
Infinity | 3 | Infinity of either sign. |
NaN | 4 | Not 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.
Fields
| Name | Type | Description |
|---|---|---|
class | WideClass | Which kind of value this came from. |
UnpackWide
pub func UnpackWide(
bits: uint512,
layout: &FloatLayout
) -> UnpackedWide
Takes a bit pattern apart under layout.
Parameters
| Name | Type | Description |
|---|---|---|
bits | uint512 | the value's bit pattern |
layout | &FloatLayout | which 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.
Parameters
| Name | Type | Description |
|---|---|---|
negative | bool | whether the value is negative |
significand | uint512 | the significand |
exponent | int | the binary exponent |
layout | &FloatLayout | which 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.
Parameters
| Name | Type | Description |
|---|---|---|
negative | bool | whether the value is negative |
layout | &FloatLayout | which 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.
Parameters
| Name | Type | Description |
|---|---|---|
layout | &FloatLayout | which 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.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the working storage comes from |
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
bits | uint512 | the value's bit pattern |
layout | &FloatLayout | which wide floating-point format the bits are in |
Returns: success when the whole rendering was accepted