diff options
| author | he <he@NetBSD.org> | 2017-07-24 18:14:46 +0000 |
|---|---|---|
| committer | he <he@NetBSD.org> | 2017-07-24 18:14:46 +0000 |
| commit | edd3b9e2e241c9b0ec007bb8db104dafb77feb24 (patch) | |
| tree | 05f754c91e335498da232dba0cd44832b99671a0 /tests/lib/libm | |
| parent | 7fbbd6eb5d8160e17937eedf32cdd2f9ddbb8673 (diff) | |
Add a test checking nearbyint(), using the same table as used by
the existing lrint() test.
Diffstat (limited to 'tests/lib/libm')
| -rw-r--r-- | tests/lib/libm/t_fe_round.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/lib/libm/t_fe_round.c b/tests/lib/libm/t_fe_round.c index 8d94d02821c..0988f5018f3 100644 --- a/tests/lib/libm/t_fe_round.c +++ b/tests/lib/libm/t_fe_round.c @@ -93,10 +93,40 @@ ATF_TC_BODY(fe_round, tc) } } +ATF_TC(fe_nearbyint); +ATF_TC_HEAD(fe_nearbyint, tc) +{ + atf_tc_set_md_var(tc, "descr","Checking IEEE 754 rounding modes using nearbyint"); +} + +ATF_TC_BODY(fe_nearbyint, tc) +{ + double received; + + for (unsigned int i = 0; i < __arraycount(values); i++) { + fesetround(values[i].round_mode); + + received = nearbyint(values[i].input); + ATF_CHECK_MSG( + (fabs(received - values[i].expected) < EPSILON), + "nearbyint rounding wrong, difference too large\n" + "input: %f (index %d): got %f, expected %ld\n", + values[i].input, i, received, values[i].expected); + + /* Do we get the same rounding mode out? */ + ATF_CHECK_MSG( + (fegetround() == values[i].round_mode), + "Didn't get the same rounding mode out!\n" + "(index %d) fed in %d rounding mode, got %d out\n", + i, values[i].round_mode, fegetround()); + } +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fe_round); + ATF_TP_ADD_TC(tp, fe_nearbyint); return atf_no_error(); } @@ -109,15 +139,27 @@ ATF_TC_HEAD(t_nofe_round, tc) "dummy test case - no fenv.h support"); } - ATF_TC_BODY(t_nofe_round, tc) { atf_tc_skip("no fenv.h support on this architecture"); } +ATF_TC_HEAD(t_nofe_nearbyint, tc) +{ + atf_tc_set_md_var(tc, "descr", + "dummy test case - no fenv.h support"); +} + +ATF_TC_BODY(t_nofe_nearbyint, tc) +{ + atf_tc_skip("no fenv.h support on this architecture"); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_nofe_round); + ATF_TP_ADD_TC(tp, t_nofe_nearbyint); return atf_no_error(); } |
