Math Functions For Fixed Types

Common Mathematical Functions For Fixed Types. More...

Namespaces

 playrho::detail
 

Functions

template<typename BT , unsigned int FB, int N = 5>
constexpr Fixed< BT, FB > playrho::abs (Fixed< BT, FB > arg)
 Computes the absolute value. More...
 
template<typename BT , unsigned int FB>
constexpr Fixed< BT, FB > playrho::pow (Fixed< BT, FB > value, int n)
 Computes the value of the given number raised to the given power. More...
 
template<typename BT , unsigned int FB>
constexpr Fixed< BT, FB > playrho::trunc (Fixed< BT, FB > arg)
 Truncates the given value. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::nextafter (Fixed< BT, FB > from, Fixed< BT, FB > to) noexcept
 Next after function for Fixed types. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::fmod (Fixed< BT, FB > dividend, Fixed< BT, FB > divisor) noexcept
 Computes the remainder of the division of the given dividend by the given divisor. More...
 
template<typename BT , unsigned int FB>
auto playrho::sqrt (Fixed< BT, FB > arg)
 Square root's the given value. More...
 
template<typename BT , unsigned int FB>
bool playrho::isnormal (Fixed< BT, FB > arg)
 Gets whether the given value is normal - i.e. not 0 nor infinite. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::sin (Fixed< BT, FB > arg)
 Computes the sine of the argument for Fixed types. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::cos (Fixed< BT, FB > arg)
 Computes the cosine of the argument for Fixed types. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::atan (Fixed< BT, FB > arg)
 Computes the arc tangent. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::atan2 (Fixed< BT, FB > y, Fixed< BT, FB > x)
 Computes the multi-valued inverse tangent. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::log (Fixed< BT, FB > arg)
 Computes the natural logarithm of the given argument. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::exp (Fixed< BT, FB > arg)
 Computes the Euler number raised to the power of the given argument. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::pow (Fixed< BT, FB > base, Fixed< BT, FB > exponent)
 Computes the value of the base number raised to the power of the exponent. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::hypot (Fixed< BT, FB > x, Fixed< BT, FB > y)
 Computes the square root of the sum of the squares. More...
 
template<typename BT , unsigned int FB>
Fixed< BT, FB > playrho::round (Fixed< BT, FB > value) noexcept
 Rounds the given value. More...
 
template<typename BT , unsigned int FB>
bool playrho::signbit (Fixed< BT, FB > value) noexcept
 Determines whether the given value is negative. More...
 
template<typename BT , unsigned int FB>
PLAYRHO_CONSTEXPR bool playrho::isnan (Fixed< BT, FB > value) noexcept
 Gets whether the given value is not-a-number. More...
 
template<typename BT , unsigned int FB>
bool playrho::isfinite (Fixed< BT, FB > value) noexcept
 Gets whether the given value is finite. More...
 

Detailed Description

Common Mathematical Functions For Fixed Types.

Note
These functions directly compute their respective results. They don't convert their inputs to a floating point type to use the standard math functions and then convert those results back to the fixed point type. This has pros and cons. Some pros are that: this won't suffer from the "non-determinism" inherent with different hardware platforms potentially having different floating point or math library implementations; this implementation won't suffer any overhead of converting between the underlying type and a floating point type. On the con side however: this implementation is unlikely to be anywhere near as tested as standard C++ math library functions likely are; this implementation is unlikely to have anywhere near as much performance tuning as standard library functions have had.
See also
Fixed
http://en.cppreference.com/w/cpp/numeric/math

Function Documentation

◆ abs()

template<typename BT , unsigned int FB, int N = 5>
constexpr Fixed<BT, FB> playrho::abs ( Fixed< BT, FB >  arg)
inlineconstexpr

Computes the absolute value.

See also
http://en.cppreference.com/w/cpp/numeric/math/fabs

Definition at line 48 of file FixedMath.hpp.

◆ pow() [1/2]

template<typename BT , unsigned int FB>
constexpr Fixed<BT, FB> playrho::pow ( Fixed< BT, FB >  value,
int  n 
)
constexpr

Computes the value of the given number raised to the given power.

Note
This implementation is for raising a given value to an integer power. This may have significantly different performance than raising a value to a non-integer power.
See also
http://en.cppreference.com/w/cpp/numeric/math/pow

Definition at line 59 of file FixedMath.hpp.

◆ trunc()

template<typename BT , unsigned int FB>
constexpr Fixed<BT, FB> playrho::trunc ( Fixed< BT, FB >  arg)
inlineconstexpr

Truncates the given value.

See also
http://en.cppreference.com/w/c/numeric/math/trunc

Definition at line 343 of file FixedMath.hpp.

◆ nextafter()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::nextafter ( Fixed< BT, FB >  from,
Fixed< BT, FB >  to 
)
inlinenoexcept

Next after function for Fixed types.

See also
http://en.cppreference.com/w/cpp/numeric/math/nextafter
Examples
World.cpp.

Definition at line 351 of file FixedMath.hpp.

◆ fmod()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::fmod ( Fixed< BT, FB >  dividend,
Fixed< BT, FB >  divisor 
)
inlinenoexcept

Computes the remainder of the division of the given dividend by the given divisor.

See also
http://en.cppreference.com/w/cpp/numeric/math/fmod

Definition at line 367 of file FixedMath.hpp.

◆ sqrt()

template<typename BT , unsigned int FB>
auto playrho::sqrt ( Fixed< BT, FB >  arg)
inline

Square root's the given value.

Note
This implementation isn't meant to be fast, only correct enough.
The IEEE standard (presumably IEC 60559), requires std::sqrt to be exact to within half of a ULP for floating-point types (float, double). That sets a precedence that puts a high expectation on this implementation for fixed-point types.
"Domain error" occurs if arg is less than zero.
Returns
Mathematical square root value of the given value or the NaN value.
See also
http://en.cppreference.com/w/cpp/numeric/math/sqrt

Definition at line 384 of file FixedMath.hpp.

◆ isnormal()

template<typename BT , unsigned int FB>
bool playrho::isnormal ( Fixed< BT, FB >  arg)
inline

Gets whether the given value is normal - i.e. not 0 nor infinite.

See also
http://en.cppreference.com/w/cpp/numeric/math/isnormal

Definition at line 401 of file FixedMath.hpp.

◆ sin()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::sin ( Fixed< BT, FB >  arg)
inline

Computes the sine of the argument for Fixed types.

See also
http://en.cppreference.com/w/cpp/numeric/math/sin

Definition at line 433 of file FixedMath.hpp.

◆ cos()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::cos ( Fixed< BT, FB >  arg)
inline

Computes the cosine of the argument for Fixed types.

See also
http://en.cppreference.com/w/cpp/numeric/math/cos

Definition at line 442 of file FixedMath.hpp.

◆ atan()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::atan ( Fixed< BT, FB >  arg)
inline

Computes the arc tangent.

See also
http://en.cppreference.com/w/cpp/numeric/math/atan
Returns
Value between -Pi / 2 and Pi / 2.

Definition at line 452 of file FixedMath.hpp.

◆ atan2()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::atan2 ( Fixed< BT, FB >  y,
Fixed< BT, FB >  x 
)
inline

Computes the multi-valued inverse tangent.

See also
http://en.cppreference.com/w/cpp/numeric/math/atan2
Returns
Value between -Pi and +Pi inclusive.

Definition at line 473 of file FixedMath.hpp.

◆ log()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::log ( Fixed< BT, FB >  arg)
inline

Computes the natural logarithm of the given argument.

See also
http://en.cppreference.com/w/cpp/numeric/math/log

Definition at line 499 of file FixedMath.hpp.

◆ exp()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::exp ( Fixed< BT, FB >  arg)
inline

Computes the Euler number raised to the power of the given argument.

See also
http://en.cppreference.com/w/cpp/numeric/math/exp

Definition at line 507 of file FixedMath.hpp.

◆ pow() [2/2]

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::pow ( Fixed< BT, FB >  base,
Fixed< BT, FB >  exponent 
)
inline

Computes the value of the base number raised to the power of the exponent.

See also
http://en.cppreference.com/w/cpp/numeric/math/pow

Definition at line 515 of file FixedMath.hpp.

◆ hypot()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::hypot ( Fixed< BT, FB >  x,
Fixed< BT, FB >  y 
)
inline

Computes the square root of the sum of the squares.

See also
http://en.cppreference.com/w/cpp/numeric/math/hypot

Definition at line 540 of file FixedMath.hpp.

◆ round()

template<typename BT , unsigned int FB>
Fixed<BT, FB> playrho::round ( Fixed< BT, FB >  value)
inlinenoexcept

Rounds the given value.

See also
http://en.cppreference.com/w/cpp/numeric/math/round

Definition at line 548 of file FixedMath.hpp.

◆ signbit()

template<typename BT , unsigned int FB>
bool playrho::signbit ( Fixed< BT, FB >  value)
inlinenoexcept

Determines whether the given value is negative.

See also
http://en.cppreference.com/w/cpp/numeric/math/signbit

Definition at line 558 of file FixedMath.hpp.

◆ isnan()

template<typename BT , unsigned int FB>
PLAYRHO_CONSTEXPR bool playrho::isnan ( Fixed< BT, FB >  value)
inlinenoexcept

Gets whether the given value is not-a-number.

See also
http://en.cppreference.com/w/cpp/numeric/math/isnan

Definition at line 566 of file FixedMath.hpp.

◆ isfinite()

template<typename BT , unsigned int FB>
bool playrho::isfinite ( Fixed< BT, FB >  value)
inlinenoexcept

Gets whether the given value is finite.

See also
http://en.cppreference.com/w/cpp/numeric/math/isfinite

Definition at line 574 of file FixedMath.hpp.