AP_Math: create a constrain_int64
The template system doesn't work across 32/64 bit builds (SITL vs fmuv4), probably because int is typedef'd to int64
This commit is contained in:
parent
01e0c03a12
commit
6af0dcfed0
@ -201,6 +201,7 @@ T constrain_value(const T amt, const T low, const T high)
|
||||
|
||||
template int constrain_value<int>(const int amt, const int low, const int high);
|
||||
template long constrain_value<long>(const long amt, const long low, const long high);
|
||||
template long long constrain_value<long long>(const long long amt, const long long low, const long long high);
|
||||
template short constrain_value<short>(const short amt, const short low, const short high);
|
||||
template float constrain_value<float>(const float amt, const float low, const float high);
|
||||
template double constrain_value<double>(const double amt, const double low, const double high);
|
||||
|
@ -154,6 +154,11 @@ inline int32_t constrain_int32(const int32_t amt, const int32_t low, const int32
|
||||
return constrain_value(amt, low, high);
|
||||
}
|
||||
|
||||
inline int64_t constrain_int64(const int64_t amt, const int64_t low, const int64_t high)
|
||||
{
|
||||
return constrain_value(amt, low, high);
|
||||
}
|
||||
|
||||
// degrees -> radians
|
||||
static inline constexpr float radians(float deg)
|
||||
{
|
||||
|
@ -128,14 +128,17 @@ TEST(MathTest, Constrain)
|
||||
EXPECT_EQ(250, constrain_float(i, 250, 500));
|
||||
EXPECT_EQ(250, constrain_int16(i, 250, 500));
|
||||
EXPECT_EQ(250, constrain_int32(i, 250, 500));
|
||||
EXPECT_EQ(250, constrain_int64(i, 250, 500));
|
||||
} else if (i > 500) {
|
||||
EXPECT_EQ(500, constrain_float(i, 250, 500));
|
||||
EXPECT_EQ(500, constrain_int16(i, 250, 500));
|
||||
EXPECT_EQ(500, constrain_int32(i, 250, 500));
|
||||
EXPECT_EQ(500, constrain_int64(i, 250, 500));
|
||||
} else {
|
||||
EXPECT_EQ(i, constrain_float(i, 250, 500));
|
||||
EXPECT_EQ(i, constrain_int16(i, 250, 500));
|
||||
EXPECT_EQ(i, constrain_int32(i, 250, 500));
|
||||
EXPECT_EQ(i, constrain_int64(i, 250, 500));
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,14 +148,17 @@ TEST(MathTest, Constrain)
|
||||
EXPECT_EQ(-250, constrain_float(c, -250, -50));
|
||||
EXPECT_EQ(-250, constrain_int16(c, -250, -50));
|
||||
EXPECT_EQ(-250, constrain_int32(c, -250, -50));
|
||||
EXPECT_EQ(-250, constrain_int64(c, -250, -50));
|
||||
} else if(c > -50) {
|
||||
EXPECT_EQ(-50, constrain_float(c, -250, -50));
|
||||
EXPECT_EQ(-50, constrain_int16(c, -250, -50));
|
||||
EXPECT_EQ(-50, constrain_int32(c, -250, -50));
|
||||
EXPECT_EQ(-50, constrain_int64(c, -250, -50));
|
||||
} else {
|
||||
EXPECT_EQ(c, constrain_float(c, -250, -50));
|
||||
EXPECT_EQ(c, constrain_int16(c, -250, -50));
|
||||
EXPECT_EQ(c, constrain_int32(c, -250, -50));
|
||||
EXPECT_EQ(c, constrain_int64(c, -250, -50));
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,14 +168,17 @@ TEST(MathTest, Constrain)
|
||||
EXPECT_EQ(-250, constrain_float(c, -250, 50));
|
||||
EXPECT_EQ(-250, constrain_int16(c, -250, 50));
|
||||
EXPECT_EQ(-250, constrain_int32(c, -250, 50));
|
||||
EXPECT_EQ(-250, constrain_int64(c, -250, 50));
|
||||
} else if(c > 50) {
|
||||
EXPECT_EQ(50, constrain_float(c, -250, 50));
|
||||
EXPECT_EQ(50, constrain_int16(c, -250, 50));
|
||||
EXPECT_EQ(50, constrain_int32(c, -250, 50));
|
||||
EXPECT_EQ(50, constrain_int64(c, -250, 50));
|
||||
} else {
|
||||
EXPECT_EQ(c, constrain_float(c, -250, 50));
|
||||
EXPECT_EQ(c, constrain_int16(c, -250, 50));
|
||||
EXPECT_EQ(c, constrain_int32(c, -250, 50));
|
||||
EXPECT_EQ(c, constrain_int64(c, -250, 50));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user