aboutsummaryrefslogtreecommitdiffstats
path: root/tests/math_test.cpp
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2014-09-04 12:47:07 -0700
committerDmitriy Ivanov <dimitry@google.com>2014-09-04 18:38:21 -0700
commit7b956ede3f0f40bd8a085a8ad3729bb3e0e030f2 (patch)
treeb917b5aaa05f3bbc147d041e46e10ab5153f29a5 /tests/math_test.cpp
parent44352f5f7f06ff9383d695b0a7d4243f5268f430 (diff)
downloadandroid_bionic-7b956ede3f0f40bd8a085a8ad3729bb3e0e030f2.tar.gz
android_bionic-7b956ede3f0f40bd8a085a8ad3729bb3e0e030f2.tar.bz2
android_bionic-7b956ede3f0f40bd8a085a8ad3729bb3e0e030f2.zip
Reset enviroment for math_tests
Bug: 17390824 Change-Id: I42f4c8d9199a2efe7641f0b0e64580cacb5695da
Diffstat (limited to 'tests/math_test.cpp')
-rw-r--r--tests/math_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index b4f5b1427..ad4654e53 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -53,6 +53,8 @@ template<typename T> inline int test_capture_isinf(const T in) {
#include <limits.h>
#include <stdint.h>
+#include <private/ScopeGuard.h>
+
float float_subnormal() {
union {
float f;
@@ -760,6 +762,10 @@ TEST(math, erfcl) {
}
TEST(math, lrint) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
+
fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
ASSERT_EQ(1235, lrint(1234.01));
ASSERT_EQ(1235, lrintf(1234.01f));
@@ -780,6 +786,10 @@ TEST(math, lrint) {
}
TEST(math, rint) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
+
fesetround(FE_UPWARD); // rint/rintf/rintl obey the rounding mode.
feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
ASSERT_EQ(1234.0, rint(1234.0));
@@ -806,6 +816,9 @@ TEST(math, rint) {
}
TEST(math, nearbyint) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
ASSERT_EQ(1234.0, nearbyint(1234.0));
@@ -832,6 +845,9 @@ TEST(math, nearbyint) {
}
TEST(math, lround) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // lround ignores the rounding mode.
ASSERT_EQ(1234, lround(1234.01));
ASSERT_EQ(1234, lroundf(1234.01f));
@@ -839,6 +855,9 @@ TEST(math, lround) {
}
TEST(math, llround) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // llround ignores the rounding mode.
ASSERT_EQ(1234L, llround(1234.01));
ASSERT_EQ(1234L, llroundf(1234.01f));
@@ -933,6 +952,9 @@ TEST(math, fdiml) {
}
TEST(math, round) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_TOWARDZERO); // round ignores the rounding mode and always rounds away from zero.
ASSERT_DOUBLE_EQ(1.0, round(0.5));
ASSERT_DOUBLE_EQ(-1.0, round(-0.5));
@@ -943,6 +965,9 @@ TEST(math, round) {
}
TEST(math, roundf) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_TOWARDZERO); // roundf ignores the rounding mode and always rounds away from zero.
ASSERT_FLOAT_EQ(1.0f, roundf(0.5f));
ASSERT_FLOAT_EQ(-1.0f, roundf(-0.5f));
@@ -953,6 +978,9 @@ TEST(math, roundf) {
}
TEST(math, roundl) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero.
ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L));
ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L));
@@ -963,6 +991,9 @@ TEST(math, roundl) {
}
TEST(math, trunc) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // trunc ignores the rounding mode and always rounds toward zero.
ASSERT_DOUBLE_EQ(1.0, trunc(1.5));
ASSERT_DOUBLE_EQ(-1.0, trunc(-1.5));
@@ -973,6 +1004,9 @@ TEST(math, trunc) {
}
TEST(math, truncf) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // truncf ignores the rounding mode and always rounds toward zero.
ASSERT_FLOAT_EQ(1.0f, truncf(1.5f));
ASSERT_FLOAT_EQ(-1.0f, truncf(-1.5f));
@@ -983,6 +1017,9 @@ TEST(math, truncf) {
}
TEST(math, truncl) {
+ auto guard = create_scope_guard([]() {
+ fesetenv(FE_DFL_ENV);
+ });
fesetround(FE_UPWARD); // truncl ignores the rounding mode and always rounds toward zero.
ASSERT_DOUBLE_EQ(1.0L, truncl(1.5L));
ASSERT_DOUBLE_EQ(-1.0L, truncl(-1.5L));