Tighten condition in vect/pr85586.c (PR 85654)
[official-gcc.git] / gcc / testsuite / gcc.dg / nextafter-1.c
blobc8647ede00be4e7fab100b41d294fb3a16d59d90
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
24 #define TEST(name, fn, type, L1, L2, l1, l2, MIN1, \
25 MAX1, DENORM_MIN1, EPSILON1, MIN2, MAX2, DENORM_MIN2) \
26 void \
27 name (void) \
28 { \
29 const type a = fn (0.0##L1, 0.0##L2); \
30 CHECK (a == 0.0##L1 && !__builtin_signbit (a)); \
31 const type b = fn (0.0##L1, -0.0##L2); \
32 CHECK (b == 0.0##L1 && __builtin_signbit (b)); \
33 const type c = fn (__builtin_nan##l1 (""), 0.0##L2); \
34 CHECK (__builtin_isnan##l1 (c)); \
35 const type d = fn (2.0##L1, __builtin_nan##l2 ("")); \
36 CHECK (__builtin_isnan##l1 (d)); \
37 const type e = NEED_EXC ? DENORM_MIN1 : fn (0.0##L1, 8.0##L2); \
38 CHECK (e == DENORM_MIN1); \
39 const type f = fn (1.0##L1, 8.0##L2); \
40 CHECK (f == 1.0##L1 + EPSILON1); \
41 const type g = fn (1.0##L1, -8.0##L2); \
42 CHECK (g == 1.0##L1 - EPSILON1 / 2.0##L1); \
43 const type h = fn (__builtin_inf (), 0.0##L2); \
44 CHECK (h == MAX1); \
45 const type i = fn (-1.0##L1, -__builtin_inf ()); \
46 CHECK (i == -1.0##L1 - EPSILON1); \
47 const type j = fn (1.5##L1, __builtin_inf ()); \
48 CHECK (j == 1.5##L1 + EPSILON1); \
49 const type k = fn (1.5##L1 - EPSILON1, 100.0##L2); \
50 CHECK (k == 1.5##L1); \
51 const type l \
52 = (NEED_EXC || NEED_ERRNO) ? 0.0##L1 : fn (DENORM_MIN1, 0.0##L2); \
53 CHECK (l == 0.0##L1 && !__builtin_signbit (l)); \
54 const type m \
55 = (NEED_EXC || NEED_ERRNO) ? __builtin_inf##l1 () \
56 : fn (MAX1, __builtin_inf ()); \
57 CHECK (__builtin_isinf##l1 (m) && !__builtin_signbit (m)); \
58 const type n = fn (DENORM_MIN1, 12.0##L2); \
59 CHECK (n == 2.0##L1 * DENORM_MIN1); \
60 const type o = fn (n, 24.0##L2); \
61 CHECK (o == 3.0##L1 * DENORM_MIN1); \
62 const type p = fn (o, 132.0##L2); \
63 CHECK (p == 4.0##L1 * DENORM_MIN1); \
64 const type q = fn (2.0##L1 * DENORM_MIN1, -__builtin_inf ()); \
65 CHECK (q == DENORM_MIN1); \
66 const type r = fn (3.0##L1 * DENORM_MIN1, DENORM_MIN2); \
67 CHECK (r == 2.0##L1 * DENORM_MIN1); \
68 const type s = fn (4.0##L1 * DENORM_MIN1, 2.0##L2 * DENORM_MIN2); \
69 CHECK (s == 3.0##L1 * DENORM_MIN1); \
70 const type t = fn (MIN1, 0.0##L2); \
71 CHECK (t == MIN1 - DENORM_MIN1); \
72 const type u = fn (MIN1 - DENORM_MIN1, -MIN2); \
73 CHECK (u == MIN1 - 2.0##L1 * DENORM_MIN1); \
74 const type v = fn (MIN1 - 2.0##L1 * DENORM_MIN1, 100.0##L2); \
75 CHECK (v == MIN1 - DENORM_MIN1); \
76 const type w = fn (MIN1 - DENORM_MIN1, MAX2); \
77 CHECK (w == MIN1); \
78 const type x = fn (MIN1, 17.0##L2); \
79 CHECK (x == MIN1 + DENORM_MIN1); \
80 const type y = fn (MIN1 + DENORM_MIN1, __builtin_inf##l2 ()); \
81 CHECK (y == MIN1 + 2.0##L1 * DENORM_MIN1); \
82 const type z = fn (MIN1 / 2.0##L1, -MIN2); \
83 CHECK (z == MIN1 / 2.0##L1 - DENORM_MIN1); \
84 const type aa = fn (-MIN1 / 4.0##L1, MIN2); \
85 CHECK (aa == -MIN1 / 4.0##L1 + DENORM_MIN1); \
86 const type ab = fn (MIN1 * 2.0##L1, -MIN2); \
87 CHECK (ab == MIN1 * 2.0##L1 - DENORM_MIN1); \
88 const type ac = fn (MIN1 * 4.0##L1, MIN2); \
89 CHECK (ac == MIN1 * 4.0##L1 - DENORM_MIN1 * 2.0##L1); \
90 const type ad = fn (MIN1 * 64.0##L1, MIN2); \
91 CHECK (ad == MIN1 * 64.0##L1 - DENORM_MIN1 * 32.0##L1); \
92 const type ae = fn (MIN1 / 2.0##L1 - DENORM_MIN1, 100.0##L2); \
93 CHECK (ae == MIN1 / 2.0##L1); \
94 const type af = fn (-MIN1 / 4 + DENORM_MIN1, -100.0##L2); \
95 CHECK (af == -MIN1 / 4.0##L1); \
96 const type ag = fn (MIN1 * 2.0##L1 - DENORM_MIN1, 100.0##L2); \
97 CHECK (ag == MIN1 * 2.0##L1); \
98 const type ah = fn (MIN1 * 4.0##L1 - 2.0##L1 * DENORM_MIN1, 100.0##L2); \
99 CHECK (ah == MIN1 * 4.0##L1); \
100 const type ai = fn (MIN1 * 64.0##L1 - 32.0##L1 * DENORM_MIN1, 100.0##L2); \
101 CHECK (ai == MIN1 * 64.0##L1); \
102 const type aj = fn (MIN1 * 64.0##L1, 100.0##L2); \
103 CHECK (aj == MIN1 * 64.0##L1 + 64.0##L1 * DENORM_MIN1); \
104 const type ak = fn (MIN1 * 64.0##L1 + DENORM_MIN1 * 64.0##L1, 1024.0##L2); \
105 CHECK (ak == MIN1 * 64.0##L1 + 128.0##L1 * DENORM_MIN1); \
106 const type al = fn (128.0##L1, 128.0##L2); \
107 CHECK (al == 128.0##L1); \
108 const type am = fn (128.0##L1, 129.0##L2); \
109 CHECK (am == 128.0##L1 + 128.0##L1 * EPSILON1); \
110 const type an = fn (-128.0##L1 + -128.0##L1 * EPSILON1, -130.0##L2); \
111 CHECK (an == -128.0##L1 - 256.0##L1 * EPSILON1); \
112 const type ao = fn (128.0##L1 + 256.0##L1 * EPSILON1, 256.0##L2); \
113 CHECK (ao == 128.0##L1 + 384.0##L1 * EPSILON1); \
114 const type ap = fn (128.0##L1 + 384.0##L1 * EPSILON1, -0.0##L2); \
115 CHECK (ap == 128.0##L1 + 256.0##L1 * EPSILON1); \
116 const type aq = fn (128.0##L1 + 256.0##L1 * EPSILON1, 1.0##L2); \
117 CHECK (aq == 128.0##L1 + 128.0##L1 * EPSILON1); \
118 const type ar = fn (128.0##L1 + 128.0##L1 * EPSILON1, 0.0##L2); \
119 CHECK (ar == 128.0##L1); \
120 const type as = fn (128.0##L1, 0.0##L2); \
121 CHECK (as == 128.0##L1 - 64.0##L1 * EPSILON1); \
122 const type at = fn (128.0##L1 - 64.0##L1 * EPSILON1, 5.0##L2); \
123 CHECK (at == 128.0##L1 - 128.0##L1 * EPSILON1); \
126 TEST (test1, nextafterf, float, F, F, f, f, __FLT_MIN__, __FLT_MAX__,
127 __FLT_DENORM_MIN__, __FLT_EPSILON__, __FLT_MIN__, __FLT_MAX__,
128 __FLT_DENORM_MIN__)
129 TEST (test2, nextafter, double, , , , , __DBL_MIN__, __DBL_MAX__,
130 __DBL_DENORM_MIN__, __DBL_EPSILON__, __DBL_MIN__, __DBL_MAX__,
131 __DBL_DENORM_MIN__)
132 #if __LDBL_MANT_DIG__ != 106
133 TEST (test3, nextafterl, long double, L, L, l, l, __LDBL_MIN__, __LDBL_MAX__,
134 __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
135 __LDBL_DENORM_MIN__)
136 TEST (test4, nexttowardf, float, F, L, f, l, __FLT_MIN__, __FLT_MAX__,
137 __FLT_DENORM_MIN__, __FLT_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
138 __LDBL_DENORM_MIN__)
139 TEST (test5, nexttoward, double, , L, , l, __DBL_MIN__, __DBL_MAX__,
140 __DBL_DENORM_MIN__, __DBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
141 __LDBL_DENORM_MIN__)
142 TEST (test6, nexttowardl, long double, L, L, l, l, __LDBL_MIN__, __LDBL_MAX__,
143 __LDBL_DENORM_MIN__, __LDBL_EPSILON__, __LDBL_MIN__, __LDBL_MAX__,
144 __LDBL_DENORM_MIN__)
145 #endif
148 main ()
150 test1 ();
151 test2 ();
152 #if __LDBL_MANT_DIG__ != 106
153 test3 ();
154 test4 ();
155 test5 ();
156 test6 ();
157 #endif
158 return 0;