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.
Function Documentation
◆ abs()
|
inlineconstexpr |
Computes the absolute value.
Definition at line 48 of file FixedMath.hpp.
◆ pow() [1/2]
|
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.
Definition at line 59 of file FixedMath.hpp.
◆ trunc()
|
inlineconstexpr |
Truncates the given value.
Definition at line 343 of file FixedMath.hpp.
◆ nextafter()
|
inlinenoexcept |
Next after function for Fixed types.
- Examples
- World.cpp.
Definition at line 351 of file FixedMath.hpp.
◆ fmod()
|
inlinenoexcept |
Computes the remainder of the division of the given dividend by the given divisor.
Definition at line 367 of file FixedMath.hpp.
◆ sqrt()
|
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.
Definition at line 384 of file FixedMath.hpp.
◆ isnormal()
|
inline |
Gets whether the given value is normal - i.e. not 0 nor infinite.
Definition at line 401 of file FixedMath.hpp.
◆ sin()
Computes the sine of the argument for Fixed types.
Definition at line 433 of file FixedMath.hpp.
◆ cos()
Computes the cosine of the argument for Fixed types.
Definition at line 442 of file FixedMath.hpp.
◆ atan()
Computes the arc tangent.
- Returns
- Value between
-Pi / 2
andPi / 2
.
Definition at line 452 of file FixedMath.hpp.
◆ atan2()
|
inline |
Computes the multi-valued inverse tangent.
- Returns
- Value between
-Pi
and+Pi
inclusive.
Definition at line 473 of file FixedMath.hpp.
◆ log()
Computes the natural logarithm of the given argument.
Definition at line 499 of file FixedMath.hpp.
◆ exp()
Computes the Euler number raised to the power of the given argument.
Definition at line 507 of file FixedMath.hpp.
◆ pow() [2/2]
|
inline |
Computes the value of the base number raised to the power of the exponent.
Definition at line 515 of file FixedMath.hpp.
◆ hypot()
|
inline |
Computes the square root of the sum of the squares.
Definition at line 540 of file FixedMath.hpp.
◆ round()
|
inlinenoexcept |
Rounds the given value.
Definition at line 548 of file FixedMath.hpp.
◆ signbit()
|
inlinenoexcept |
Determines whether the given value is negative.
Definition at line 558 of file FixedMath.hpp.
◆ isnan()
|
inlinenoexcept |
Gets whether the given value is not-a-number.
Definition at line 566 of file FixedMath.hpp.
◆ isfinite()
|
inlinenoexcept |
Gets whether the given value is finite.
Definition at line 574 of file FixedMath.hpp.