Fix math tests.
Bug: 13657654
Change-Id: I39b2f13b5b3d3e6897618ac3aed49a0a08458dd0
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index 80083fa..c1a9f4f 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -1226,6 +1226,11 @@
double di;
double df = modf(123.456, &di);
ASSERT_DOUBLE_EQ(123.0, di);
+ // ASSERT_DOUBLE uses more decimals than the double precision when performing
+ // the comparison which can result in false failures. And it seems that modf
+ // results are not 100% precise as expected but within the acceptable delta.
+ // Work around this by tweaking the expected value (taken) from the result of
+ // glibc modf).
ASSERT_DOUBLE_EQ(0.45600000000000307, df);
}
@@ -1233,6 +1238,7 @@
float fi;
float ff = modff(123.456f, &fi);
ASSERT_FLOAT_EQ(123.0f, fi);
+ // See modf comment on why we don't use 0.456f as an excepted value.
ASSERT_FLOAT_EQ(0.45600128f, ff);
}
@@ -1240,7 +1246,14 @@
long double ldi;
long double ldf = modfl(123.456l, &ldi);
ASSERT_DOUBLE_EQ(123.0l, ldi);
- ASSERT_DOUBLE_EQ(0.45600000000000002l, ldf);
+ // See modf comment on why we don't use 0.456l as an excepted value when the
+ // modf == modfl. For LP64, where long double != double, modfl algorithm
+ // gives precise results and thus we don't need to tweak the expected value.
+#if defined(__LP64__) || !defined(__BIONIC__)
+ ASSERT_DOUBLE_EQ(0.456l, ldf);
+#else
+ ASSERT_DOUBLE_EQ(0.45600000000000307, ldf);
+#endif // __LP64__ || !__BIONIC__
}
TEST(math, remquo) {