1 /* Test of ilogb*() function family.
2 Copyright (C) 2012-2017 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/>. */
18 my_ldexp (DOUBLE x
, int d
)
34 /* Some particular values. */
53 ASSERT (y
== (FLT_RADIX
== 2 ? 2 : 1));
57 ASSERT (y
== (FLT_RADIX
== 2 ? -2 : -1));
60 ASSERT (ILOGB (L_(0.0)) == FP_ILOGB0
);
61 ASSERT (ILOGB (MINUS_ZERO
) == FP_ILOGB0
);
64 ASSERT (ILOGB (INFINITY
) == INT_MAX
);
65 ASSERT (ILOGB (- INFINITY
) == INT_MAX
);
68 ASSERT (ILOGB (NAN
) == FP_ILOGBNAN
);
70 /* From here on, this test assumes FLT_RADIX == 2. */
72 for (i
= 1, x
= L_(1.0); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
77 for (i
= 1, x
= L_(1.0); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
82 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
88 for (i
= 1, x
= - L_(1.0); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
93 for (i
= 1, x
= - L_(1.0); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
98 for (; i
>= MIN_EXP
- 100 && x
< L_(0.0); i
--, x
*= L_(0.5))
104 for (i
= 1, x
= L_(1.01); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
109 for (i
= 1, x
= L_(1.01); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
114 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
120 for (i
= 1, x
= L_(1.73205); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
125 for (i
= 1, x
= L_(1.73205); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
130 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
133 ASSERT (y
== i
- 1 || y
== i
);
136 /* Randomized tests. */
137 for (i
= 0; i
< SIZEOF (RANDOM
); i
++)
139 x
= L_(20.0) * RANDOM
[i
] - L_(10.0); /* -10.0 <= x <= 10.0 */
142 DOUBLE abs_x
= (x
< L_(0.0) ? - x
: x
);
144 ASSERT (abs_x
>= my_ldexp (L_(1.0), y
));
145 ASSERT (abs_x
< my_ldexp (L_(1.0), y
+ 1));