1 /* Test of logb*() function family.
2 Copyright (C) 2012-2018 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 <https://www.gnu.org/licenses/>. */
18 my_ldexp (DOUBLE x
, int d
)
34 /* Some particular values. */
37 ASSERT (y
== - L_(1.0));
41 ASSERT (y
== L_(0.0));
45 ASSERT (y
== L_(1.0));
49 ASSERT (y
== L_(1.0));
53 ASSERT (y
== (FLT_RADIX
== 2 ? L_(2.0) : L_(1.0)));
57 ASSERT (y
== (FLT_RADIX
== 2 ? - L_(2.0) : - L_(1.0)));
60 ASSERT (LOGB (L_(0.0)) == - HUGEVAL
);
61 ASSERT (LOGB (MINUS_ZERO
) == - HUGEVAL
);
63 /* From here on, this test assumes FLT_RADIX == 2. */
65 for (i
= 1, x
= L_(1.0); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
68 ASSERT (y
== (DOUBLE
)(i
- 1));
70 for (i
= 1, x
= L_(1.0); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
73 ASSERT (y
== (DOUBLE
)(i
- 1));
75 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
78 ASSERT (y
== (DOUBLE
)(i
- 1));
81 for (i
= 1, x
= - L_(1.0); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
84 ASSERT (y
== (DOUBLE
)(i
- 1));
86 for (i
= 1, x
= - L_(1.0); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
89 ASSERT (y
== (DOUBLE
)(i
- 1));
91 for (; i
>= MIN_EXP
- 100 && x
< L_(0.0); i
--, x
*= L_(0.5))
94 ASSERT (y
== (DOUBLE
)(i
- 1));
97 for (i
= 1, x
= L_(1.01); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
100 ASSERT (y
== (DOUBLE
)(i
- 1));
102 for (i
= 1, x
= L_(1.01); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
105 ASSERT (y
== (DOUBLE
)(i
- 1));
107 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
110 ASSERT (y
== (DOUBLE
)(i
- 1));
113 for (i
= 1, x
= L_(1.73205); i
<= MAX_EXP
; i
++, x
*= L_(2.0))
116 ASSERT (y
== (DOUBLE
)(i
- 1));
118 for (i
= 1, x
= L_(1.73205); i
>= MIN_NORMAL_EXP
; i
--, x
*= L_(0.5))
121 ASSERT (y
== (DOUBLE
)(i
- 1));
123 for (; i
>= MIN_EXP
- 100 && x
> L_(0.0); i
--, x
*= L_(0.5))
126 ASSERT (y
== (DOUBLE
)(i
- 1) || y
== (DOUBLE
)i
);
129 /* Randomized tests. */
130 for (i
= 0; i
< SIZEOF (RANDOM
); i
++)
132 x
= L_(20.0) * RANDOM
[i
] - L_(10.0); /* -10.0 <= x <= 10.0 */
135 DOUBLE abs_x
= (x
< L_(0.0) ? - x
: x
);
137 ASSERT (y
== (DOUBLE
) (int) y
);
138 ASSERT (abs_x
>= my_ldexp (L_(1.0), (int) y
));
139 ASSERT (abs_x
< my_ldexp (L_(1.0), (int) y
+ 1));