pthread: Determine $(LIB_PTHREAD) correctly on IRIX 6.5.
[gnulib.git] / tests / test-ldexpl.c
1 /* Test of multiplying a 'long double' by a power of 2.
2    Copyright (C) 2007-2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
18
19 #include <config.h>
20
21 #include <math.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (ldexpl, long double, (long double, int));
25
26 #include <float.h>
27
28 #include "fpucw.h"
29 #include "isnanl-nolibm.h"
30 #include "minus-zero.h"
31 #include "nan.h"
32 #include "macros.h"
33
34 int
35 main ()
36 {
37   int i;
38   long double x;
39   long double y;
40   DECL_LONG_DOUBLE_ROUNDING
41
42   BEGIN_LONG_DOUBLE_ROUNDING ();
43
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));
49   }
50
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);
56   }
57
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);
63   }
64
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));
70   }
71
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));
77   }
78
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);
84   }
85
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);
91   }
92
93   for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
94     {
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);
98     }
99   for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
100     {
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)
104         {
105           y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
106         }
107     }
108   for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
109     {
110       y = ldexpl (x, 0); ASSERT (y == x);
111       y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
112     }
113
114   return 0;
115 }