diff options
-rw-r--r-- | src/regress/lib/libc/Makefile | 4 | ||||
-rw-r--r-- | src/regress/lib/libc/ldexp/Makefile | 5 | ||||
-rw-r--r-- | src/regress/lib/libc/ldexp/ldexp_test.c | 75 |
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 | ||
3 | SUBDIR+= _setjmp | 3 | SUBDIR+= _setjmp |
4 | SUBDIR+= alloca arc4random-fork atexit | 4 | SUBDIR+= alloca arc4random-fork atexit |
@@ -10,7 +10,7 @@ SUBDIR+= fmemopen fnmatch fpclassify | |||
10 | SUBDIR+= getaddrinfo getcap getopt_long glob | 10 | SUBDIR+= getaddrinfo getcap getopt_long glob |
11 | SUBDIR+= hsearch | 11 | SUBDIR+= hsearch |
12 | SUBDIR+= ieeefp ifnameindex | 12 | SUBDIR+= ieeefp ifnameindex |
13 | SUBDIR+= longjmp locale | 13 | SUBDIR+= ldexp longjmp locale |
14 | SUBDIR+= malloc mkstemp modf | 14 | SUBDIR+= malloc mkstemp modf |
15 | SUBDIR+= netdb | 15 | SUBDIR+= netdb |
16 | SUBDIR+= open_memstream orientation | 16 | SUBDIR+= 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 | |||
3 | PROG=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 | |||
22 | int | ||
23 | main(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 | } | ||