1
/* Test of ldexp*() function family.
2
Copyright (C) 2007-2012 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, 2010. */
26
/* A particular value. */
30
ASSERT (y >= L_(0.5999999999) && y <= L_(0.6000000001));
35
ASSERT (y >= L_(1.199999999) && y <= L_(1.200000001));
40
ASSERT (y >= L_(0.2999999999) && y <= L_(0.3000000001));
45
y = LDEXP (x, 0); ASSERT (ISNAN (y));
46
y = LDEXP (x, 5); ASSERT (ISNAN (y));
47
y = LDEXP (x, -5); ASSERT (ISNAN (y));
50
{ /* Positive infinity. */
52
y = LDEXP (x, 0); ASSERT (y == x);
53
y = LDEXP (x, 5); ASSERT (y == x);
54
y = LDEXP (x, -5); ASSERT (y == x);
57
{ /* Negative infinity. */
59
y = LDEXP (x, 0); ASSERT (y == x);
60
y = LDEXP (x, 5); ASSERT (y == x);
61
y = LDEXP (x, -5); ASSERT (y == x);
64
{ /* Positive zero. */
66
y = LDEXP (x, 0); ASSERT (y == x); ASSERT (!signbit (x));
67
y = LDEXP (x, 5); ASSERT (y == x); ASSERT (!signbit (x));
68
y = LDEXP (x, -5); ASSERT (y == x); ASSERT (!signbit (x));
71
{ /* Negative zero. */
73
y = LDEXP (x, 0); ASSERT (y == x); ASSERT (signbit (x));
74
y = LDEXP (x, 5); ASSERT (y == x); ASSERT (signbit (x));
75
y = LDEXP (x, -5); ASSERT (y == x); ASSERT (signbit (x));
78
{ /* Positive finite number. */
80
y = LDEXP (x, 0); ASSERT (y == x);
81
y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
82
y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
85
{ /* Negative finite number. */
86
x = - L_(20.085536923187667742);
87
y = LDEXP (x, 0); ASSERT (y == x);
88
y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
89
y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
92
for (i = 1, x = L_(1.73205); i <= MAX_EXP; i++, x *= L_(2.0))
94
y = LDEXP (x, 0); ASSERT (y == x);
96
volatile DOUBLE expected;
98
expected = x * L_(32.0);
99
ASSERT (y == expected);
101
y = LDEXP (x, -5); ASSERT (y == x * 0.03125L);
103
for (i = 1, x = L_(1.73205); i >= MIN_EXP; i--, x *= L_(0.5))
105
y = LDEXP (x, 0); ASSERT (y == x);
106
y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
107
if (i - 5 >= MIN_EXP)
109
y = LDEXP (x, -5); ASSERT (y == x * L_(0.03125));
112
for (; i >= LDBL_MIN_EXP - 100 && x > L_(0.0); i--, x *= L_(0.5))
114
y = LDEXP (x, 0); ASSERT (y == x);
115
y = LDEXP (x, 5); ASSERT (y == x * L_(32.0));
118
/* Randomized tests. */
119
for (i = 0; i < SIZEOF (RANDOM); i++)
123
x = L_(20.0) * RANDOM[i] - L_(10.0); /* -10.0 <= x <= 10.0 */
124
/* LDEXP only does rounding when it returns a denormalized number
125
or there is underflow. It doesn't happen here. */
126
for (u = -10; u <= 10; u++)
127
for (v = -10; v <= 10; v++)
128
ASSERT (LDEXP (x, u + v) == LDEXP (LDEXP (x, u), v));