summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvisa <>2017-10-15 12:15:30 +0000
committervisa <>2017-10-15 12:15:30 +0000
commit2730ecb4adb4efcd9352c1fc403b4ca9791c054d (patch)
tree2b56ab0b8e16ace46d11892234657618f6d88b7b
parent31480a4cf9b7421dfffa30591096c6e8854f1638 (diff)
downloadopenbsd-2730ecb4adb4efcd9352c1fc403b4ca9791c054d.tar.gz
openbsd-2730ecb4adb4efcd9352c1fc403b4ca9791c054d.tar.bz2
openbsd-2730ecb4adb4efcd9352c1fc403b4ca9791c054d.zip
Add a regression test for ldexp(3).
-rw-r--r--src/regress/lib/libc/Makefile4
-rw-r--r--src/regress/lib/libc/ldexp/Makefile5
-rw-r--r--src/regress/lib/libc/ldexp/ldexp_test.c75
3 files changed, 82 insertions, 2 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile
index c91456d826..0530008c49 100644
--- a/src/regress/lib/libc/Makefile
+++ b/src/regress/lib/libc/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.50 2017/07/27 17:56:35 bluhm Exp $ 1# $OpenBSD: Makefile,v 1.51 2017/10/15 12:15:30 visa Exp $
2 2
3SUBDIR+= _setjmp 3SUBDIR+= _setjmp
4SUBDIR+= alloca arc4random-fork atexit 4SUBDIR+= alloca arc4random-fork atexit
@@ -10,7 +10,7 @@ SUBDIR+= fmemopen fnmatch fpclassify
10SUBDIR+= getaddrinfo getcap getopt_long glob 10SUBDIR+= getaddrinfo getcap getopt_long glob
11SUBDIR+= hsearch 11SUBDIR+= hsearch
12SUBDIR+= ieeefp ifnameindex 12SUBDIR+= ieeefp ifnameindex
13SUBDIR+= longjmp locale 13SUBDIR+= ldexp longjmp locale
14SUBDIR+= malloc mkstemp modf 14SUBDIR+= malloc mkstemp modf
15SUBDIR+= netdb 15SUBDIR+= netdb
16SUBDIR+= open_memstream orientation 16SUBDIR+= open_memstream orientation
diff --git a/src/regress/lib/libc/ldexp/Makefile b/src/regress/lib/libc/ldexp/Makefile
new file mode 100644
index 0000000000..bfe79ac679
--- /dev/null
+++ b/src/regress/lib/libc/ldexp/Makefile
@@ -0,0 +1,5 @@
1# $OpenBSD: Makefile,v 1.1 2017/10/15 12:15:30 visa Exp $
2
3PROG=ldexp_test
4
5.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/ldexp/ldexp_test.c b/src/regress/lib/libc/ldexp/ldexp_test.c
new file mode 100644
index 0000000000..75031e3083
--- /dev/null
+++ b/src/regress/lib/libc/ldexp/ldexp_test.c
@@ -0,0 +1,75 @@
1/* $OpenBSD: ldexp_test.c,v 1.1 2017/10/15 12:15:30 visa Exp $ */
2
3/*
4 * Copyright (c) 2017 Visa Hankala
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <assert.h>
20#include <math.h>
21
22int
23main(int argc, char *argv[])
24{
25 double f;
26
27 /*
28 * Test that the result has the correct sign.
29 * Assumes IEEE 754 double-precision arithmetics.
30 */
31
32 assert(ldexp(1.0, -1022) > 0.0); /* IEEE 754 minimum normal positive */
33 assert(ldexp(1.0, -1023) > 0.0); /* subnormal positive */
34 assert(ldexp(1.0, -1024) > 0.0); /* subnormal positive */
35 assert(ldexp(1.0, -1074) > 0.0); /* minimum subnormal positive */
36 assert(ldexp(1.0, -1075) >= 0.0); /* zero */
37 assert(ldexp(ldexp(1.0, -1022), -53) >= 0.0); /* zero */
38
39 assert(ldexp(1.0, 1023) > 0.0); /* normal positive */
40
41 f = ldexp(1.0, 1024); /* infinite positive */
42 assert(isinf(f));
43 assert(!signbit(f));
44
45 f = ldexp(ldexp(1.0, 1023), 1); /* infinite positive */
46 assert(isinf(f));
47 assert(!signbit(f));
48
49 assert(ldexp(-1.0, -1022) < 0.0); /* IEEE 754 maximum normal negative */
50 assert(ldexp(-1.0, -1023) < 0.0); /* subnormal negative */
51 assert(ldexp(-1.0, -1024) < 0.0); /* subnormal negative */
52 assert(ldexp(-1.0, -1074) < 0.0); /* maximum subnormal negative */
53 assert(ldexp(-1.0, -1075) <= 0.0); /* zero */
54 assert(ldexp(ldexp(-1.0, -1022), -53) <= 0.0); /* zero */
55
56 assert(ldexp(-1.0, 1023) < 0.0); /* normal negative */
57
58 f = ldexp(-1.0, 1024); /* infinite negative */
59 assert(isinf(f));
60 assert(signbit(f));
61
62 f = ldexp(ldexp(-1.0, 1023), 1); /* infinite negative */
63 assert(isinf(f));
64 assert(signbit(f));
65
66 f = ldexp(NAN, 0);
67 assert(isnan(f));
68 assert(!signbit(f));
69
70 f = ldexp(-NAN, 0);
71 assert(isnan(f));
72 assert(signbit(f));
73
74 return 0;
75}