PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::Fixed< BASE_TYPE, FRACTION_BITS > Class Template Reference

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

#include <Fixed.hpp>

Collaboration diagram for playrho::Fixed< BASE_TYPE, FRACTION_BITS >:
[legend]

Classes

struct  scalar_type
 Scalar type. More...
 

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Private Types

using wider_type = typename Wider< value_type >::type
 Widened type alias.
 
using unsigned_wider_type = typename std::make_unsigned< wider_type >::type
 Unsigned widened type alias.
 
using numeric_limits = std::numeric_limits< value_type >
 Numeric limits type alias.
 

Private Member Functions

constexpr Fixed (value_type val, scalar_type scalar) noexcept
 Initializing constructor.
 

Private Attributes

value_type m_value
 Value in internal form.
 

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 named requirement.

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

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