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