Skip to content

Commit 976ada4

Browse files
MaEtUgRjkflying
authored andcommitted
Matrix: min max comments and test style
1 parent fa7153e commit 976ada4

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

matrix/Matrix.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ template<typename Type>
615615
Type min(const Type x, const Type y) {
616616
bool x_is_nan = isnan(x);
617617
bool y_is_nan = isnan(y);
618-
// z > nan for z != nan is required by C the standard
618+
// take the non-nan value if there is one
619619
if (x_is_nan || y_is_nan) {
620620
if (x_is_nan && !y_is_nan) {
621621
return y;
@@ -625,11 +625,12 @@ Type min(const Type x, const Type y) {
625625
}
626626
return (x < y) ? x : y;
627627
}
628+
628629
template<typename Type>
629630
Type max(const Type x, const Type y) {
630631
bool x_is_nan = isnan(x);
631632
bool y_is_nan = isnan(y);
632-
// z > nan for z != nan is required by C the standard
633+
// take the non-nan value if there is one
633634
if (x_is_nan || y_is_nan) {
634635
if (x_is_nan && !y_is_nan) {
635636
return y;
@@ -639,6 +640,7 @@ Type max(const Type x, const Type y) {
639640
}
640641
return (x > y) ? x : y;
641642
}
643+
642644
template<typename Type>
643645
Type constrain(const Type x, const Type lower_bound, const Type upper_bound) {
644646
if (lower_bound > upper_bound) {

test/matrixAssignment.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,20 @@ int main()
194194
TEST(isEqual(constrain(m10, m10_lower_bound, m10_upper_bound), m10_constrained_ref));
195195

196196
// min, max, constrain with NAN
197-
TEST(isEqualF(matrix::typeFunction::min(5.0f,NAN), 5.0f));
198-
TEST(isEqualF(matrix::typeFunction::min(NAN,5.0f), 5.0f));
199-
TEST(isEqualF(matrix::typeFunction::min(NAN,NAN), NAN));
200-
TEST(isEqualF(matrix::typeFunction::max(5.0f,NAN), 5.0f));
201-
TEST(isEqualF(matrix::typeFunction::max(NAN,5.0f), 5.0f));
202-
TEST(isEqualF(matrix::typeFunction::max(NAN,NAN), NAN));
203-
TEST(isEqualF(matrix::typeFunction::constrain(NAN,5.0f,6.0f), NAN));
204-
TEST(isEqualF(matrix::typeFunction::constrain(1.0f,5.0f,4.0f), NAN));
205-
TEST(isEqualF(matrix::typeFunction::constrain(6.0f,NAN,5.0f), 5.0f));
206-
TEST(isEqualF(matrix::typeFunction::constrain(1.0f,5.0f,NAN), 5.0f));
197+
TEST(isEqualF(matrix::typeFunction::min(5.f, NAN), 5.f));
198+
TEST(isEqualF(matrix::typeFunction::min(NAN, 5.f), 5.f));
199+
TEST(isEqualF(matrix::typeFunction::min(NAN, NAN), NAN));
200+
TEST(isEqualF(matrix::typeFunction::max(5.f, NAN), 5.f));
201+
TEST(isEqualF(matrix::typeFunction::max(NAN, 5.f), 5.f));
202+
TEST(isEqualF(matrix::typeFunction::max(NAN, NAN), NAN));
203+
TEST(isEqualF(matrix::typeFunction::constrain(NAN, 5.f, 6.f), NAN));
204+
TEST(isEqualF(matrix::typeFunction::constrain(1.f, 5.f, 4.f), NAN));
205+
TEST(isEqualF(matrix::typeFunction::constrain(6.f, NAN, 5.f), 5.f));
206+
TEST(isEqualF(matrix::typeFunction::constrain(1.f, 5.f, NAN), 5.f));
207207
Vector2f v1{NAN, 5.0f};
208-
Vector2f v1_min = min(v1,1.0f);
208+
Vector2f v1_min = min(v1, 1.f);
209209
Matrix3f m11 = min(m10_constrained_ref,NAN);
210-
TEST(isEqualF(fmin(NAN,1.0f), float(v1_min(0))));
210+
TEST(isEqualF(fmin(NAN, 1.f), float(v1_min(0))));
211211
TEST(isEqual(m11, m10_constrained_ref));
212212

213213
// check write_string()

0 commit comments

Comments
 (0)