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