Add malloc predictor (PR middle-end/83023).
[official-gcc.git] / gcc / testsuite / gcc.dg / nextafter-1.c
blob502e0f49b1ee5e2a9a9cd8c58b643c4ae5f3842d
1 /* PR libstdc++/85466 */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -fno-math-errno -fno-trapping-math -fdump-tree-optimized" } */
4 /* { dg-add-options ieee } */
5 /* { dg-final { scan-tree-dump-not "nextafter" "optimized" } } */
6 /* { dg-final { scan-tree-dump-not "nexttoward" "optimized" } } */
8 float nextafterf (float, float);
9 double nextafter (double, double);
10 long double nextafterl (long double, long double);
11 float nexttowardf (float, long double);
12 double nexttoward (double, long double);
13 long double nexttowardl (long double, long double);
15 #define CHECK(x) if (!(x)) __builtin_abort ()
17 #ifndef NEED_ERRNO
18 #define NEED_ERRNO 0
19 #endif
20 #ifndef NEED_EXC
21 #define NEED_EXC 0
22 #endif
23 #ifndef NO_LONG_DOUBLE
24 #define NO_LONG_DOUBLE (__LDBL_MANT_DIG__ == 106)
25 #endif
27 #define TEST(name, fn, type, L1, L2, l1, l2, MIN1, \
28 MAX1, DENORM_MIN1, EPSILON1, MIN2, MAX2, DENORM_MIN2) \
29 void \
30 name (void) \
31 { \
32 const type a = fn (0.0##L1, 0.0##L2); \
33 CHECK (a == 0.0##L1 && !__builtin_signbit (a)); \
34 const type b = fn (0.0##L1, -0.0##L2); \
35 CHECK (b == 0.0##L1 && __builtin_signbit (b)); \
36 const type c = fn (__builtin_nan##l1 (""), 0.0##L2); \
37 CHECK (__builtin_isnan##l1 (c)); \
38 const type d = fn (2.0##L1, __builtin_nan##l2 ("")); \
39 CHECK (__builtin_isnan##l1 (d)); \
40 const type e = NEED_EXC ? DENORM_MIN1 : fn (0.0##L1, 8.0##L2); \
41 CHECK (e == DENORM_MIN1); \
42 const type f = fn (1.0##L1, 8.0##L2); \
43 CHECK (f == 1.0##L1 + EPSILON1); \
44 const type g = fn (1.0##L1, -8.0##L2); \
45 CHECK (g == 1.0##L1 - EPSILON1 / 2.0##L1); \
46 const type h = fn (__builtin_inf (), 0.0##L2); \
47 CHECK (h == MAX1); \
48 const type i = fn (-1.0##L1, -__builtin_inf ()); \
49 CHECK (i == -1.0##L1 - EPSILON1); \
50 const type j = fn (1.5##L1, __builtin_inf ()); \
51 CHECK (j == 1.5##L1 + EPSILON1); \
52 const type k = fn (1.5##L1 - EPSILON1, 100.0##L2); \
53 CHECK (k == 1.5##L1); \
54 const type l \
55 = (NEED_EXC || NEED_ERRNO) ? 0.0##L1 : fn (DENORM_MIN1, 0.0##L2); \
56 CHECK (l == 0.0##L1 && !__builtin_signbit (l)); \
57 const type m \
58 = (NEED_EXC || NEED_ERRNO) ? __builtin_inf##l1 () \
59 : fn (MAX1, __builtin_inf ()); \
60 CHECK (__builtin_isinf##l1 (m) && !__builtin_signbit (m)); \
61 const type n \
62 = (NEED_EXC || NEED_ERRNO) ? 2.0##L1 * DENORM_MIN1 \
63 : fn (DENORM_MIN1, 12.0##L2); \
64 CHECK (n == 2.0##L1 * DENORM_MIN1); \
65 const type o \
66 = (NEED_EXC || NEED_ERRNO) ? 3.0##L1 * DENORM_MIN1 \
67 : fn (n, 24.0##L2); \
68 CHECK (o == 3.0##L1 * DENORM_MIN1); \
69 const type p \
70 = (NEED_EXC || NEED_ERRNO) ? 4.0##L1 * DENORM_MIN1 \
71 : fn (o, 132.0##L2); \
72 CHECK (p == 4.0##L1 * DENORM_MIN1); \
73 const type q \
74 = (NEED_EXC || NEED_ERRNO) ? DENORM_MIN1 \
75 : fn (2.0##L1 * DENORM_MIN1, -__builtin_inf ()); \
76 CHECK (q == DENORM_MIN1); \
77 const type r \
78 = (NEED_EXC || NEED_ERRNO) ? 2.0##L1 * DENORM_MIN1 \
79 : fn (3.0##L1 * DENORM_MIN1, DENORM_MIN2); \
80 CHECK (r == 2.0##L1 * DENORM_MIN1); \
81 const type s \
82 = (NEED_EXC || NEED_ERRNO) ? 3.0##L1 * DENORM_MIN1 \
83 : fn (4.0##L1 * DENORM_MIN1, 2.0##L2 * DENORM_MIN2); \
84 CHECK (s == 3.0##L1 * DENORM_MIN1); \
85 const type t \
86 = (NEED_EXC || NEED_ERRNO) ? MIN1 - DENORM_MIN1 \
87 : fn (MIN1, 0.0##L2); \
88 CHECK (t == MIN1 - DENORM_MIN1); \
89 const type u \
90 = (NEED_EXC || NEED_ERRNO) ? MIN1 - 2.0##L1 * DENORM_MIN1 \
91 : fn (MIN1 - DENORM_MIN1, -MIN2); \
92 CHECK (u == MIN1 - 2.0##L1 * DENORM_MIN1); \
93 const type v \
94 = (NEED_EXC || NEED_ERRNO) ? MIN1 - DENORM_MIN1 \
95 : fn (MIN1 - 2.0##L1 * DENORM_MIN1, 100.0##L2); \
96 CHECK (v == MIN1 - DENORM_MIN1); \
97 const type w = fn (MIN1 - DENORM_MIN1, MAX2); \
98 CHECK (w == MIN1); \
99 const type x = fn (MIN1, 17.0##L2); \
100 CHECK (x == MIN1 + DENORM_MIN1); \
101 const type y = fn (MIN1 + DENORM_MIN1, __builtin_inf##l2 ()); \
102 CHECK (y == MIN1 + 2.0##L1 * DENORM_MIN1); \
103 const type z \
104 = (NEED_EXC || NEED_ERRNO) ? MIN1 / 2.0##L1 - DENORM_MIN1 \
105 : fn (MIN1 / 2.0##L1, -MIN2); \
106 CHECK (z == MIN1 / 2.0##L1 - DENORM_MIN1); \
107 const type aa \
108 = (NEED_EXC || NEED_ERRNO) ? -MIN1 / 4.0##L1 + DENORM_MIN1 \
109 : fn (-MIN1 / 4.0##L1, MIN2); \
110 CHECK (aa == -MIN1 / 4.0##L1 + DENORM_MIN1); \
111 const type ab = fn (MIN1 * 2.0##L1, -MIN2); \
112 CHECK (ab == MIN1 * 2.0##L1 - DENORM_MIN1); \
113 const type ac = fn (MIN1 * 4.0##L1, MIN2); \
114 CHECK (ac == MIN1 * 4.0##L1 - DENORM_MIN1 * 2.0##L1); \
115 const type ad = fn (MIN1 * 64.0##L1, MIN2); \
116 CHECK (ad == MIN1 * 64.0##L1 - DENORM_MIN1 * 32.0##L1); \
117 const type ae \
118 = (NEED_EXC || NEED_ERRNO) ? MIN1 / 2.0##L1 \
119 : fn (MIN1 / 2.0##L1 - DENORM_MIN1, 100.0##L2); \
120 CHECK (ae == MIN1 / 2.0##L1); \
121 const type af \
122 = (NEED_EXC || NEED_ERRNO) ? -MIN1 / 4.0##L1 \
123 : fn (-MIN1 / 4 + DENORM_MIN1, -100.0##L2); \
124 CHECK (af == -MIN1 / 4.0##L1); \
125 const type ag = fn (MIN1 * 2.0##L1 - DENORM_MIN1, 100.0##L2); \
126 CHECK (ag == MIN1 * 2.0##L1); \
127 const type ah = fn (MIN1 * 4.0##L1 - 2.0##L1 * DENORM_MIN1, 100.0##L2); \
128 CHECK (ah == MIN1 * 4.0##L1); \
129 const type ai = fn (MIN1 * 64.0##L1 - 32.0##L1 * DENORM_MIN1, 100.0##L2); \
130 CHECK (ai == MIN1 * 64.0##L1); \
131 const type aj = fn (MIN1 * 64.0##L1, 100.0##L2); \
132 CHECK (aj == MIN1 * 64.0##L1 + 64.0##L1 * DENORM_MIN1); \
133 const type ak = fn (MIN1 * 64.0##L1 + DENORM_MIN1 * 64.0##L1, 1024.0##L2); \
134 CHECK (ak == MIN1 * 64.0##L1 + 128.0##L1 * DENORM_MIN1); \
135 const type al = fn (128.0##L1, 128.0##L2); \
136 CHECK (al == 128.0##L1); \
137 const type am = fn (128.0##L1, 129.0##L2); \
138 CHECK (am == 128.0##L1 + 128.0##L1 * EPSILON1); \
139 const type an = fn (-128.0##L1 + -128.0##L1 * EPSILON1, -130.0##L2); \
140 CHECK (an == -128.0##L1 - 256.0##L1 * EPSILON1); \
141 const type ao = fn (128.0##L1 + 256.0##L1 * EPSILON1, 256.0##L2); \
142 CHECK (ao == 128.0##L1 + 384.0##L1 * EPSILON1); \
143 const type ap = fn (128.0##L1 + 384.0##L1 * EPSILON1, -0.0##L2); \
144 CHECK (ap == 128.0##L1 + 256.0##L1 * EPSILON1); \
145 const type aq = fn (128.0##L1 + 256.0##L1 * EPSILON1, 1.0##L2); \
146 CHECK (aq == 128.0##L1 + 128.0##L1 * EPSILON1); \
147 const type ar = fn (128.0##L1 + 128.0##L1 * EPSILON1, 0.0##L2); \
148 CHECK (ar == 128.0##L1); \
149 const type as = fn (128.0##L1, 0.0##L2); \
150 CHECK (as == 128.0##L1 - 64.0##L1 * EPSILON1); \
151 const type at = fn (128.0##L1 - 64.0##L1 * EPSILON1, 5.0##L2); \
152 CHECK (at == 128.0##L1 - 128.0##L1 * EPSILON1); \
155 TEST (test1, nextafterf, float, F, F, f, f, __FLT_MIN__, __FLT_MAX__,
156 __FLT_DENORM_MIN__, __FLT_EPSILON__, __FLT_MIN__, __FLT_MAX__,
157 __FLT_DENORM_MIN__)
158 TEST (test2, nextafter, double, , , , , __DBL_MIN__, __DBL_MAX__,
159 __DBL_DENORM_MIN__, __DBL_EPSILON__, __DBL_MIN__, __DBL_MAX__,
160 __DBL_DENORM_MIN__)
161 #if !NO_LONG_DOUBLE
162 TEST (test3, nextafterl, long double, L, L, l, l, __LDBL_MIN__, __LDBL_MAX__,
163 __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
164 __LDBL_DENORM_MIN__)
165 TEST (test4, nexttowardf, float, F, L, f, l, __FLT_MIN__, __FLT_MAX__,
166 __FLT_DENORM_MIN__, __FLT_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
167 __LDBL_DENORM_MIN__)
168 TEST (test5, nexttoward, double, , L, , l, __DBL_MIN__, __DBL_MAX__,
169 __DBL_DENORM_MIN__, __DBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
170 __LDBL_DENORM_MIN__)
171 TEST (test6, nexttowardl, long double, L, L, l, l, __LDBL_MIN__, __LDBL_MAX__,
172 __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
173 __LDBL_DENORM_MIN__)
174 #endif
177 main ()
179 test1 ();
180 test2 ();
181 #if !NO_LONG_DOUBLE
182 test3 ();
183 test4 ();
184 test5 ();
185 test6 ();
186 #endif
187 return 0;