template <typename Integer, size_t FractionalBits>

struct FixedFormat

Defined at line 45 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

Forward declaration.

Public Members

static const bool IsSigned
static const bool IsUnsigned
static const size_t Bits
static const size_t FractionalBits
static const size_t IntegralBits
static const size_t PositiveBits
static const size_t Power
static const Integer One
static const Integer FractionalMask
static const Integer IntegralMask
static const Integer SignBit
static const Integer BinaryPoint
static const Integer OnesPlace
static const bool ApproximateUnit
static const size_t AdjustedFractionalBits
static const size_t AdjustedPower
static const Integer AdjustmentFactor
static const Integer AdjustedFractionalMask
static const Integer AdjustedIntegralMask
static const Integer Min
static const Integer Max
static const Integer IntegralMin
static const Integer IntegralMax

Public Methods

template <typename I, typename = std::enable_if_t<std::is_integral_v<I>>>
Integer Saturate (I value)

Saturates an intermediate value to the valid range of the base type.

Defined at line 96 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

Integer Saturate (Value<FixedFormat<Integer_, FractionalBits_>> value)

Defined at line 99 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

template <size_t Place, typename = std::enable_if_t<(Place < PositiveBits)>>
Integer Round (Integer value, Bit<Place> )

Rounds |value| to the given significant bit |Place| using the convergent,

or round-half-to-even, method to eliminate positive/negative and

towards/away from zero biases. This is the default rounding mode used in

IEEE 754 computing functions and operators.

References:

https://en.wikipedia.org/wiki/Rounding#Round_half_to_even

https://en.wikipedia.org/wiki/Nearest_integer_function

For example, rounding an 8bit value to bit 4 produces these values in the

constants defined below:

uint8_t value = vvvphmmm

PlaceBit = 00010000 -> 000p0000

PlaceMask = 11110000 -> vvvp0000

HalfBit = 00001000 -> 0000h000

BelowHalfMask = 00000111 -> 00000mmm

Rounding half to even is computed as follows:

PlaceBit 00010000

BelowHalfMask 00000111

| ------------------------

00010111

value vvvvvvvv

&

------------------------

000v0vvv

non-zero

? ------------------------

HalfBit 00001000

: zero 00000000

------------------------

round_bit 0000r000

value vvvvvvvv

+ ------------------------

rounded rrrrxxxx

PlaceMask 11110000

&

------------------------

result rrrr0000

Defined at line 143 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

Integer Round (Integer value, Bit<0> )

Rounding to the 0th bit is a no-op.

Defined at line 161 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

Integer Round (Integer value)

Rounds |value| around the integer position.

Defined at line 164 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

template <typename SourceFormat>
Value<FixedFormat<Integer_, FractionalBits_>> Convert (Value<SourceFormat> value)

Converts an intermediate value in SourceFormat to this format, rounding

as necessary.

Defined at line 169 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h

Value<FixedFormat<Integer_, FractionalBits_>> Convert (Value<FixedFormat<Integer_, FractionalBits_>> value)

Converting to the same format is a no-op.

Defined at line 203 of file ../../zircon/system/ulib/ffl/include/ffl/fixed_format.h