1 /* Test of splitting a float 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 (frexpf, float, (float, int *));
28 #include "isnanf-nolibm.h"
29 #include "minus-zero.h"
34 /* Avoid some warnings from "gcc -Wshadow".
35 This file doesn't use the exp() function. */
40 my_ldexp (float x, int d)
59 mantissa = frexpf (x, &exp);
60 ASSERT (isnanf (mantissa));
63 { /* Positive infinity. */
67 mantissa = frexpf (x, &exp);
68 ASSERT (mantissa == x);
71 { /* Negative infinity. */
75 mantissa = frexpf (x, &exp);
76 ASSERT (mantissa == x);
79 { /* Positive zero. */
83 mantissa = frexpf (x, &exp);
85 ASSERT (mantissa == x);
86 ASSERT (!signbit (mantissa));
89 { /* Negative zero. */
93 mantissa = frexpf (x, &exp);
95 ASSERT (mantissa == x);
96 ASSERT (signbit (mantissa));
99 for (i = 1, x = 1.0f; i <= FLT_MAX_EXP; i++, x *= 2.0f)
102 float mantissa = frexpf (x, &exp);
104 ASSERT (mantissa == 0.5f);
106 for (i = 1, x = 1.0f; i >= FLT_MIN_EXP; i--, x *= 0.5f)
109 float mantissa = frexpf (x, &exp);
111 ASSERT (mantissa == 0.5f);
113 for (; i >= FLT_MIN_EXP - 100 && x > 0.0f; i--, x *= 0.5f)
116 float mantissa = frexpf (x, &exp);
118 ASSERT (mantissa == 0.5f);
121 for (i = 1, x = -1.0f; i <= FLT_MAX_EXP; i++, x *= 2.0f)
124 float mantissa = frexpf (x, &exp);
126 ASSERT (mantissa == -0.5f);
128 for (i = 1, x = -1.0f; i >= FLT_MIN_EXP; i--, x *= 0.5f)
131 float mantissa = frexpf (x, &exp);
133 ASSERT (mantissa == -0.5f);
135 for (; i >= FLT_MIN_EXP - 100 && x < 0.0f; i--, x *= 0.5f)
138 float mantissa = frexpf (x, &exp);
140 ASSERT (mantissa == -0.5f);
143 for (i = 1, x = 1.01f; i <= FLT_MAX_EXP; i++, x *= 2.0f)
146 float mantissa = frexpf (x, &exp);
148 ASSERT (mantissa == 0.505f);
150 for (i = 1, x = 1.01f; i >= FLT_MIN_EXP; i--, x *= 0.5f)
153 float mantissa = frexpf (x, &exp);
155 ASSERT (mantissa == 0.505f);
157 for (; i >= FLT_MIN_EXP - 100 && x > 0.0f; i--, x *= 0.5f)
160 float mantissa = frexpf (x, &exp);
162 ASSERT (mantissa >= 0.5f);
163 ASSERT (mantissa < 1.0f);
164 ASSERT (mantissa == my_ldexp (x, - exp));
167 for (i = 1, x = 1.73205f; i <= FLT_MAX_EXP; i++, x *= 2.0f)
170 float mantissa = frexpf (x, &exp);
172 ASSERT (mantissa == 0.866025f);
174 for (i = 1, x = 1.73205f; i >= FLT_MIN_EXP; i--, x *= 0.5f)
177 float mantissa = frexpf (x, &exp);
179 ASSERT (mantissa == 0.866025f);
181 for (; i >= FLT_MIN_EXP - 100 && x > 0.0f; i--, x *= 0.5f)
184 float mantissa = frexpf (x, &exp);
185 ASSERT (exp == i || exp == i + 1);
186 ASSERT (mantissa >= 0.5f);
187 ASSERT (mantissa < 1.0f);
188 ASSERT (mantissa == my_ldexp (x, - exp));