ignore-value: remove dependency on stdint
[gnulib.git] / tests / test-ldexpl.c
blobd8e7e15ebdd4b0f12a121362e1fe6edf380c55f8
1 /* Test of multiplying a 'long double' by a power of 2.
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. */
19 #include <config.h>
21 #include <math.h>
23 #include "signature.h"
24 SIGNATURE_CHECK (ldexpl, long double, (long double, int));
26 #include <float.h>
28 #include "fpucw.h"
29 #include "isnanl-nolibm.h"
30 #include "minus-zero.h"
31 #include "nan.h"
32 #include "macros.h"
34 int
35 main ()
37 int i;
38 long double x;
39 long double y;
40 DECL_LONG_DOUBLE_ROUNDING
42 BEGIN_LONG_DOUBLE_ROUNDING ();
44 { /* NaN. */
45 x = NaNl ();
46 y = ldexpl (x, 0); ASSERT (isnanl (y));
47 y = ldexpl (x, 5); ASSERT (isnanl (y));
48 y = ldexpl (x, -5); ASSERT (isnanl (y));
51 { /* Positive infinity. */
52 x = 1.0L / 0.0L;
53 y = ldexpl (x, 0); ASSERT (y == x);
54 y = ldexpl (x, 5); ASSERT (y == x);
55 y = ldexpl (x, -5); ASSERT (y == x);
58 { /* Negative infinity. */
59 x = -1.0L / 0.0L;
60 y = ldexpl (x, 0); ASSERT (y == x);
61 y = ldexpl (x, 5); ASSERT (y == x);
62 y = ldexpl (x, -5); ASSERT (y == x);
65 { /* Positive zero. */
66 x = 0.0L;
67 y = ldexpl (x, 0); ASSERT (y == x); ASSERT (!signbit (x));
68 y = ldexpl (x, 5); ASSERT (y == x); ASSERT (!signbit (x));
69 y = ldexpl (x, -5); ASSERT (y == x); ASSERT (!signbit (x));
72 { /* Negative zero. */
73 x = minus_zerol;
74 y = ldexpl (x, 0); ASSERT (y == x); ASSERT (signbit (x));
75 y = ldexpl (x, 5); ASSERT (y == x); ASSERT (signbit (x));
76 y = ldexpl (x, -5); ASSERT (y == x); ASSERT (signbit (x));
79 { /* Positive finite number. */
80 x = 1.73205L;
81 y = ldexpl (x, 0); ASSERT (y == x);
82 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
83 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
86 { /* Negative finite number. */
87 x = -20.085536923187667742L;
88 y = ldexpl (x, 0); ASSERT (y == x);
89 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
90 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
93 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
95 y = ldexpl (x, 0); ASSERT (y == x);
96 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
97 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
99 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
101 y = ldexpl (x, 0); ASSERT (y == x);
102 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
103 if (i - 5 >= LDBL_MIN_EXP)
105 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
108 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
110 y = ldexpl (x, 0); ASSERT (y == x);
111 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
114 return 0;