1 /* Test of multiplying a 'long double' by a power of 2.
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__); \
48 DECL_LONG_DOUBLE_ROUNDING
50 BEGIN_LONG_DOUBLE_ROUNDING ();
54 y = ldexpl (x, 0); ASSERT (isnanl (y));
55 y = ldexpl (x, 5); ASSERT (isnanl (y));
56 y = ldexpl (x, -5); ASSERT (isnanl (y));
59 { /* Positive infinity. */
61 y = ldexpl (x, 0); ASSERT (y == x);
62 y = ldexpl (x, 5); ASSERT (y == x);
63 y = ldexpl (x, -5); ASSERT (y == x);
66 { /* Negative infinity. */
68 y = ldexpl (x, 0); ASSERT (y == x);
69 y = ldexpl (x, 5); ASSERT (y == x);
70 y = ldexpl (x, -5); ASSERT (y == x);
73 { /* Positive zero. */
75 y = ldexpl (x, 0); ASSERT (y == x); ASSERT (!signbit (x));
76 y = ldexpl (x, 5); ASSERT (y == x); ASSERT (!signbit (x));
77 y = ldexpl (x, -5); ASSERT (y == x); ASSERT (!signbit (x));
80 { /* Negative zero. */
82 y = ldexpl (x, 0); ASSERT (y == x); ASSERT (signbit (x));
83 y = ldexpl (x, 5); ASSERT (y == x); ASSERT (signbit (x));
84 y = ldexpl (x, -5); ASSERT (y == x); ASSERT (signbit (x));
87 { /* Positive finite number. */
89 y = ldexpl (x, 0); ASSERT (y == x);
90 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
91 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
94 { /* Negative finite number. */
95 x = -20.085536923187667742L;
96 y = ldexpl (x, 0); ASSERT (y == x);
97 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
98 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
101 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
103 y = ldexpl (x, 0); ASSERT (y == x);
104 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
105 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
107 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
109 y = ldexpl (x, 0); ASSERT (y == x);
110 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
111 if (i - 5 >= LDBL_MIN_EXP)
113 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
116 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
118 y = ldexpl (x, 0); ASSERT (y == x);
119 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);