diff options
| author | miod <> | 2023-08-13 06:57:04 +0000 |
|---|---|---|
| committer | miod <> | 2023-08-13 06:57:04 +0000 |
| commit | f1bd0522263db179f22b3cb92f6f7085fc960a84 (patch) | |
| tree | 516e3a997ce572dca6ef2c0d0ab4a370df6ead8b /src | |
| parent | ff25cebf99dc89ae5dbe6c9e30440c9a0a156804 (diff) | |
| download | openbsd-f1bd0522263db179f22b3cb92f6f7085fc960a84.tar.gz openbsd-f1bd0522263db179f22b3cb92f6f7085fc960a84.tar.bz2 openbsd-f1bd0522263db179f22b3cb92f6f7085fc960a84.zip | |
Extent the modf() tests; from Willemijn Coene.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/modf/modf_test.c | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/src/regress/lib/libc/modf/modf_test.c b/src/regress/lib/libc/modf/modf_test.c index f732533635..b96618e1f0 100644 --- a/src/regress/lib/libc/modf/modf_test.c +++ b/src/regress/lib/libc/modf/modf_test.c | |||
| @@ -1,35 +1,67 @@ | |||
| 1 | /* Public domain, 2014, Tobias Ulmer <tobiasu@tmux.org> */ | 1 | /* $OpenBSD: modf_test.c,v 1.2 2023/08/13 06:57:04 miod Exp $ */ |
| 2 | |||
| 3 | /* Test for bug introduced in 4.4BSD modf() on sparc */ | ||
| 4 | 2 | ||
| 3 | #include <assert.h> | ||
| 5 | #include <math.h> | 4 | #include <math.h> |
| 6 | 5 | ||
| 6 | /* Test for bug introduced in 4.4BSD modf() on sparc */ | ||
| 7 | /* Public domain, 2014, Tobias Ulmer <tobiasu@tmux.org> */ | ||
| 8 | |||
| 7 | #define BIGFLOAT (5e15) /* Number large enough to trigger the "big" case */ | 9 | #define BIGFLOAT (5e15) /* Number large enough to trigger the "big" case */ |
| 8 | 10 | ||
| 9 | int | 11 | void |
| 10 | main(void) | 12 | modf_sparc(void) |
| 11 | { | 13 | { |
| 12 | double f, i; | 14 | double f, i; |
| 13 | 15 | ||
| 14 | f = modf(BIGFLOAT, &i); | 16 | f = modf(BIGFLOAT, &i); |
| 15 | if (i != BIGFLOAT) | 17 | assert(i == BIGFLOAT); |
| 16 | return 1; | 18 | assert(f == 0.0); |
| 17 | if (f != 0.0) | ||
| 18 | return 1; | ||
| 19 | 19 | ||
| 20 | /* Repeat, maybe we were lucky */ | 20 | /* Repeat, maybe we were lucky */ |
| 21 | f = modf(BIGFLOAT, &i); | 21 | f = modf(BIGFLOAT, &i); |
| 22 | if (i != BIGFLOAT) | 22 | assert(i == BIGFLOAT); |
| 23 | return 1; | 23 | assert(f == 0.0); |
| 24 | if (f != 0.0) | ||
| 25 | return 1; | ||
| 26 | 24 | ||
| 27 | /* With negative number, for good measure */ | 25 | /* With negative number, for good measure */ |
| 28 | f = modf(-BIGFLOAT, &i); | 26 | f = modf(-BIGFLOAT, &i); |
| 29 | if (i != -BIGFLOAT) | 27 | assert(i == -BIGFLOAT); |
| 30 | return 1; | 28 | assert(f == 0.0); |
| 31 | if (f != 0.0) | 29 | } |
| 32 | return 1; | ||
| 33 | 30 | ||
| 34 | return 0; | 31 | /* Test for modf() behaviour on Inf and Nan */ |
| 32 | /* Written by Willemijn Coene. Public domain */ | ||
| 33 | |||
| 34 | void | ||
| 35 | modf_infnan(void) | ||
| 36 | { | ||
| 37 | double f, i; | ||
| 38 | |||
| 39 | f = modf(__builtin_inf(), &i); | ||
| 40 | assert(isinf(i)); | ||
| 41 | assert(signbit(i) == 0); | ||
| 42 | assert(f == 0.0); | ||
| 43 | |||
| 44 | f = modf(-__builtin_inf(), &i); | ||
| 45 | assert(isinf(i)); | ||
| 46 | assert(signbit(i) != 0); | ||
| 47 | assert(f == -0.0); | ||
| 48 | |||
| 49 | f = modf(NAN, &i); | ||
| 50 | assert(isnan(i)); | ||
| 51 | assert(signbit(i) == 0); | ||
| 52 | assert(isnan(f)); | ||
| 53 | assert(signbit(f) == 0); | ||
| 54 | |||
| 55 | f = modf(-NAN, &i); | ||
| 56 | assert(isnan(i)); | ||
| 57 | assert(signbit(i) != 0); | ||
| 58 | assert(isnan(f)); | ||
| 59 | assert(signbit(f) != 0); | ||
| 60 | } | ||
| 61 | |||
| 62 | int | ||
| 63 | main(void) | ||
| 64 | { | ||
| 65 | modf_sparc(); | ||
| 66 | modf_infnan(); | ||
| 35 | } | 67 | } |
