summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2023-08-13 06:57:04 +0000
committermiod <>2023-08-13 06:57:04 +0000
commit3cde1bdecc67ca754135cb159062a3f18e09068f (patch)
tree516e3a997ce572dca6ef2c0d0ab4a370df6ead8b
parent7fba0dd806cbf48616276dd791ca6454190d90a6 (diff)
downloadopenbsd-3cde1bdecc67ca754135cb159062a3f18e09068f.tar.gz
openbsd-3cde1bdecc67ca754135cb159062a3f18e09068f.tar.bz2
openbsd-3cde1bdecc67ca754135cb159062a3f18e09068f.zip
Extent the modf() tests; from Willemijn Coene.
-rw-r--r--src/regress/lib/libc/modf/modf_test.c68
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
9int 11void
10main(void) 12modf_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
34void
35modf_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
62int
63main(void)
64{
65 modf_sparc();
66 modf_infnan();
35} 67}