|
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true> |
constexpr | FixedPoint (T i) |
|
constexpr | FixedPoint (IntType i, FracType f) |
| Constructor for setting both the integral and fractional part. More...
|
|
constexpr | FixedPoint (const FixedPoint &o) |
|
constexpr FixedPoint & | operator= (FixedPoint o) |
|
template<typename T , std::enable_if_t< std::is_floating_point_v< T >, bool > = true> |
__fp_consteval | FixedPoint (T f) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr | FixedPoint (FixedPoint< OI, OF, S > o) |
|
constexpr IntType | as_i () const |
| Returns just the integral portion. More...
|
|
constexpr FracType | as_f () const |
| Returns just the fractional portion. More...
|
|
constexpr StorageType | get () const |
| Returns the entire value. More...
|
|
constexpr void | set_i (IntType value) |
| Update just the integral portion. More...
|
|
constexpr void | set_f (FracType value) |
| Update just the fractional portion. More...
|
|
constexpr void | set (StorageType value) |
| Update the entire value. More...
|
|
template<intmax_t OI, intmax_t OF, bool S = true> |
constexpr FixedPoint< OI, OF, S > | as () |
|
constexpr bool | is_signed () const |
|
constexpr intmax_t | bitcount () const |
|
constexpr intmax_t | int_bitcount () const |
|
constexpr intmax_t | frac_bitcount () const |
|
constexpr FixedPoint | operator- () const |
|
constexpr FixedPoint | operator~ () const |
|
constexpr FixedPoint & | operator%= (FixedPoint o) |
|
constexpr FixedPoint | operator% (FixedPoint o) const |
|
constexpr FixedPoint & | operator&= (FixedPoint o) |
|
constexpr FixedPoint | operator& (FixedPoint o) const |
|
constexpr FixedPoint & | operator|= (FixedPoint o) |
|
constexpr FixedPoint | operator| (FixedPoint o) const |
|
constexpr FixedPoint & | operator^= (FixedPoint o) |
|
constexpr FixedPoint | operator^ (FixedPoint o) const |
|
constexpr FixedPoint & | operator+= (FixedPoint o) |
|
constexpr FixedPoint | operator+ (FixedPoint o) const |
|
constexpr FixedPoint & | operator-= (FixedPoint o) |
|
constexpr FixedPoint | operator- (FixedPoint o) const |
|
constexpr FixedPoint & | operator/= (FixedPoint o) |
|
constexpr FixedPoint | operator/ (FixedPoint o) const |
|
constexpr FixedPoint & | operator*= (FixedPoint o) |
|
constexpr FixedPoint | operator* (FixedPoint o) const |
|
constexpr FixedPoint & | operator>>= (StorageType v) |
|
constexpr FixedPoint | operator>> (StorageType v) const |
|
constexpr FixedPoint & | operator<<= (StorageType v) |
|
constexpr FixedPoint | operator<< (StorageType v) const |
|
FixedPoint & | operator++ () |
|
FixedPoint | operator++ (int) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator+ (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator+= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator- (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator-= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator% (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator%= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator^ (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator^= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator& (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator&= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator| (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator|= (FixedPoint< OI, OF, S > o) |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator* (FixedPoint< OI, OF, S > o) const |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr FixedPoint & | operator*= (FixedPoint< OI, OF, S > o) |
|
constexpr bool | operator== (const FixedPoint &o) const noexcept |
|
constexpr bool | operator< (const FixedPoint &o) const noexcept |
|
constexpr bool | operator!= (const FixedPoint &o) const noexcept |
|
constexpr bool | operator> (const FixedPoint &o) const noexcept |
|
constexpr bool | operator>= (const FixedPoint &o) const noexcept |
|
constexpr bool | operator<= (const FixedPoint &o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator== (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator< (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator!= (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator> (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator>= (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t OI, intmax_t OF, bool S> |
constexpr auto | operator<= (FixedPoint< OI, OF, S > o) const noexcept |
|
template<intmax_t IntSize, intmax_t FracSize, bool Signed>
class FixedPoint< IntSize, FracSize, Signed >
Numeric Wrapper for Fixed Point math
Without dedicated floating point hardware, fixed point math is a good choice for many llvm-mos targets. This class wraps common fixed point idioms to provide a typesafe way to perform math operations that represent fractional values.
For a quick primer on fixed point math, consider a simple case of a 8.8 fixed point number. The first number represents the number of bits used to hold the Integer portion of the value, and the second 8 bits hold the fractional portion. This has some very useful properties for the 6502 such as when adding two fixed point numbers with the same size, the math is the simply 16 bit math. Another benefit is should you only want to use the integer portion of the value, accessing this comes with no additional cost because its merely the high bytes. This property is not true for all combination of sizes, but in general, it still is reasonably quick to access the higher byte by shifting as needed.
In a little bit more detail, a fixed point number can be considered a regular 16 bit number that is implicitly divided by the size of the fractional portion. With our 8.8 example, the Fractional portion can represent 256 values total, meaning the value in the fractional part represents a number divided by 256. As a practical example, a 16 bit number 0x5060
, and when divided by 0x100
yields 0x50
with a remainder of 0x60
. This class makes that divider a part of the type of the class, allowing seamless math operations as if its a normal integer, but with the correct shifting when combining with other values.