CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Math::FixedPoint< T, P > Struct Template Reference

#include <CeresEngine/Math/FixedPoint.hpp>

Public Types

using Self = FixedPoint< T, P >
 The fixed point type itself.
 

Public Member Functions

constexpr FixedPoint ()=default
 Creates a new fixed-point number and initializes it with 0.0.
 
constexpr FixedPoint (T raw) noexcept
 Creates a new fixed-point number and initializes it with the given raw integer value.
 
constexpr FixedPoint (const FixedPoint &)=default
 Creates a new fixed-point number by copying another.
 
constexpr FixedPointoperator= (const FixedPoint &)=default
 Assigns the fixed-point number by copying another.
 
constexpr FixedPoint (float f) noexcept
 Creates a new fixed-point number from an existing float value.
 
constexpr operator float () const
 Converts the fixed-point number to a float value.
 
constexpr FixedPoint (const double d) noexcept
 Creates a new fixed-point number from an existing double value.
 
constexpr operator double () const
 Converts the fixed-point number to a double value.
 
constexpr FixedPoint (long double d) noexcept
 Creates a new fixed-point number from an existing double value.
 
constexpr operator long double () const
 Converts the fixed-point number to a double value.
 
template<typename TT , unsigned int TP>
constexpr FixedPoint (const FixedPoint< TT, TP > &other)
 Creates a new fixed-point number by converting representation from another fixed-point.
 
template<typename TT , unsigned int TP>
TT convert () const
 

Public Attributes

raw
 The underlying integer value.
 

Static Public Attributes

static const constexpr T one = T(1) << P
 The integer value that best represents 1.000....
 

Detailed Description

template<typename T = Int64, unsigned int P = 20>
struct Math::FixedPoint< T, P >
Template Parameters
Tthe fixed-point underlying integer type
Pthe number of bits dedicated to the fixed-point

Member Typedef Documentation

◆ Self

template<typename T = Int64, unsigned int P = 20>
using Math::FixedPoint< T, P >::Self = FixedPoint<T, P>

The fixed point type itself.

Used to avoid automatic template deduction on operator arguments.

Constructor & Destructor Documentation

◆ FixedPoint() [1/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( )
constexprdefault

Creates a new fixed-point number and initializes it with 0.0.

◆ FixedPoint() [2/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( raw)
inlineexplicitconstexprnoexcept

Creates a new fixed-point number and initializes it with the given raw integer value.

Parameters
rawThe raw integer value to initialize with

◆ FixedPoint() [3/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( const FixedPoint< T, P > &  )
constexprdefault

Creates a new fixed-point number by copying another.

◆ FixedPoint() [4/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( float  f)
inlineconstexprnoexcept

Creates a new fixed-point number from an existing float value.

Parameters
fThe floating-point value to be converted

◆ FixedPoint() [5/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( const double  d)
inlineconstexprnoexcept

Creates a new fixed-point number from an existing double value.

Parameters
dThe floating-point value to be converted

◆ FixedPoint() [6/7]

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::FixedPoint ( long double  d)
inlineconstexprnoexcept

Creates a new fixed-point number from an existing double value.

Parameters
dThe floating-point value to be converted

◆ FixedPoint() [7/7]

template<typename T = Int64, unsigned int P = 20>
template<typename TT , unsigned int TP>
constexpr Math::FixedPoint< T, P >::FixedPoint ( const FixedPoint< TT, TP > &  other)
inlineconstexpr

Creates a new fixed-point number by converting representation from another fixed-point.

Template Parameters
TTthe target underlying type
TPthe target underlying precision
Parameters
otherThe instance to be converted

Member Function Documentation

◆ convert()

template<typename T = Int64, unsigned int P = 20>
template<typename TT , unsigned int TP>
TT Math::FixedPoint< T, P >::convert ( ) const
inline

◆ operator double()

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::operator double ( ) const
inlineexplicitconstexpr

Converts the fixed-point number to a double value.

Returns
The double value

◆ operator float()

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::operator float ( ) const
inlineexplicitconstexpr

Converts the fixed-point number to a float value.

Returns
The float value

◆ operator long double()

template<typename T = Int64, unsigned int P = 20>
constexpr Math::FixedPoint< T, P >::operator long double ( ) const
inlineexplicitconstexpr

Converts the fixed-point number to a double value.

Returns
The double value

◆ operator=()

template<typename T = Int64, unsigned int P = 20>
constexpr FixedPoint & Math::FixedPoint< T, P >::operator= ( const FixedPoint< T, P > &  )
constexprdefault

Assigns the fixed-point number by copying another.

Returns
*this

Member Data Documentation

◆ one

template<typename T = Int64, unsigned int P = 20>
const constexpr T Math::FixedPoint< T, P >::one = T(1) << P
staticconstexpr

The integer value that best represents 1.000....

◆ raw

template<typename T = Int64, unsigned int P = 20>
T Math::FixedPoint< T, P >::raw

The underlying integer value.


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