Deluge Firmware 1.3.0
Build date: 2025.04.16
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::size_t OtherFractionalBits>
constexpr operator FixedPoint< OtherFractionalBits > () const
 
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.
 
template<std::size_t OtherFractionalBits, bool OtherRounded = Rounded, bool OtherApproximating = FastApproximation>
constexpr operator FixedPoint< OtherFractionalBits, OtherRounded, OtherApproximating > () const
 
constexpr operator float () const noexcept
 Explicit conversion to float.
 
constexpr float to_float () const noexcept
 Explicit conversion to float.
 
constexpr FixedPoint (double value) noexcept
 Convert from a double to a fixed point number.
 
constexpr 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::signed_integral T>
constexpr operator T () const noexcept
 Explicit conversion to integer.
 
constexpr 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>
requires (OtherRounded == Rounded && OtherApproximating == FastApproximation)
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.
 
template<std::size_t OtherFractionalBits, std::size_t ResultFractionalBits = std::max(FractionalBits, OtherFractionalBits) - std::min(FractionalBits, OtherFractionalBits)>
requires (ResultFractionalBits < std::max(FractionalBits, OtherFractionalBits)) && (ResultFractionalBits > std::min(FractionalBits, OtherFractionalBits))
constexpr FixedPoint< ResultFractionalBits, Rounded, FastApproximation > operator/ (const FixedPoint< OtherFractionalBits > &rhs) const
 Division operator Divide two fixed point numbers with different 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>
requires std::floating_point<T>
constexpr bool operator== (const T &rhs) const noexcept
 Equality operator for integers and floating point numbers.
 
template<std::integral T>
constexpr FixedPoint MultiplyInt (const T &rhs) const
 Multiply by an integral type.
 
template<std::integral T>
constexpr FixedPoint DivideInt (const T &rhs) const
 Divide by an integral type.
 
template<std::integral T>
constexpr FixedPoint operator* (const T &rhs) const
 
template<std::integral T>
constexpr FixedPoint operator/ (const T &rhs)
 
constexpr int32_t integral () const
 
constexpr FixedPoint absolute () const noexcept
 

Static Public Member Functions

static consteval uint32_t one () noexcept
 
static constexpr FixedPoint max () noexcept
 
static constexpr FixedPoint min () noexcept
 
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)
 

Private Attributes

BaseType value_ {0}
 

Detailed Description

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = (FractionalBits == 31 && ARMv7a)>
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 = (FractionalBits == 31 && ARMv7a)>
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 = (FractionalBits == 31 && ARMv7a)>
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 = (FractionalBits == 31 && ARMv7a)>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( float value)
inlineconstexprnoexcept

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 = (FractionalBits == 31 && ARMv7a)>
FixedPoint< FractionalBits, Rounded, FastApproximation >::FixedPoint ( double value)
inlineconstexprnoexcept

Convert from a double to a fixed point number.

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

Member Function Documentation

◆ MultiplyAdd() [1/2]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = (FractionalBits == 31 && ARMv7a)>
FixedPoint FixedPoint< FractionalBits, Rounded, FastApproximation >::MultiplyAdd ( const FixedPoint< FractionalBits, Rounded, FastApproximation > & a,
const FixedPoint< FractionalBits, Rounded, FastApproximation > & b ) const
inlinenodiscardconstexpr

Fused multiply-add operation for fixed point numbers with the same number of fractional bits.

a + b * c

◆ MultiplyAdd() [2/2]

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = (FractionalBits == 31 && ARMv7a)>
template<std::size_t OtherFractionalBitsA, std::size_t OtherFractionalBitsB>
FixedPoint FixedPoint< FractionalBits, Rounded, FastApproximation >::MultiplyAdd ( const FixedPoint< OtherFractionalBitsA > & a,
const FixedPoint< OtherFractionalBitsB > & b ) const
inlineconstexpr

Fused multiply-add operation for fixed point numbers with a different number of fractional bits.

a + b * c

◆ operator double()

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = (FractionalBits == 31 && ARMv7a)>
FixedPoint< FractionalBits, Rounded, FastApproximation >::operator double ( ) const
inlineexplicitconstexprnoexcept

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 = (FractionalBits == 31 && ARMv7a)>
FixedPoint< FractionalBits, Rounded, FastApproximation >::operator float ( ) const
inlineexplicitconstexprnoexcept

Explicit conversion to float.

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

◆ to_float()

template<std::size_t FractionalBits, bool Rounded = false, bool FastApproximation = (FractionalBits == 31 && ARMv7a)>
float FixedPoint< FractionalBits, Rounded, FastApproximation >::to_float ( ) const
inlinenodiscardconstexprnoexcept

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: