playrho::Fixed< BASE_TYPE, FRACTION_BITS > Class Template Reference

Template class for fixed-point numbers. More...

#include <Fixed.hpp>

Public Types

enum  CmpResult { CmpResult::Incomparable, CmpResult::Equal, CmpResult::LessThan, CmpResult::GreaterThan }
 Compare result enumeration. More...
 
using value_type = BASE_TYPE
 Value type. More...
 

Public Member Functions

 Fixed ()=default
 
PLAYRHO_CONSTEXPR Fixed (long double val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (double val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (float val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (unsigned long long val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (unsigned long val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (unsigned int val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (long long val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (long val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (int val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (short val) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR Fixed (value_type val, unsigned int fraction) noexcept
 Initializing constructor. More...
 
template<typename BT , unsigned int FB>
PLAYRHO_CONSTEXPR Fixed (const Fixed< BT, FB > val) noexcept
 Initializing constructor. More...
 
template<typename T >
PLAYRHO_CONSTEXPRConvertTo () const noexcept
 Converts the value to the expressed type. More...
 
PLAYRHO_CONSTEXPR CmpResult Compare (const Fixed other) const noexcept
 Compares this value to the given one. More...
 
PLAYRHO_CONSTEXPR operator long double () const noexcept
 Long double operator. More...
 
PLAYRHO_CONSTEXPR operator double () const noexcept
 Double operator. More...
 
PLAYRHO_CONSTEXPR operator float () const noexcept
 Float operator. More...
 
PLAYRHO_CONSTEXPR operator long long () const noexcept
 Long long operator. More...
 
PLAYRHO_CONSTEXPR operator long () const noexcept
 Long operator. More...
 
PLAYRHO_CONSTEXPR operator unsigned long long () const noexcept
 Unsigned long long operator. More...
 
PLAYRHO_CONSTEXPR operator unsigned long () const noexcept
 Unsigned long operator. More...
 
PLAYRHO_CONSTEXPR operator unsigned int () const noexcept
 Unsigned int operator. More...
 
PLAYRHO_CONSTEXPR operator int () const noexcept
 int operator. More...
 
PLAYRHO_CONSTEXPR operator short () const noexcept
 short operator. More...
 
PLAYRHO_CONSTEXPR Fixed operator- () const noexcept
 Negation operator. More...
 
PLAYRHO_CONSTEXPR Fixed operator+ () const noexcept
 Positive operator. More...
 
PLAYRHO_CONSTEXPR operator bool () const noexcept
 Boolean operator. More...
 
PLAYRHO_CONSTEXPR bool operator! () const noexcept
 Logical not operator. More...
 
PLAYRHO_CONSTEXPR Fixedoperator+= (Fixed val) noexcept
 Addition assignment operator. More...
 
PLAYRHO_CONSTEXPR Fixedoperator-= (Fixed val) noexcept
 Subtraction assignment operator. More...
 
PLAYRHO_CONSTEXPR Fixedoperator*= (Fixed val) noexcept
 Multiplication assignment operator. More...
 
PLAYRHO_CONSTEXPR Fixedoperator/= (Fixed val) noexcept
 Division assignment operator. More...
 
PLAYRHO_CONSTEXPR Fixedoperator%= (Fixed val) noexcept
 Modulo operator. More...
 
PLAYRHO_CONSTEXPR bool isfinite () const noexcept
 Is finite. More...
 
PLAYRHO_CONSTEXPR bool isnan () const noexcept
 Is NaN. More...
 
PLAYRHO_CONSTEXPR int getsign () const noexcept
 Gets this value's sign. More...
 

Static Public Member Functions

static PLAYRHO_CONSTEXPR Fixed GetMin () noexcept
 Gets the min value this type is capable of expressing. More...
 
static PLAYRHO_CONSTEXPR Fixed GetInfinity () noexcept
 Gets an infinite value for this type. More...
 
static PLAYRHO_CONSTEXPR Fixed GetMax () noexcept
 Gets the max value this type is capable of expressing. More...
 
static PLAYRHO_CONSTEXPR Fixed GetNaN () noexcept
 Gets a NaN value for this type. More...
 
static PLAYRHO_CONSTEXPR Fixed GetNegativeInfinity () noexcept
 Gets the negative infinity value for this type. More...
 
static PLAYRHO_CONSTEXPR Fixed GetLowest () noexcept
 Gets the lowest value this type is capable of expressing. More...
 
template<typename T >
static PLAYRHO_CONSTEXPR value_type GetFromFloat (T val) noexcept
 Gets the value from a floating point value. More...
 
template<typename T >
static PLAYRHO_CONSTEXPR value_type GetFromSignedInt (T val) noexcept
 Gets the value from a signed integral value. More...
 
template<typename T >
static PLAYRHO_CONSTEXPR value_type GetFromUnsignedInt (T val) noexcept
 Gets the value from an unsigned integral value. More...
 

Static Public Attributes

static const PLAYRHO_CONSTEXPR unsigned int TotalBits = sizeof(BASE_TYPE) * 8
 Total number of bits. More...
 
static const PLAYRHO_CONSTEXPR unsigned int FractionBits = FRACTION_BITS
 Fraction bits. More...
 
static const PLAYRHO_CONSTEXPR unsigned int WholeBits = TotalBits - FractionBits
 Whole value bits. More...
 
static const PLAYRHO_CONSTEXPR value_type ScaleFactor = static_cast<value_type>(1u << FractionBits)
 Scale factor. More...
 

Detailed Description

template<typename BASE_TYPE, unsigned int FRACTION_BITS>
class playrho::Fixed< BASE_TYPE, FRACTION_BITS >

Template class for fixed-point numbers.

This is a fixed point type template for a given base type using a given number of fraction bits that satisfies the LiteralType concept.

See also
https://en.wikipedia.org/wiki/Fixed-point_arithmetic
http://en.cppreference.com/w/cpp/concept/LiteralType

Definition at line 44 of file Fixed.hpp.

Member Typedef Documentation

◆ value_type

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
using playrho::Fixed< BASE_TYPE, FRACTION_BITS >::value_type = BASE_TYPE

Value type.

Definition at line 49 of file Fixed.hpp.

Member Enumeration Documentation

◆ CmpResult

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
enum playrho::Fixed::CmpResult
strong

Compare result enumeration.

Enumerator
Incomparable 
Equal 
LessThan 
GreaterThan 

Definition at line 64 of file Fixed.hpp.

Constructor & Destructor Documentation

◆ Fixed() [1/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( )
default

◆ Fixed() [2/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( long double  val)
inlinenoexcept

Initializing constructor.

Definition at line 148 of file Fixed.hpp.

◆ Fixed() [3/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( double  val)
inlinenoexcept

Initializing constructor.

Definition at line 155 of file Fixed.hpp.

◆ Fixed() [4/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( float  val)
inlinenoexcept

Initializing constructor.

Definition at line 162 of file Fixed.hpp.

◆ Fixed() [5/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( unsigned long long  val)
inlinenoexcept

Initializing constructor.

Definition at line 169 of file Fixed.hpp.

◆ Fixed() [6/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( unsigned long  val)
inlinenoexcept

Initializing constructor.

Definition at line 176 of file Fixed.hpp.

◆ Fixed() [7/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( unsigned int  val)
inlinenoexcept

Initializing constructor.

Definition at line 183 of file Fixed.hpp.

◆ Fixed() [8/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( long long  val)
inlinenoexcept

Initializing constructor.

Definition at line 190 of file Fixed.hpp.

◆ Fixed() [9/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( long  val)
inlinenoexcept

Initializing constructor.

Definition at line 197 of file Fixed.hpp.

◆ Fixed() [10/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( int  val)
inlinenoexcept

Initializing constructor.

Definition at line 204 of file Fixed.hpp.

◆ Fixed() [11/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( short  val)
inlinenoexcept

Initializing constructor.

Definition at line 211 of file Fixed.hpp.

◆ Fixed() [12/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( value_type  val,
unsigned int  fraction 
)
inlinenoexcept

Initializing constructor.

Definition at line 218 of file Fixed.hpp.

◆ Fixed() [13/13]

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
template<typename BT , unsigned int FB>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Fixed ( const Fixed< BT, FB >  val)
inlinenoexcept

Initializing constructor.

Definition at line 226 of file Fixed.hpp.

Member Function Documentation

◆ GetMin()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetMin ( )
inlinestaticnoexcept

Gets the min value this type is capable of expressing.

Definition at line 73 of file Fixed.hpp.

◆ GetInfinity()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetInfinity ( )
inlinestaticnoexcept

Gets an infinite value for this type.

Definition at line 79 of file Fixed.hpp.

◆ GetMax()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetMax ( )
inlinestaticnoexcept

Gets the max value this type is capable of expressing.

Definition at line 85 of file Fixed.hpp.

◆ GetNaN()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetNaN ( )
inlinestaticnoexcept

Gets a NaN value for this type.

Definition at line 92 of file Fixed.hpp.

◆ GetNegativeInfinity()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetNegativeInfinity ( )
inlinestaticnoexcept

Gets the negative infinity value for this type.

Definition at line 98 of file Fixed.hpp.

◆ GetLowest()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
static PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetLowest ( )
inlinestaticnoexcept

Gets the lowest value this type is capable of expressing.

Definition at line 105 of file Fixed.hpp.

◆ GetFromFloat()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
template<typename T >
static PLAYRHO_CONSTEXPR value_type playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetFromFloat ( val)
inlinestaticnoexcept

Gets the value from a floating point value.

Definition at line 114 of file Fixed.hpp.

◆ GetFromSignedInt()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
template<typename T >
static PLAYRHO_CONSTEXPR value_type playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetFromSignedInt ( val)
inlinestaticnoexcept

Gets the value from a signed integral value.

Definition at line 126 of file Fixed.hpp.

◆ GetFromUnsignedInt()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
template<typename T >
static PLAYRHO_CONSTEXPR value_type playrho::Fixed< BASE_TYPE, FRACTION_BITS >::GetFromUnsignedInt ( val)
inlinestaticnoexcept

Gets the value from an unsigned integral value.

Definition at line 137 of file Fixed.hpp.

◆ ConvertTo()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
template<typename T >
PLAYRHO_CONSTEXPR T playrho::Fixed< BASE_TYPE, FRACTION_BITS >::ConvertTo ( ) const
inlinenoexcept

Converts the value to the expressed type.

Definition at line 236 of file Fixed.hpp.

◆ Compare()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR CmpResult playrho::Fixed< BASE_TYPE, FRACTION_BITS >::Compare ( const Fixed< BASE_TYPE, FRACTION_BITS >  other) const
inlinenoexcept

Compares this value to the given one.

Definition at line 244 of file Fixed.hpp.

◆ operator long double()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator long double ( ) const
inlineexplicitnoexcept

Long double operator.

Definition at line 264 of file Fixed.hpp.

◆ operator double()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator double ( ) const
inlineexplicitnoexcept

Double operator.

Definition at line 270 of file Fixed.hpp.

◆ operator float()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator float ( ) const
inlineexplicitnoexcept

Float operator.

Definition at line 276 of file Fixed.hpp.

◆ operator long long()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator long long ( ) const
inlineexplicitnoexcept

Long long operator.

Definition at line 282 of file Fixed.hpp.

◆ operator long()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator long ( ) const
inlineexplicitnoexcept

Long operator.

Definition at line 288 of file Fixed.hpp.

◆ operator unsigned long long()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator unsigned long long ( ) const
inlineexplicitnoexcept

Unsigned long long operator.

Definition at line 294 of file Fixed.hpp.

◆ operator unsigned long()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator unsigned long ( ) const
inlineexplicitnoexcept

Unsigned long operator.

Definition at line 301 of file Fixed.hpp.

◆ operator unsigned int()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator unsigned int ( ) const
inlineexplicitnoexcept

Unsigned int operator.

Definition at line 308 of file Fixed.hpp.

◆ operator int()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator int ( ) const
inlineexplicitnoexcept

int operator.

Definition at line 315 of file Fixed.hpp.

◆ operator short()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator short ( ) const
inlineexplicitnoexcept

short operator.

Definition at line 321 of file Fixed.hpp.

◆ operator-()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator- ( ) const
inlinenoexcept

Negation operator.

Definition at line 327 of file Fixed.hpp.

◆ operator+()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator+ ( ) const
inlinenoexcept

Positive operator.

Definition at line 333 of file Fixed.hpp.

◆ operator bool()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator bool ( ) const
inlineexplicitnoexcept

Boolean operator.

Definition at line 339 of file Fixed.hpp.

◆ operator!()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR bool playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator! ( ) const
inlinenoexcept

Logical not operator.

Definition at line 345 of file Fixed.hpp.

◆ operator+=()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed& playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator+= ( Fixed< BASE_TYPE, FRACTION_BITS >  val)
inlinenoexcept

Addition assignment operator.

Definition at line 351 of file Fixed.hpp.

◆ operator-=()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed& playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator-= ( Fixed< BASE_TYPE, FRACTION_BITS >  val)
inlinenoexcept

Subtraction assignment operator.

Definition at line 390 of file Fixed.hpp.

◆ operator*=()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed& playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator*= ( Fixed< BASE_TYPE, FRACTION_BITS >  val)
inlinenoexcept

Multiplication assignment operator.

Definition at line 429 of file Fixed.hpp.

◆ operator/=()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed& playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator/= ( Fixed< BASE_TYPE, FRACTION_BITS >  val)
inlinenoexcept

Division assignment operator.

Definition at line 475 of file Fixed.hpp.

◆ operator%=()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR Fixed& playrho::Fixed< BASE_TYPE, FRACTION_BITS >::operator%= ( Fixed< BASE_TYPE, FRACTION_BITS >  val)
inlinenoexcept

Modulo operator.

Definition at line 522 of file Fixed.hpp.

◆ isfinite()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR bool playrho::Fixed< BASE_TYPE, FRACTION_BITS >::isfinite ( ) const
inlinenoexcept

Is finite.

Definition at line 532 of file Fixed.hpp.

◆ isnan()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR bool playrho::Fixed< BASE_TYPE, FRACTION_BITS >::isnan ( ) const
inlinenoexcept

Is NaN.

Definition at line 539 of file Fixed.hpp.

◆ getsign()

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
PLAYRHO_CONSTEXPR int playrho::Fixed< BASE_TYPE, FRACTION_BITS >::getsign ( ) const
inlinenoexcept

Gets this value's sign.

Definition at line 545 of file Fixed.hpp.

Member Data Documentation

◆ TotalBits

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
const PLAYRHO_CONSTEXPR unsigned int playrho::Fixed< BASE_TYPE, FRACTION_BITS >::TotalBits = sizeof(BASE_TYPE) * 8
static

Total number of bits.

Definition at line 52 of file Fixed.hpp.

◆ FractionBits

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
const PLAYRHO_CONSTEXPR unsigned int playrho::Fixed< BASE_TYPE, FRACTION_BITS >::FractionBits = FRACTION_BITS
static

Fraction bits.

Definition at line 55 of file Fixed.hpp.

◆ WholeBits

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
const PLAYRHO_CONSTEXPR unsigned int playrho::Fixed< BASE_TYPE, FRACTION_BITS >::WholeBits = TotalBits - FractionBits
static

Whole value bits.

Definition at line 58 of file Fixed.hpp.

◆ ScaleFactor

template<typename BASE_TYPE , unsigned int FRACTION_BITS>
const PLAYRHO_CONSTEXPR value_type playrho::Fixed< BASE_TYPE, FRACTION_BITS >::ScaleFactor = static_cast<value_type>(1u << FractionBits)
static

Scale factor.

Definition at line 61 of file Fixed.hpp.


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