1 /* Test of splitting a 'long double' into fraction and mantissa.
2 Copyright (C) 2007 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 2, or (at your option)
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, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
28 #include "isnanl-nolibm.h"
30 #define ASSERT(expr) if (!(expr)) abort ();
33 my_ldexp (long double x, int d)
47 DECL_LONG_DOUBLE_ROUNDING
49 BEGIN_LONG_DOUBLE_ROUNDING ();
55 mantissa = frexpl (x, &exp);
56 ASSERT (isnanl (mantissa));
59 { /* Positive infinity. */
63 mantissa = frexpl (x, &exp);
64 ASSERT (mantissa == x);
67 { /* Negative infinity. */
71 mantissa = frexpl (x, &exp);
72 ASSERT (mantissa == x);
75 { /* Positive zero. */
79 mantissa = frexpl (x, &exp);
81 ASSERT (mantissa == x);
84 { /* Negative zero. */
88 mantissa = frexpl (x, &exp);
90 ASSERT (mantissa == x);
93 for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
96 long double mantissa = frexpl (x, &exp);
98 ASSERT (mantissa == 0.5L);
100 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
103 long double mantissa = frexpl (x, &exp);
105 ASSERT (mantissa == 0.5L);
107 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
110 long double mantissa = frexpl (x, &exp);
112 ASSERT (mantissa == 0.5L);
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 >= LDBL_MIN_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.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
140 long double mantissa = frexpl (x, &exp);
142 ASSERT (mantissa == 0.505L);
144 for (i = 1, x = 1.01L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
147 long double mantissa = frexpl (x, &exp);
149 ASSERT (mantissa == 0.505L);
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);
157 ASSERT (mantissa < 1.0L);
158 ASSERT (mantissa == my_ldexp (x, - exp));
161 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
164 long double mantissa = frexpl (x, &exp);
166 ASSERT (mantissa == 0.866025L);
168 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
171 long double mantissa = frexpl (x, &exp);
173 ASSERT (mantissa == 0.866025L);
175 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
178 long double mantissa = frexpl (x, &exp);
179 ASSERT (exp == i || exp == i + 1);
180 ASSERT (mantissa >= 0.5L);
181 ASSERT (mantissa < 1.0L);
182 ASSERT (mantissa == my_ldexp (x, - exp));