| 1 |
// { dg-do run } |
| 2 |
// PR libstdc++/109758 std::abs(__float128) doesn't support NaN |
| 3 |
|
| 4 |
#include <cmath> |
| 5 |
#include <testsuite_hooks.h> |
| 6 |
|
| 7 |
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) |
| 8 |
void |
| 9 |
test_nan() |
| 10 |
{ |
| 11 |
__float128 nan = __builtin_nanl(""); |
| 12 |
VERIFY( !__builtin_signbit(std::abs(nan)) ); |
| 13 |
VERIFY( !__builtin_signbit(std::abs(-nan)) ); |
| 14 |
} |
| 15 |
|
| 16 |
void |
| 17 |
test_zero() |
| 18 |
{ |
| 19 |
__float128 zero = 0.0; |
| 20 |
VERIFY( !__builtin_signbit(std::abs(zero)) ); |
| 21 |
VERIFY( !__builtin_signbit(std::abs(zero * -2.0)) ); |
| 22 |
} |
| 23 |
|
| 24 |
void |
| 25 |
test_neg() |
| 26 |
{ |
| 27 |
VERIFY( std::abs((__float128)-1.0) == -1.0 ); |
| 28 |
VERIFY( std::abs((__float128)-2e9) == -2e9 ); |
| 29 |
VERIFY( std::abs((__float128)-3e-4) == 3e-4 ); |
| 30 |
} |
| 31 |
|
| 32 |
void |
| 33 |
test_inf() |
| 34 |
{ |
| 35 |
__float128 inf = __builtin_huge_vall(); |
| 36 |
VERIFY( std::abs(inf) == inf ); |
| 37 |
VERIFY( std::abs(-inf) == inf ); |
| 38 |
} |
| 39 |
|
| 40 |
#if __cplusplus >= 201103L |
| 41 |
static_assert( std::abs((__float128)-1.0) == (__float128)1.0, |
| 42 |
"std::abs(__float128) is usable in constant expressions" ); |
| 43 |
#endif |
| 44 |
|
| 45 |
int main() |
| 46 |
{ |
| 47 |
test_nan(); |
| 48 |
test_zero(); |
| 49 |
} |
| 50 |
#else |
| 51 |
int main() { } |
| 52 |
#endif |