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. */
27 #define ASSERT(expr) if (!(expr)) abort ();
30 my_ldexp (long double x, int d)
49 mantissa = frexpl (x, &exp);
50 ASSERT (mantissa != mantissa);
53 { /* Positive infinity. */
57 mantissa = frexpl (x, &exp);
58 ASSERT (mantissa == x);
61 { /* Negative infinity. */
65 mantissa = frexpl (x, &exp);
66 ASSERT (mantissa == x);
69 { /* Positive zero. */
73 mantissa = frexpl (x, &exp);
75 ASSERT (mantissa == x);
78 { /* Negative zero. */
82 mantissa = frexpl (x, &exp);
84 ASSERT (mantissa == x);
87 for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
90 long double mantissa = frexpl (x, &exp);
92 ASSERT (mantissa == 0.5L);
94 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
97 long double mantissa = frexpl (x, &exp);
99 ASSERT (mantissa == 0.5L);
101 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
104 long double mantissa = frexpl (x, &exp);
106 ASSERT (mantissa == 0.5L);
109 for (i = 1, x = -1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
112 long double mantissa = frexpl (x, &exp);
114 ASSERT (mantissa == -0.5L);
116 for (i = 1, x = -1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
119 long double mantissa = frexpl (x, &exp);
121 ASSERT (mantissa == -0.5L);
123 for (; i >= LDBL_MIN_EXP - 100 && x < 0.0L; i--, x *= 0.5L)
126 long double mantissa = frexpl (x, &exp);
128 ASSERT (mantissa == -0.5L);
131 for (i = 1, x = 1.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
134 long double mantissa = frexpl (x, &exp);
136 ASSERT (mantissa == 0.505L);
138 for (i = 1, x = 1.01L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
141 long double mantissa = frexpl (x, &exp);
143 ASSERT (mantissa == 0.505L);
145 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
148 long double mantissa = frexpl (x, &exp);
150 ASSERT (mantissa >= 0.5L);
151 ASSERT (mantissa < 1.0L);
152 ASSERT (mantissa == my_ldexp (x, - exp));
155 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
158 long double mantissa = frexpl (x, &exp);
160 ASSERT (mantissa == 0.866025L);
162 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
165 long double mantissa = frexpl (x, &exp);
167 ASSERT (mantissa == 0.866025L);
169 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
172 long double mantissa = frexpl (x, &exp);
173 ASSERT (exp == i || exp == i + 1);
174 ASSERT (mantissa >= 0.5L);
175 ASSERT (mantissa < 1.0L);
176 ASSERT (mantissa == my_ldexp (x, - exp));