Deluge Firmware 1.3.0
Build date: 2026.03.02
Loading...
Searching...
No Matches
FixedPoint< FractionalBits, Rounded, FastApproximation > Class Template Reference

Fixed point number with a configurable number of fractional bits. More...

#include <fixedpoint.h>

Public Member Functions

constexpr FixedPoint ()=default
 Default constructor.
template<std::size_t OtherFractionalBits>
constexpr FixedPoint (FixedPoint< OtherFractionalBits > other) noexcept
 Construct a fixed point number from another fixed point number.
template<std::integral T>
constexpr FixedPoint (T value) noexcept
 Convert an integer to a fixed point number.
constexpr FixedPoint (float value) noexcept
 Convert from a float to a fixed point number.
constexpr operator float () const noexcept
 Explicit conversion to float.
constexpr FixedPoint (double value) noexcept
 Convert from a double to a fixed point number.
 operator double () const noexcept
 Explicit conversion to double.
template<std::size_t OutputFractionalBits>
constexpr FixedPoint< OutputFractionalBits > as () const
 Convert to a fixed point number with a different number of fractional bits.
template<std::integral T>
 operator T () const noexcept
 Explicit conversion to integer.
 operator bool () const noexcept
constexpr FixedPoint operator- () const
 Negation operator.
constexpr BaseType raw () const noexcept
 Get the internal value.
constexpr FixedPoint operator+ (const FixedPoint &rhs) const
 Addition operator Add two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator+= (const FixedPoint &rhs)
 Addition operator Add two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator- (const FixedPoint &rhs) const
 Subtraction operator Subtract two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator-= (const FixedPoint &rhs)
 Subtraction operator Subtract two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator* (const FixedPoint &rhs) const
 Multiplication operator Multiply two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator*= (const FixedPoint &rhs)
 Multiplication operator Multiply two fixed point numbers with the same number of fractional bits.
template<std::size_t OutputFractionalBits = FractionalBits, std::size_t OtherFractionalBits, bool OtherRounded, bool OtherApproximating>
constexpr FixedPoint< OutputFractionalBits, Rounded, FastApproximation > operator* (const FixedPoint< OtherFractionalBits, OtherRounded, OtherApproximating > &rhs) const
 Multiplication operator Multiply two fixed point numbers with different number of fractional bits.
template<std::size_t OtherFractionalBits>
constexpr FixedPoint operator*= (const FixedPoint< OtherFractionalBits > &rhs)
 Multiplication operator Multiply two fixed point numbers with different number of fractional bits.
constexpr FixedPoint operator/ (const FixedPoint &rhs) const
 Division operator Divide two fixed point numbers with the same number of fractional bits.
constexpr FixedPoint operator/= (const FixedPoint &rhs)
 Division operator Divide two fixed point numbers with the same number of fractional bits.
template<std::size_t OtherFractionalBitsA, std::size_t OtherFractionalBitsB>
constexpr FixedPoint MultiplyAdd (const FixedPoint< OtherFractionalBitsA > &a, const FixedPoint< OtherFractionalBitsB > &b) const
 Fused multiply-add operation for fixed point numbers with a different number of fractional bits.
constexpr FixedPoint MultiplyAdd (const FixedPoint &a, const FixedPoint &b) const
 Fused multiply-add operation for fixed point numbers with the same number of fractional bits.
constexpr bool operator== (const FixedPoint &rhs) const noexcept
 Equality operator.
constexpr std::strong_ordering operator<=> (const FixedPoint &rhs) const noexcept
 Three-way comparison operator.
template<std::size_t OtherFractionalBits>
constexpr bool operator== (const FixedPoint< OtherFractionalBits > &rhs) const noexcept
 Equality operator for fixed point numbers with different number of fractional bits.
template<std::size_t OtherFractionalBits>
constexpr std::strong_ordering operator<=> (const FixedPoint< OtherFractionalBits > &rhs) const noexcept
 Three-way comparison operator for fixed point numbers with different number of fractional bits.
template<typename T>
constexpr bool operator== (const T &rhs) const noexcept
 Equality operator for integers and floating point numbers.

Static Public Member Functions

static constexpr FixedPoint from_raw (BaseType raw) noexcept
 Construct from a raw value.

Static Public Attributes

static constexpr std::size_t fractional_bits = FractionalBits
static constexpr std::size_t integral_bits = 32 - FractionalBits
static constexpr bool rounded = Rounded
static constexpr bool fast_approximation = FastApproximation

Private Types

using BaseType = int32_t
using IntermediateType = int64_t

Static Private Member Functions

static int32_t signed_most_significant_word_multiply_add (int32_t a, int32_t b, int32_t c)
 a + b * c
static int32_t signed_most_significant_word_multiply (int32_t a, int32_t b)
static constexpr BaseType one () noexcept

Private Attributes

BaseType value_ {0}

Detailed Description

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
class FixedPoint< FractionalBits, Rounded, FastApproximation >

Fixed point number with a configurable number of fractional bits.

Note
This class only supports 32-bit signed fixed point numbers
Template Parameters
FractionalBitsThe number of fractional bits
RoundedWhether to round the result when performing operations
FastApproximationWhether to use a fast approximation for operations

Constructor & Destructor Documentation

◆ FixedPoint() [1/4]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
template<std::size_t OtherFractionalBits>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( FixedPoint< OtherFractionalBits > other)
inlineexplicitconstexprnoexcept

Construct a fixed point number from another fixed point number.

Note
This will saturate or truncate (and/or round) the value if the number of fractional bits is different

◆ FixedPoint() [2/4]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
template<std::integral T>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( T value)
inlineexplicitconstexprnoexcept

Convert an integer to a fixed point number.

Note
This truncates the integer if it is too large

◆ FixedPoint() [3/4]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( float value)
inlineexplicitconstexprnoexcept

Convert from a float to a fixed point number.

Note
VFP instruction - 1 cycle for issue, 4 cycles result latency

◆ FixedPoint() [4/4]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( double value)
inlineexplicitconstexprnoexcept

Convert from a double to a fixed point number.

Note
VFP instruction - 1 cycle for issue, 4 cycles result latency

Member Function Documentation

◆ operator double()

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
FixedPoint< FractionalBits, Rounded, FastApproximation >::operator double ( ) const
inlineexplicitnoexcept

Explicit conversion to double.

Note
VFP instruction - 1 cycle for issue, 4 cycles result latency

◆ operator float()

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = true>
FixedPoint< FractionalBits, Rounded, FastApproximation >::operator float ( ) const
inlineexplicitconstexprnoexcept

Explicit conversion to float.

Note
VFP instruction - 1 cycle for issue, 4 cycles result latency

The documentation for this class was generated from the following file: