PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
Math Functions For Fixed Types

Common Mathematical Functions For Fixed Types. More...

Namespaces

 playrho::detail
 Name space for internal/detail related PlayRho names.
 

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>
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
https://en.cppreference.com/w/cpp/numeric/math

Function Documentation

◆ abs()

◆ atan()

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

Computes the arc tangent.

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

Referenced by playrho::atan2().

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/atan2
Returns
Value between -Pi and +Pi inclusive.

Referenced by playrho::Atan2().

◆ cos()

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

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/exp

Referenced by playrho::pow().

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/fmod

Referenced by playrho::detail::AngularNormalize(), and playrho::ModuloViaFmod().

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/hypot

Referenced by playrho::d2::UnitVec::Get().

◆ isfinite()

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

Gets whether the given value is finite.

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

Referenced by playrho::Cross(), and playrho::d2::GetToiViaSat().

◆ isnan()

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

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

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

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/isnormal

Referenced by playrho::d2::UnitVec::Get().

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/log

Referenced by playrho::pow().

◆ nextafter()

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

◆ pow() [1/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
https://en.cppreference.com/w/cpp/numeric/math/pow

◆ pow() [2/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
https://en.cppreference.com/w/cpp/numeric/math/pow

Referenced by playrho::pow().

◆ round()

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

Rounds the given value.

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

Referenced by playrho::RoundOff().

◆ signbit()

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

◆ sin()

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

◆ 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
https://en.cppreference.com/w/cpp/numeric/math/sqrt

Referenced by playrho::d2::Cap(), playrho::d2::UnitVec::Get(), playrho::d2::VertexSet::GetDefaultMinSeparationSquared(), playrho::GetMagnitude(), playrho::hypot(), playrho::MixFriction(), and playrho::d2::RayCast().

◆ trunc()

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