diff options
Diffstat (limited to 'test/std/numerics/c.math/cmath.pass.cpp')
-rw-r--r-- | test/std/numerics/c.math/cmath.pass.cpp | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/test/std/numerics/c.math/cmath.pass.cpp b/test/std/numerics/c.math/cmath.pass.cpp index 0b0d86288737..7161bd37e3e2 100644 --- a/test/std/numerics/c.math/cmath.pass.cpp +++ b/test/std/numerics/c.math/cmath.pass.cpp @@ -9,13 +9,11 @@ // <cmath> -// NOTE: isinf and isnan are tested separately because they are expected to fail -// on linux. We don't want their expected failure to hide other failures in this file. - #include <cmath> #include <type_traits> #include <cassert> +#include "test_macros.h" #include "hexfloat.h" // convertible to int/float/double/etc @@ -79,6 +77,7 @@ Ambiguous fma(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous fmax(Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous fmin(Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous hypot(Ambiguous, Ambiguous){ return Ambiguous(); } +Ambiguous hypot(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } Ambiguous ilogb(Ambiguous){ return Ambiguous(); } Ambiguous lgamma(Ambiguous){ return Ambiguous(); } Ambiguous llrint(Ambiguous){ return Ambiguous(); } @@ -631,6 +630,29 @@ void test_isgreaterequal() assert(std::isgreaterequal(-1.0, 0.F) == false); } +void test_isinf() +{ +#ifdef isinf +#error isinf defined +#endif + static_assert((std::is_same<decltype(std::isinf((float)0)), bool>::value), ""); + + typedef decltype(std::isinf((double)0)) DoubleRetType; +#ifndef __linux__ + static_assert((std::is_same<DoubleRetType, bool>::value), ""); +#else + // GLIBC < 2.26 defines 'isinf(double)' with a return type of 'int' in + // all C++ dialects. The test should tolerate this. + // See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439 + static_assert((std::is_same<DoubleRetType, bool>::value + || std::is_same<DoubleRetType, int>::value), ""); +#endif + + static_assert((std::is_same<decltype(std::isinf(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isinf((long double)0)), bool>::value), ""); + assert(std::isinf(-1.0) == false); +} + void test_isless() { #ifdef isless @@ -688,6 +710,29 @@ void test_islessgreater() assert(std::islessgreater(-1.0, 0.F) == true); } +void test_isnan() +{ +#ifdef isnan +#error isnan defined +#endif + static_assert((std::is_same<decltype(std::isnan((float)0)), bool>::value), ""); + + typedef decltype(std::isnan((double)0)) DoubleRetType; +#ifndef __linux__ + static_assert((std::is_same<DoubleRetType, bool>::value), ""); +#else + // GLIBC < 2.26 defines 'isnan(double)' with a return type of 'int' in + // all C++ dialects. The test should tolerate this. + // See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439 + static_assert((std::is_same<DoubleRetType, bool>::value + || std::is_same<DoubleRetType, int>::value), ""); +#endif + + static_assert((std::is_same<decltype(std::isnan(0)), bool>::value), ""); + static_assert((std::is_same<decltype(std::isnan((long double)0)), bool>::value), ""); + assert(std::isnan(-1.0) == false); +} + void test_isunordered() { #ifdef isunordered @@ -1010,6 +1055,28 @@ void test_hypot() static_assert((std::is_same<decltype(std::hypot((int)0, (int)0)), double>::value), ""); static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous())), Ambiguous>::value), ""); assert(std::hypot(3,4) == 5); + +#if TEST_STD_VER > 14 + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (float)0)), float>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (bool)0, (float)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned short)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (unsigned int)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (long double)0, (unsigned long)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (int)0, (unsigned long long)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (long double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (double)0)), double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (float)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((float)0, (double)0, (long double)0)), long double>::value), ""); + static_assert((std::is_same<decltype(std::hypot((int)0, (int)0, (int)0)), double>::value), ""); + static_assert((std::is_same<decltype(hypot(Ambiguous(), Ambiguous(), Ambiguous())), Ambiguous>::value), ""); + + assert(std::hypot(2,3,6) == 7); + assert(std::hypot(1,4,8) == 9); +#endif } void test_ilogb() @@ -1443,9 +1510,11 @@ int main() test_isnormal(); test_isgreater(); test_isgreaterequal(); + test_isinf(); test_isless(); test_islessequal(); test_islessgreater(); + test_isnan(); test_isunordered(); test_acosh(); test_asinh(); |