mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +08:00
AP_Math: add separate double and float implementations for wrap_PI and wrap_2PI
avoids double promotion when the argument is not double
This commit is contained in:
committed by
Andrew Tridgell
parent
aeacb3b6fd
commit
0c26780cce
@@ -248,23 +248,40 @@ long wrap_360_cd(const long angle)
|
||||
return res;
|
||||
}
|
||||
|
||||
ftype wrap_PI(const ftype radian)
|
||||
float wrap_2PI(const float radian)
|
||||
{
|
||||
ftype res = wrap_2PI(radian);
|
||||
if (res > M_PI) {
|
||||
res -= M_2PI;
|
||||
float res = fmodf(radian, float(M_2PI));
|
||||
if (res < 0) {
|
||||
res += float(M_2PI);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
ftype wrap_2PI(const ftype radian)
|
||||
#if AP_MATH_ALLOW_DOUBLE_FUNCTIONS
|
||||
double wrap_2PI(const double radian)
|
||||
{
|
||||
ftype res = fmodF(radian, M_2PI);
|
||||
double res = fmod(radian, M_2PI);
|
||||
if (res < 0) {
|
||||
res += M_2PI;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
T wrap_PI(const T radian)
|
||||
{
|
||||
T res = wrap_2PI(radian);
|
||||
if (res > T(M_PI)) {
|
||||
res -= T(M_2PI);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template float wrap_PI<float>(const float radian);
|
||||
#if AP_MATH_ALLOW_DOUBLE_FUNCTIONS
|
||||
template double wrap_PI<double>(const double radian);
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
T constrain_value_line(const T amt, const T low, const T high, uint32_t line)
|
||||
|
||||
Reference in New Issue
Block a user