1 /* Test of splitting a 'long double' into fraction and mantissa.
2 Copyright (C) 2007-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
23 #include "signature.h"
24 SIGNATURE_CHECK (frexpl, long double, (long double, int *));
29 #include "isnanl-nolibm.h"
30 #include "minus-zero.h"
34 /* Avoid some warnings from "gcc -Wshadow".
35 This file doesn't use the exp() function. */
39 /* On MIPS IRIX machines, LDBL_MIN_EXP is -1021, but the smallest reliable
40 exponent for 'long double' is -964. Similarly, on PowerPC machines,
41 LDBL_MIN_EXP is -1021, but the smallest reliable exponent for 'long double'
42 is -968. For exponents below that, the precision may be truncated to the
43 precision used for 'double'. */
45 # define MIN_NORMAL_EXP (LDBL_MIN_EXP + 57)
46 #elif defined __ppc || defined __ppc__ || defined __powerpc || defined __powerpc__
47 # define MIN_NORMAL_EXP (LDBL_MIN_EXP + 53)
49 # define MIN_NORMAL_EXP LDBL_MIN_EXP
53 my_ldexp (long double x, int d)
67 DECL_LONG_DOUBLE_ROUNDING
69 BEGIN_LONG_DOUBLE_ROUNDING ();
75 mantissa = frexpl (x, &exp);
76 ASSERT (isnanl (mantissa));
79 { /* Positive infinity. */
83 mantissa = frexpl (x, &exp);
84 ASSERT (mantissa == x);
87 { /* Negative infinity. */
91 mantissa = frexpl (x, &exp);
92 ASSERT (mantissa == x);
95 { /* Positive zero. */
99 mantissa = frexpl (x, &exp);
101 ASSERT (mantissa == x);
102 ASSERT (!signbit (mantissa));
105 { /* Negative zero. */
107 long double mantissa;
109 mantissa = frexpl (x, &exp);
111 ASSERT (mantissa == x);
112 ASSERT (signbit (mantissa));
115 for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
118 long double mantissa = frexpl (x, &exp);
120 ASSERT (mantissa == 0.5L);
122 for (i = 1, x = 1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
125 long double mantissa = frexpl (x, &exp);
127 ASSERT (mantissa == 0.5L);
129 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
132 long double mantissa = frexpl (x, &exp);
134 ASSERT (mantissa == 0.5L);
137 for (i = 1, x = -1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
140 long double mantissa = frexpl (x, &exp);
142 ASSERT (mantissa == -0.5L);
144 for (i = 1, x = -1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
147 long double mantissa = frexpl (x, &exp);
149 ASSERT (mantissa == -0.5L);
151 for (; i >= LDBL_MIN_EXP - 100 && x < 0.0L; i--, x *= 0.5L)
154 long double mantissa = frexpl (x, &exp);
156 ASSERT (mantissa == -0.5L);
159 for (i = 1, x = 1.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
162 long double mantissa = frexpl (x, &exp);
164 ASSERT (mantissa == 0.505L);
166 for (i = 1, x = 1.01L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
169 long double mantissa = frexpl (x, &exp);
171 ASSERT (mantissa == 0.505L);
173 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
176 long double mantissa = frexpl (x, &exp);
178 ASSERT (mantissa >= 0.5L);
179 ASSERT (mantissa < 1.0L);
180 ASSERT (mantissa == my_ldexp (x, - exp));
183 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
186 long double mantissa = frexpl (x, &exp);
188 ASSERT (mantissa == 0.866025L);
190 for (i = 1, x = 1.73205L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
193 long double mantissa = frexpl (x, &exp);
195 ASSERT (mantissa == 0.866025L);
197 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
200 long double mantissa = frexpl (x, &exp);
201 ASSERT (exp == i || exp == i + 1);
202 ASSERT (mantissa >= 0.5L);
203 ASSERT (mantissa < 1.0L);
204 ASSERT (mantissa == my_ldexp (x, - exp));