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"
35 /* Avoid some warnings from "gcc -Wshadow".
36 This file doesn't use the exp() function. */
40 /* On MIPS IRIX machines, LDBL_MIN_EXP is -1021, but the smallest reliable
41 exponent for 'long double' is -964. Similarly, on PowerPC machines,
42 LDBL_MIN_EXP is -1021, but the smallest reliable exponent for 'long double'
43 is -968. For exponents below that, the precision may be truncated to the
44 precision used for 'double'. */
46 # define MIN_NORMAL_EXP (LDBL_MIN_EXP + 57)
47 #elif defined __ppc || defined __ppc__ || defined __powerpc || defined __powerpc__
48 # define MIN_NORMAL_EXP (LDBL_MIN_EXP + 53)
50 # define MIN_NORMAL_EXP LDBL_MIN_EXP
54 my_ldexp (long double x, int d)
68 DECL_LONG_DOUBLE_ROUNDING
70 BEGIN_LONG_DOUBLE_ROUNDING ();
76 mantissa = frexpl (x, &exp);
77 ASSERT (isnanl (mantissa));
80 { /* Positive infinity. */
84 mantissa = frexpl (x, &exp);
85 ASSERT (mantissa == x);
88 { /* Negative infinity. */
92 mantissa = frexpl (x, &exp);
93 ASSERT (mantissa == x);
96 { /* Positive zero. */
100 mantissa = frexpl (x, &exp);
102 ASSERT (mantissa == x);
103 ASSERT (!signbit (mantissa));
106 { /* Negative zero. */
108 long double mantissa;
110 mantissa = frexpl (x, &exp);
112 ASSERT (mantissa == x);
113 ASSERT (signbit (mantissa));
116 for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
119 long double mantissa = frexpl (x, &exp);
121 ASSERT (mantissa == 0.5L);
123 for (i = 1, x = 1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
126 long double mantissa = frexpl (x, &exp);
128 ASSERT (mantissa == 0.5L);
130 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
133 long double mantissa = frexpl (x, &exp);
135 ASSERT (mantissa == 0.5L);
138 for (i = 1, x = -1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
141 long double mantissa = frexpl (x, &exp);
143 ASSERT (mantissa == -0.5L);
145 for (i = 1, x = -1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
148 long double mantissa = frexpl (x, &exp);
150 ASSERT (mantissa == -0.5L);
152 for (; i >= LDBL_MIN_EXP - 100 && x < 0.0L; i--, x *= 0.5L)
155 long double mantissa = frexpl (x, &exp);
157 ASSERT (mantissa == -0.5L);
160 for (i = 1, x = 1.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
163 long double mantissa = frexpl (x, &exp);
165 ASSERT (mantissa == 0.505L);
167 for (i = 1, x = 1.01L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
170 long double mantissa = frexpl (x, &exp);
172 ASSERT (mantissa == 0.505L);
174 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
177 long double mantissa = frexpl (x, &exp);
179 ASSERT (mantissa >= 0.5L);
180 ASSERT (mantissa < 1.0L);
181 ASSERT (mantissa == my_ldexp (x, - exp));
184 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
187 long double mantissa = frexpl (x, &exp);
189 ASSERT (mantissa == 0.866025L);
191 for (i = 1, x = 1.73205L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
194 long double mantissa = frexpl (x, &exp);
196 ASSERT (mantissa == 0.866025L);
198 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
201 long double mantissa = frexpl (x, &exp);
202 ASSERT (exp == i || exp == i + 1);
203 ASSERT (mantissa >= 0.5L);
204 ASSERT (mantissa < 1.0L);
205 ASSERT (mantissa == my_ldexp (x, - exp));