annotate tests/test-frexp.c @ 9850:7f3ed6b093be

Guarantee a definition of NAN. * lib/math.in.h (NAN): Define if missing. * tests/test-math.c (main): Test it. * doc/posix-headers/math.texi (math.h): Document this. * lib/isnan.c (rpl_isnand): Use it. * tests/test-ceilf1.c (NaN): Delete, and use NAN instead. * tests/test-floorf1.c (NaN): Likewise. * tests/test-frexp.c (NaN): Likewise. * tests/test-isnand.c (NaN): Likewise. * tests/test-isnanf.c (NaN): Likewise. * tests/test-round1.c (NaN): Likewise. * tests/test-roundf1.c (NaN): Likewise. * tests/test-snprintf-posix.h (NaN): Likewise. * tests/test-sprintf-posix.h (NaN): Likewise. * tests/test-trunc1.c (NaN): Likewise. * tests/test-truncf1.c (NaN): Likewise. * tests/test-vasnprintf-posix.c (NaN): Likewise. * tests/test-vasprintf-posix.c (NaN): Likewise. * modules/isnand-nolibm (Depends-on): Add math. * modules/isnanf-nolibm (Depends-on): Likewise. * modules/isnanl (Depends-on): Likewise. * modules/isnanl-nolibm (Depends-on): Likewise. * modules/snprintf-posix-tests (Depends-on): Likewise. * modules/sprintf-posix-tests (Depends-on): Likewise. * modules/vsnprintf-posix-tests (Depends-on): Likewise. * modules/vsprintf-posix-tests (Depends-on): Likewise. * modules/vasnprintf-posix-tests (Depends-on): Likewise. * modules/vasprintf-posix-tests (Depends-on): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Mon, 31 Mar 2008 20:56:25 -0600
parents a113e473cc98
children baba3b346ab2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of splitting a double into fraction and mantissa.
9646
a113e473cc98 Rename isnan, applicable to 'double' only, to isnand.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
4 This program is free software: you can redistribute it and/or modify
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
7 (at your option) any later version.
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <float.h>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
24 #include <stdio.h>
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
9646
a113e473cc98 Rename isnan, applicable to 'double' only, to isnand.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
27 #include "isnand.h"
8545
418f381347dc Work around IRIX 6.5 cc compiler bug, which simplifies x != x to false.
Bruno Haible <bruno@clisp.org>
parents: 8543
diff changeset
28
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
29 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
30 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
31 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
32 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
33 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
35 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
36 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
37 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8654
diff changeset
38 while (0)
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 static double
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 my_ldexp (double x, int d)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 for (; d > 0; d--)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 x *= 2.0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 for (; d < 0; d++)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 x *= 0.5;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 return x;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 int
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 main ()
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 int i;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 /* The use of 'volatile' guarantees that excess precision bits are dropped
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 when dealing with denormalized numbers. It is necessary on x86 systems
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 where double-floats are not IEEE compliant by default, to avoid that the
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 results become platform and compiler option dependent. 'volatile' is a
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 portable alternative to gcc's -ffloat-store option. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 volatile double x;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 { /* NaN. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 double mantissa;
9850
7f3ed6b093be Guarantee a definition of NAN.
Eric Blake <ebb9@byu.net>
parents: 9646
diff changeset
64 x = NAN;
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 mantissa = frexp (x, &exp);
9646
a113e473cc98 Rename isnan, applicable to 'double' only, to isnand.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
66 ASSERT (isnand (mantissa));
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 { /* Positive infinity. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 double mantissa;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 x = 1.0 / 0.0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 ASSERT (mantissa == x);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 { /* Negative infinity. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 double mantissa;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 x = -1.0 / 0.0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 ASSERT (mantissa == x);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 { /* Positive zero. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 double mantissa;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 x = 0.0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 ASSERT (exp == 0);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ASSERT (mantissa == x);
8654
a2bc90a7b7aa Test also the sign bit of zero results.
Bruno Haible <bruno@clisp.org>
parents: 8545
diff changeset
92 ASSERT (!signbit (mantissa));
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 { /* Negative zero. */
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 double mantissa;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 x = -0.0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 ASSERT (exp == 0);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 ASSERT (mantissa == x);
8654
a2bc90a7b7aa Test also the sign bit of zero results.
Bruno Haible <bruno@clisp.org>
parents: 8545
diff changeset
102 ASSERT (signbit (mantissa));
8492
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 for (i = 1, x = 1.0; i <= DBL_MAX_EXP; i++, x *= 2.0)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 ASSERT (mantissa == 0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 ASSERT (mantissa == 0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 for (; i >= DBL_MIN_EXP - 100 && x > 0.0; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 ASSERT (mantissa == 0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 for (i = 1, x = -1.0; i <= DBL_MAX_EXP; i++, x *= 2.0)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 ASSERT (mantissa == -0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 for (i = 1, x = -1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 ASSERT (mantissa == -0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 for (; i >= DBL_MIN_EXP - 100 && x < 0.0; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 ASSERT (mantissa == -0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 for (i = 1, x = 1.01; i <= DBL_MAX_EXP; i++, x *= 2.0)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (mantissa == 0.505);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 for (i = 1, x = 1.01; i >= DBL_MIN_EXP; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 ASSERT (mantissa == 0.505);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 for (; i >= DBL_MIN_EXP - 100 && x > 0.0; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 ASSERT (mantissa >= 0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 ASSERT (mantissa < 1.0);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 ASSERT (mantissa == my_ldexp (x, - exp));
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 for (i = 1, x = 1.73205; i <= DBL_MAX_EXP; i++, x *= 2.0)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (mantissa == 0.866025);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 for (i = 1, x = 1.73205; i >= DBL_MIN_EXP; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 ASSERT (exp == i);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 ASSERT (mantissa == 0.866025);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 for (; i >= DBL_MIN_EXP - 100 && x > 0.0; i--, x *= 0.5)
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 {
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 int exp = -9999;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 double mantissa = frexp (x, &exp);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 ASSERT (exp == i || exp == i + 1);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 ASSERT (mantissa >= 0.5);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 ASSERT (mantissa < 1.0);
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 ASSERT (mantissa == my_ldexp (x, - exp));
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 }
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 return 0;
1dcdd2ec146b Tests for module 'frexp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 }