diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2023-01-27 16:39:59 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2023-01-27 16:39:59 +0000 |
commit | 4685c2ab7b4fa785f9ce97a82415585f2e2798ee (patch) | |
tree | 0bf9d0c48ffcdf63a1a0325a3f45cd8629725560 /regress/lib | |
parent | 6970602f634f9a0ca2b55830aba9a081f1c73cc5 (diff) |
Test the behaviour of round() on halfway values.
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libm/round/round.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/regress/lib/libm/round/round.c b/regress/lib/libm/round/round.c index 3423c75cd44..11fff0bd353 100644 --- a/regress/lib/libm/round/round.c +++ b/regress/lib/libm/round/round.c @@ -1,4 +1,4 @@ -/* $OpenBSD: round.c,v 1.2 2011/07/09 03:33:07 martynas Exp $ */ +/* $OpenBSD: round.c,v 1.3 2023/01/27 16:39:58 miod Exp $ */ /* Written by Michael Shalayeff, 2003, Public domain. */ @@ -35,8 +35,8 @@ main(int argc, char *argv[]) sigaction(SIGFPE, &sa, NULL); assert(round(8.6) == 9.); - assert(roundf(8.6F) == 9); - assert(roundl(8.6L) == 9); + assert(roundf(8.6F) == 9.); + assert(roundl(8.6L) == 9.); assert(lround(8.6) == 9L); assert(lroundf(8.6F) == 9L); assert(lroundl(8.6L) == 9L); @@ -51,6 +51,14 @@ main(int argc, char *argv[]) assert(lroundf(-0.0F) == 0L); assert(lroundl(-0.0L) == 0L); + /* Test proper rounding direction of halfway values. */ + assert(round(2.5) == 3.); + assert(roundf(2.5F) == 3.); + assert(roundl(2.5L) == 3.); + assert(round(-2.5) == -3.); + assert(roundf(-2.5F) == -3.); + assert(roundl(-2.5L) == -3.); + assert(llround(4503599627370496.0) == 4503599627370496LL); assert(llroundf(4503599627370496.0F) == 4503599627370496LL); assert(llroundl(4503599627370496.0L) == 4503599627370496LL); |