mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-12 13:17:34 +08:00
Matrix: min max comments and test style
This commit is contained in:
committed by
Julian Kent
parent
fa7153ecfb
commit
976ada411b
+4
-2
@@ -615,7 +615,7 @@ template<typename Type>
|
||||
Type min(const Type x, const Type y) {
|
||||
bool x_is_nan = isnan(x);
|
||||
bool y_is_nan = isnan(y);
|
||||
// z > nan for z != nan is required by C the standard
|
||||
// take the non-nan value if there is one
|
||||
if (x_is_nan || y_is_nan) {
|
||||
if (x_is_nan && !y_is_nan) {
|
||||
return y;
|
||||
@@ -625,11 +625,12 @@ Type min(const Type x, const Type y) {
|
||||
}
|
||||
return (x < y) ? x : y;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
Type max(const Type x, const Type y) {
|
||||
bool x_is_nan = isnan(x);
|
||||
bool y_is_nan = isnan(y);
|
||||
// z > nan for z != nan is required by C the standard
|
||||
// take the non-nan value if there is one
|
||||
if (x_is_nan || y_is_nan) {
|
||||
if (x_is_nan && !y_is_nan) {
|
||||
return y;
|
||||
@@ -639,6 +640,7 @@ Type max(const Type x, const Type y) {
|
||||
}
|
||||
return (x > y) ? x : y;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
Type constrain(const Type x, const Type lower_bound, const Type upper_bound) {
|
||||
if (lower_bound > upper_bound) {
|
||||
|
||||
+12
-12
@@ -194,20 +194,20 @@ int main()
|
||||
TEST(isEqual(constrain(m10, m10_lower_bound, m10_upper_bound), m10_constrained_ref));
|
||||
|
||||
// min, max, constrain with NAN
|
||||
TEST(isEqualF(matrix::typeFunction::min(5.0f,NAN), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::min(NAN,5.0f), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::min(NAN,NAN), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::max(5.0f,NAN), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::max(NAN,5.0f), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::max(NAN,NAN), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(NAN,5.0f,6.0f), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(1.0f,5.0f,4.0f), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(6.0f,NAN,5.0f), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(1.0f,5.0f,NAN), 5.0f));
|
||||
TEST(isEqualF(matrix::typeFunction::min(5.f, NAN), 5.f));
|
||||
TEST(isEqualF(matrix::typeFunction::min(NAN, 5.f), 5.f));
|
||||
TEST(isEqualF(matrix::typeFunction::min(NAN, NAN), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::max(5.f, NAN), 5.f));
|
||||
TEST(isEqualF(matrix::typeFunction::max(NAN, 5.f), 5.f));
|
||||
TEST(isEqualF(matrix::typeFunction::max(NAN, NAN), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(NAN, 5.f, 6.f), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(1.f, 5.f, 4.f), NAN));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(6.f, NAN, 5.f), 5.f));
|
||||
TEST(isEqualF(matrix::typeFunction::constrain(1.f, 5.f, NAN), 5.f));
|
||||
Vector2f v1{NAN, 5.0f};
|
||||
Vector2f v1_min = min(v1,1.0f);
|
||||
Vector2f v1_min = min(v1, 1.f);
|
||||
Matrix3f m11 = min(m10_constrained_ref,NAN);
|
||||
TEST(isEqualF(fmin(NAN,1.0f), float(v1_min(0))));
|
||||
TEST(isEqualF(fmin(NAN, 1.f), float(v1_min(0))));
|
||||
TEST(isEqual(m11, m10_constrained_ref));
|
||||
|
||||
// check write_string()
|
||||
|
||||
Reference in New Issue
Block a user