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. */
29
#include "isnanl-nolibm.h"
31
#define ASSERT(expr) \
36
fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
42
/* On MIPS IRIX machines, LDBL_MIN_EXP is -1021, but the smallest reliable
43
exponent for 'long double' is -964. Similarly, on PowerPC machines,
44
LDBL_MIN_EXP is -1021, but the smallest reliable exponent for 'long double'
45
is -968. For exponents below that, the precision may be truncated to the
46
precision used for 'double'. */
48
# define MIN_NORMAL_EXP (LDBL_MIN_EXP + 57)
49
#elif defined __ppc || defined __ppc__ || defined __powerpc || defined __powerpc__
50
# define MIN_NORMAL_EXP (LDBL_MIN_EXP + 53)
52
# define MIN_NORMAL_EXP LDBL_MIN_EXP
56
my_ldexp (long double x, int d)
70
DECL_LONG_DOUBLE_ROUNDING
72
BEGIN_LONG_DOUBLE_ROUNDING ();
78
mantissa = frexpl (x, &exp);
79
ASSERT (isnanl (mantissa));
82
{ /* Positive infinity. */
86
mantissa = frexpl (x, &exp);
87
ASSERT (mantissa == x);
90
{ /* Negative infinity. */
94
mantissa = frexpl (x, &exp);
95
ASSERT (mantissa == x);
98
{ /* Positive zero. */
100
long double mantissa;
102
mantissa = frexpl (x, &exp);
104
ASSERT (mantissa == x);
105
ASSERT (!signbit (mantissa));
108
{ /* Negative zero. */
110
long double mantissa;
112
mantissa = frexpl (x, &exp);
114
ASSERT (mantissa == x);
115
ASSERT (signbit (mantissa));
118
for (i = 1, x = 1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
121
long double mantissa = frexpl (x, &exp);
123
ASSERT (mantissa == 0.5L);
125
for (i = 1, x = 1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
128
long double mantissa = frexpl (x, &exp);
130
ASSERT (mantissa == 0.5L);
132
for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
135
long double mantissa = frexpl (x, &exp);
137
ASSERT (mantissa == 0.5L);
140
for (i = 1, x = -1.0L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
143
long double mantissa = frexpl (x, &exp);
145
ASSERT (mantissa == -0.5L);
147
for (i = 1, x = -1.0L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
150
long double mantissa = frexpl (x, &exp);
152
ASSERT (mantissa == -0.5L);
154
for (; i >= LDBL_MIN_EXP - 100 && x < 0.0L; i--, x *= 0.5L)
157
long double mantissa = frexpl (x, &exp);
159
ASSERT (mantissa == -0.5L);
162
for (i = 1, x = 1.01L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
165
long double mantissa = frexpl (x, &exp);
167
ASSERT (mantissa == 0.505L);
169
for (i = 1, x = 1.01L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
172
long double mantissa = frexpl (x, &exp);
174
ASSERT (mantissa == 0.505L);
176
for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
179
long double mantissa = frexpl (x, &exp);
181
ASSERT (mantissa >= 0.5L);
182
ASSERT (mantissa < 1.0L);
183
ASSERT (mantissa == my_ldexp (x, - exp));
186
for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
189
long double mantissa = frexpl (x, &exp);
191
ASSERT (mantissa == 0.866025L);
193
for (i = 1, x = 1.73205L; i >= MIN_NORMAL_EXP; i--, x *= 0.5L)
196
long double mantissa = frexpl (x, &exp);
198
ASSERT (mantissa == 0.866025L);
200
for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
203
long double mantissa = frexpl (x, &exp);
204
ASSERT (exp == i || exp == i + 1);
205
ASSERT (mantissa >= 0.5L);
206
ASSERT (mantissa < 1.0L);
207
ASSERT (mantissa == my_ldexp (x, - exp));