| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // This test fails because Clang no longer enables -fdelayed-template-parsing |
| 10 | // by default on Windows with C++20 (#69431). |
| 11 | // XFAIL: msvc && (clang-18 || clang-19 || clang-20 || clang-21) |
| 12 | |
| 13 | // <math.h> |
| 14 | |
| 15 | // GCC warns about signbit comparing `bool_v < 0`, which we're testing |
| 16 | // ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare |
| 17 | |
| 18 | #include <math.h> |
| 19 | #include <type_traits> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | #include "hexfloat.h" |
| 24 | #include "truncate_fp.h" |
| 25 | #include "type_algorithms.h" |
| 26 | |
| 27 | // convertible to int/float/double/etc |
| 28 | template <class T, int N=0> |
| 29 | struct Value { |
| 30 | operator T () { return T(N); } |
| 31 | }; |
| 32 | |
| 33 | // See PR21083 |
| 34 | // Ambiguous is a user-defined type that defines its own overloads of cmath |
| 35 | // functions. When the std overloads are candidates too (by using or adl), |
| 36 | // they should not interfere. |
| 37 | struct Ambiguous : std::true_type { // ADL |
| 38 | operator float () { return 0.f; } |
| 39 | operator double () { return 0.; } |
| 40 | }; |
| 41 | Ambiguous abs(Ambiguous){ return Ambiguous(); } |
| 42 | Ambiguous acos(Ambiguous){ return Ambiguous(); } |
| 43 | Ambiguous asin(Ambiguous){ return Ambiguous(); } |
| 44 | Ambiguous atan(Ambiguous){ return Ambiguous(); } |
| 45 | Ambiguous atan2(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 46 | Ambiguous ceil(Ambiguous){ return Ambiguous(); } |
| 47 | Ambiguous cos(Ambiguous){ return Ambiguous(); } |
| 48 | Ambiguous cosh(Ambiguous){ return Ambiguous(); } |
| 49 | Ambiguous exp(Ambiguous){ return Ambiguous(); } |
| 50 | Ambiguous fabs(Ambiguous){ return Ambiguous(); } |
| 51 | Ambiguous floor(Ambiguous){ return Ambiguous(); } |
| 52 | Ambiguous fmod(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 53 | Ambiguous frexp(Ambiguous, int*){ return Ambiguous(); } |
| 54 | Ambiguous ldexp(Ambiguous, int){ return Ambiguous(); } |
| 55 | Ambiguous log(Ambiguous){ return Ambiguous(); } |
| 56 | Ambiguous log10(Ambiguous){ return Ambiguous(); } |
| 57 | Ambiguous modf(Ambiguous, Ambiguous*){ return Ambiguous(); } |
| 58 | Ambiguous pow(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 59 | Ambiguous sin(Ambiguous){ return Ambiguous(); } |
| 60 | Ambiguous sinh(Ambiguous){ return Ambiguous(); } |
| 61 | Ambiguous sqrt(Ambiguous){ return Ambiguous(); } |
| 62 | Ambiguous tan(Ambiguous){ return Ambiguous(); } |
| 63 | Ambiguous tanh(Ambiguous){ return Ambiguous(); } |
| 64 | Ambiguous signbit(Ambiguous){ return Ambiguous(); } |
| 65 | Ambiguous fpclassify(Ambiguous){ return Ambiguous(); } |
| 66 | Ambiguous isfinite(Ambiguous){ return Ambiguous(); } |
| 67 | Ambiguous isnormal(Ambiguous){ return Ambiguous(); } |
| 68 | Ambiguous isgreater(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 69 | Ambiguous isgreaterequal(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 70 | Ambiguous isless(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 71 | Ambiguous islessequal(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 72 | Ambiguous islessgreater(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 73 | Ambiguous isunordered(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 74 | Ambiguous acosh(Ambiguous){ return Ambiguous(); } |
| 75 | Ambiguous asinh(Ambiguous){ return Ambiguous(); } |
| 76 | Ambiguous atanh(Ambiguous){ return Ambiguous(); } |
| 77 | Ambiguous cbrt(Ambiguous){ return Ambiguous(); } |
| 78 | Ambiguous copysign(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 79 | Ambiguous erf(Ambiguous){ return Ambiguous(); } |
| 80 | Ambiguous erfc(Ambiguous){ return Ambiguous(); } |
| 81 | Ambiguous exp2(Ambiguous){ return Ambiguous(); } |
| 82 | Ambiguous expm1(Ambiguous){ return Ambiguous(); } |
| 83 | Ambiguous fdim(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 84 | Ambiguous fma(Ambiguous, Ambiguous, Ambiguous){ return Ambiguous(); } |
| 85 | Ambiguous fmax(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 86 | Ambiguous fmin(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 87 | Ambiguous hypot(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 88 | Ambiguous ilogb(Ambiguous){ return Ambiguous(); } |
| 89 | Ambiguous lgamma(Ambiguous){ return Ambiguous(); } |
| 90 | Ambiguous llrint(Ambiguous){ return Ambiguous(); } |
| 91 | Ambiguous llround(Ambiguous){ return Ambiguous(); } |
| 92 | Ambiguous log1p(Ambiguous){ return Ambiguous(); } |
| 93 | Ambiguous log2(Ambiguous){ return Ambiguous(); } |
| 94 | Ambiguous logb(Ambiguous){ return Ambiguous(); } |
| 95 | Ambiguous lrint(Ambiguous){ return Ambiguous(); } |
| 96 | Ambiguous lround(Ambiguous){ return Ambiguous(); } |
| 97 | Ambiguous nearbyint(Ambiguous){ return Ambiguous(); } |
| 98 | Ambiguous nextafter(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 99 | Ambiguous nexttoward(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 100 | Ambiguous remainder(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 101 | Ambiguous remquo(Ambiguous, Ambiguous, int*){ return Ambiguous(); } |
| 102 | Ambiguous rint(Ambiguous){ return Ambiguous(); } |
| 103 | Ambiguous round(Ambiguous){ return Ambiguous(); } |
| 104 | Ambiguous scalbln(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 105 | Ambiguous scalbn(Ambiguous, Ambiguous){ return Ambiguous(); } |
| 106 | Ambiguous tgamma(Ambiguous){ return Ambiguous(); } |
| 107 | Ambiguous trunc(Ambiguous){ return Ambiguous(); } |
| 108 | |
| 109 | template <class T, class = decltype(::abs(T()))> |
| 110 | std::true_type has_abs_imp(int); |
| 111 | template <class T> |
| 112 | std::false_type has_abs_imp(...); |
| 113 | |
| 114 | template <class T> |
| 115 | struct has_abs : decltype(has_abs_imp<T>(0)) {}; |
| 116 | |
| 117 | void test_abs() { |
| 118 | TEST_DIAGNOSTIC_PUSH |
| 119 | TEST_CLANG_DIAGNOSTIC_IGNORED("-Wabsolute-value" ) |
| 120 | |
| 121 | ASSERT_SAME_TYPE(decltype(abs((float)0)), float); |
| 122 | ASSERT_SAME_TYPE(decltype(abs((double)0)), double); |
| 123 | ASSERT_SAME_TYPE(decltype(abs((long double)0)), long double); |
| 124 | ASSERT_SAME_TYPE(decltype(abs((int)0)), int); |
| 125 | ASSERT_SAME_TYPE(decltype(abs((long)0)), long); |
| 126 | ASSERT_SAME_TYPE(decltype(abs((long long)0)), long long); |
| 127 | ASSERT_SAME_TYPE(decltype(abs((unsigned char)0)), int); |
| 128 | ASSERT_SAME_TYPE(decltype(abs((unsigned short)0)), int); |
| 129 | ASSERT_SAME_TYPE(decltype(abs(Ambiguous())), Ambiguous); |
| 130 | |
| 131 | static_assert(!has_abs<unsigned>::value, "" ); |
| 132 | static_assert(!has_abs<unsigned long>::value, "" ); |
| 133 | static_assert(!has_abs<unsigned long long>::value, "" ); |
| 134 | |
| 135 | TEST_DIAGNOSTIC_POP |
| 136 | |
| 137 | assert(abs(-1.) == 1); |
| 138 | } |
| 139 | |
| 140 | void test_acos() { |
| 141 | ASSERT_SAME_TYPE(decltype(acosf(0)), float); |
| 142 | ASSERT_SAME_TYPE(decltype(acosl(0)), long double); |
| 143 | ASSERT_SAME_TYPE(decltype(acos(Ambiguous())), Ambiguous); |
| 144 | assert(acos(1) == 0); |
| 145 | } |
| 146 | |
| 147 | void test_asin() { |
| 148 | ASSERT_SAME_TYPE(decltype(asinf(0)), float); |
| 149 | ASSERT_SAME_TYPE(decltype(asinl(0)), long double); |
| 150 | ASSERT_SAME_TYPE(decltype(asin(Ambiguous())), Ambiguous); |
| 151 | assert(asin(0) == 0); |
| 152 | } |
| 153 | |
| 154 | void test_atan() { |
| 155 | ASSERT_SAME_TYPE(decltype(atanf(0)), float); |
| 156 | ASSERT_SAME_TYPE(decltype(atanl(0)), long double); |
| 157 | ASSERT_SAME_TYPE(decltype(atan(Ambiguous())), Ambiguous); |
| 158 | assert(atan(0) == 0); |
| 159 | } |
| 160 | |
| 161 | void test_atan2() { |
| 162 | ASSERT_SAME_TYPE(decltype(atan2f(0,0)), float); |
| 163 | ASSERT_SAME_TYPE(decltype(atan2l(0,0)), long double); |
| 164 | ASSERT_SAME_TYPE(decltype(atan2(Ambiguous(), Ambiguous())), Ambiguous); |
| 165 | assert(atan2(0,1) == 0); |
| 166 | } |
| 167 | |
| 168 | void test_ceil() { |
| 169 | ASSERT_SAME_TYPE(decltype(ceilf(0)), float); |
| 170 | ASSERT_SAME_TYPE(decltype(ceill(0)), long double); |
| 171 | ASSERT_SAME_TYPE(decltype(ceil(Ambiguous())), Ambiguous); |
| 172 | assert(ceil(0) == 0); |
| 173 | } |
| 174 | |
| 175 | void test_cos() { |
| 176 | ASSERT_SAME_TYPE(decltype(cosf(0)), float); |
| 177 | ASSERT_SAME_TYPE(decltype(cosl(0)), long double); |
| 178 | ASSERT_SAME_TYPE(decltype(cos(Ambiguous())), Ambiguous); |
| 179 | assert(cos(0) == 1); |
| 180 | } |
| 181 | |
| 182 | void test_cosh() { |
| 183 | ASSERT_SAME_TYPE(decltype(coshf(0)), float); |
| 184 | ASSERT_SAME_TYPE(decltype(coshl(0)), long double); |
| 185 | ASSERT_SAME_TYPE(decltype(cosh(Ambiguous())), Ambiguous); |
| 186 | assert(cosh(0) == 1); |
| 187 | } |
| 188 | |
| 189 | void test_exp() { |
| 190 | ASSERT_SAME_TYPE(decltype(expf(0)), float); |
| 191 | ASSERT_SAME_TYPE(decltype(expl(0)), long double); |
| 192 | ASSERT_SAME_TYPE(decltype(exp(Ambiguous())), Ambiguous); |
| 193 | assert(exp(0) == 1); |
| 194 | } |
| 195 | |
| 196 | void test_fabs() { |
| 197 | ASSERT_SAME_TYPE(decltype(fabsf(0.0f)), float); |
| 198 | ASSERT_SAME_TYPE(decltype(fabsl(0.0L)), long double); |
| 199 | ASSERT_SAME_TYPE(decltype(fabs(Ambiguous())), Ambiguous); |
| 200 | assert(fabs(-1) == 1); |
| 201 | } |
| 202 | |
| 203 | void test_floor() { |
| 204 | ASSERT_SAME_TYPE(decltype(floorf(0)), float); |
| 205 | ASSERT_SAME_TYPE(decltype(floorl(0)), long double); |
| 206 | ASSERT_SAME_TYPE(decltype(floor(Ambiguous())), Ambiguous); |
| 207 | assert(floor(1) == 1); |
| 208 | } |
| 209 | |
| 210 | void test_fmod() { |
| 211 | ASSERT_SAME_TYPE(decltype(fmodf(0,0)), float); |
| 212 | ASSERT_SAME_TYPE(decltype(fmodl(0,0)), long double); |
| 213 | ASSERT_SAME_TYPE(decltype(fmod(Ambiguous(), Ambiguous())), Ambiguous); |
| 214 | assert(fmod(1.5,1) == .5); |
| 215 | } |
| 216 | |
| 217 | void test_frexp() { |
| 218 | int ip; |
| 219 | ASSERT_SAME_TYPE(decltype(frexpf(0, &ip)), float); |
| 220 | ASSERT_SAME_TYPE(decltype(frexpl(0, &ip)), long double); |
| 221 | ASSERT_SAME_TYPE(decltype(frexp(Ambiguous(), &ip)), Ambiguous); |
| 222 | assert(frexp(0, &ip) == 0); |
| 223 | } |
| 224 | |
| 225 | void test_ldexp() { |
| 226 | int ip = 1; |
| 227 | ASSERT_SAME_TYPE(decltype(ldexpf(0, ip)), float); |
| 228 | ASSERT_SAME_TYPE(decltype(ldexpl(0, ip)), long double); |
| 229 | ASSERT_SAME_TYPE(decltype(ldexp(Ambiguous(), ip)), Ambiguous); |
| 230 | assert(ldexp(1, ip) == 2); |
| 231 | } |
| 232 | |
| 233 | void test_log() { |
| 234 | ASSERT_SAME_TYPE(decltype(logf(0)), float); |
| 235 | ASSERT_SAME_TYPE(decltype(logl(0)), long double); |
| 236 | ASSERT_SAME_TYPE(decltype(log(Ambiguous())), Ambiguous); |
| 237 | assert(log(1) == 0); |
| 238 | } |
| 239 | |
| 240 | void test_log10() { |
| 241 | ASSERT_SAME_TYPE(decltype(log10f(0)), float); |
| 242 | ASSERT_SAME_TYPE(decltype(log10l(0)), long double); |
| 243 | ASSERT_SAME_TYPE(decltype(log10(Ambiguous())), Ambiguous); |
| 244 | assert(log10(1) == 0); |
| 245 | } |
| 246 | |
| 247 | void test_modf() { |
| 248 | ASSERT_SAME_TYPE(decltype(modf((float)0, (float*)0)), float); |
| 249 | ASSERT_SAME_TYPE(decltype(modf((double)0, (double*)0)), double); |
| 250 | ASSERT_SAME_TYPE(decltype(modf((long double)0, (long double*)0)), long double); |
| 251 | ASSERT_SAME_TYPE(decltype(modff(0, (float*)0)), float); |
| 252 | ASSERT_SAME_TYPE(decltype(modfl(0, (long double*)0)), long double); |
| 253 | ASSERT_SAME_TYPE(decltype(modf(Ambiguous(), (Ambiguous*)0)), Ambiguous); |
| 254 | double i; |
| 255 | assert(modf(1., &i) == 0); |
| 256 | } |
| 257 | |
| 258 | void test_pow() { |
| 259 | ASSERT_SAME_TYPE(decltype(powf(0,0)), float); |
| 260 | ASSERT_SAME_TYPE(decltype(powl(0,0)), long double); |
| 261 | ASSERT_SAME_TYPE(decltype(pow((int)0, (int)0)), double); |
| 262 | // ASSERT_SAME_TYPE(decltype(pow(Value<int>(), (int)0)), double); |
| 263 | // ASSERT_SAME_TYPE(decltype(pow(Value<long double>(), (float)0)), long double); |
| 264 | // ASSERT_SAME_TYPE(decltype(pow((float) 0, Value<float>())), float); |
| 265 | ASSERT_SAME_TYPE(decltype(pow(Ambiguous(), Ambiguous())), Ambiguous); |
| 266 | assert(pow(1,1) == 1); |
| 267 | // assert(pow(Value<int,1>(), Value<float,1>()) == 1); |
| 268 | // assert(pow(1.0f, Value<double,1>()) == 1); |
| 269 | // assert(pow(1.0, Value<int,1>()) == 1); |
| 270 | // assert(pow(Value<long double,1>(), 1LL) == 1); |
| 271 | } |
| 272 | |
| 273 | void test_sin() { |
| 274 | ASSERT_SAME_TYPE(decltype(sinf(0)), float); |
| 275 | ASSERT_SAME_TYPE(decltype(sinl(0)), long double); |
| 276 | ASSERT_SAME_TYPE(decltype(sin(Ambiguous())), Ambiguous); |
| 277 | assert(sin(0) == 0); |
| 278 | } |
| 279 | |
| 280 | void test_sinh() { |
| 281 | ASSERT_SAME_TYPE(decltype(sinhf(0)), float); |
| 282 | ASSERT_SAME_TYPE(decltype(sinhl(0)), long double); |
| 283 | ASSERT_SAME_TYPE(decltype(sinh(Ambiguous())), Ambiguous); |
| 284 | assert(sinh(0) == 0); |
| 285 | } |
| 286 | |
| 287 | void test_sqrt() { |
| 288 | ASSERT_SAME_TYPE(decltype(sqrtf(0)), float); |
| 289 | ASSERT_SAME_TYPE(decltype(sqrtl(0)), long double); |
| 290 | ASSERT_SAME_TYPE(decltype(sqrt(Ambiguous())), Ambiguous); |
| 291 | assert(sqrt(4) == 2); |
| 292 | } |
| 293 | |
| 294 | void test_tan() { |
| 295 | ASSERT_SAME_TYPE(decltype(tanf(0)), float); |
| 296 | ASSERT_SAME_TYPE(decltype(tanl(0)), long double); |
| 297 | ASSERT_SAME_TYPE(decltype(tan(Ambiguous())), Ambiguous); |
| 298 | assert(tan(0) == 0); |
| 299 | } |
| 300 | |
| 301 | void test_tanh() { |
| 302 | ASSERT_SAME_TYPE(decltype(tanhf(0)), float); |
| 303 | ASSERT_SAME_TYPE(decltype(tanhl(0)), long double); |
| 304 | ASSERT_SAME_TYPE(decltype(tanh(Ambiguous())), Ambiguous); |
| 305 | assert(tanh(0) == 0); |
| 306 | } |
| 307 | |
| 308 | void test_signbit() { |
| 309 | #ifdef signbit |
| 310 | #error signbit defined |
| 311 | #endif |
| 312 | ASSERT_SAME_TYPE(decltype(signbit(Ambiguous())), Ambiguous); |
| 313 | assert(signbit(-1.0) == true); |
| 314 | } |
| 315 | |
| 316 | void test_fpclassify() { |
| 317 | #ifdef fpclassify |
| 318 | #error fpclassify defined |
| 319 | #endif |
| 320 | ASSERT_SAME_TYPE(decltype(fpclassify(Ambiguous())), Ambiguous); |
| 321 | assert(fpclassify(-1.0) == FP_NORMAL); |
| 322 | } |
| 323 | |
| 324 | void test_isfinite() { |
| 325 | #ifdef isfinite |
| 326 | #error isfinite defined |
| 327 | #endif |
| 328 | ASSERT_SAME_TYPE(decltype(isfinite(Ambiguous())), Ambiguous); |
| 329 | assert(isfinite(-1.0) == true); |
| 330 | } |
| 331 | |
| 332 | void test_isnormal() { |
| 333 | #ifdef isnormal |
| 334 | #error isnormal defined |
| 335 | #endif |
| 336 | ASSERT_SAME_TYPE(decltype(isnormal(Ambiguous())), Ambiguous); |
| 337 | assert(isnormal(-1.0) == true); |
| 338 | } |
| 339 | |
| 340 | void test_isgreater() { |
| 341 | #ifdef isgreater |
| 342 | #error isgreater defined |
| 343 | #endif |
| 344 | ASSERT_SAME_TYPE(decltype(isgreater(Ambiguous(), Ambiguous())), Ambiguous); |
| 345 | assert(isgreater(-1.0, 0.F) == false); |
| 346 | } |
| 347 | |
| 348 | void test_isgreaterequal() { |
| 349 | #ifdef isgreaterequal |
| 350 | #error isgreaterequal defined |
| 351 | #endif |
| 352 | ASSERT_SAME_TYPE(decltype(isgreaterequal(Ambiguous(), Ambiguous())), Ambiguous); |
| 353 | assert(isgreaterequal(-1.0, 0.F) == false); |
| 354 | } |
| 355 | |
| 356 | void test_isinf() { |
| 357 | #ifdef isinf |
| 358 | #error isinf defined |
| 359 | #endif |
| 360 | ASSERT_SAME_TYPE(decltype(isinf((float)0)), bool); |
| 361 | |
| 362 | typedef decltype(isinf(x: (double)0)) DoubleRetType; |
| 363 | #ifndef __linux__ |
| 364 | ASSERT_SAME_TYPE(DoubleRetType, bool); |
| 365 | #else |
| 366 | // GLIBC < 2.26 defines 'isinf(double)' with a return type of 'int' in |
| 367 | // all C++ dialects. The test should tolerate this. |
| 368 | // See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439 |
| 369 | static_assert((std::is_same<DoubleRetType, bool>::value |
| 370 | || std::is_same<DoubleRetType, int>::value), "" ); |
| 371 | #endif |
| 372 | |
| 373 | ASSERT_SAME_TYPE(decltype(isinf(0)), bool); |
| 374 | ASSERT_SAME_TYPE(decltype(isinf((long double)0)), bool); |
| 375 | assert(isinf(-1.0) == false); |
| 376 | } |
| 377 | |
| 378 | void test_isless() { |
| 379 | #ifdef isless |
| 380 | #error isless defined |
| 381 | #endif |
| 382 | ASSERT_SAME_TYPE(decltype(isless(Ambiguous(), Ambiguous())), Ambiguous); |
| 383 | assert(isless(-1.0, 0.F) == true); |
| 384 | } |
| 385 | |
| 386 | void test_islessequal() { |
| 387 | #ifdef islessequal |
| 388 | #error islessequal defined |
| 389 | #endif |
| 390 | ASSERT_SAME_TYPE(decltype(islessequal(Ambiguous(), Ambiguous())), Ambiguous); |
| 391 | assert(islessequal(-1.0, 0.F) == true); |
| 392 | } |
| 393 | |
| 394 | void test_islessgreater() { |
| 395 | #ifdef islessgreater |
| 396 | #error islessgreater defined |
| 397 | #endif |
| 398 | ASSERT_SAME_TYPE(decltype(islessgreater(Ambiguous(), Ambiguous())), Ambiguous); |
| 399 | assert(islessgreater(-1.0, 0.F) == true); |
| 400 | } |
| 401 | |
| 402 | void test_isnan() { |
| 403 | #ifdef isnan |
| 404 | #error isnan defined |
| 405 | #endif |
| 406 | ASSERT_SAME_TYPE(decltype(isnan((float)0)), bool); |
| 407 | |
| 408 | typedef decltype(isnan(x: (double)0)) DoubleRetType; |
| 409 | #ifndef __linux__ |
| 410 | ASSERT_SAME_TYPE(DoubleRetType, bool); |
| 411 | #else |
| 412 | // GLIBC < 2.26 defines 'isnan(double)' with a return type of 'int' in |
| 413 | // all C++ dialects. The test should tolerate this. |
| 414 | // See: https://sourceware.org/bugzilla/show_bug.cgi?id=19439 |
| 415 | static_assert((std::is_same<DoubleRetType, bool>::value |
| 416 | || std::is_same<DoubleRetType, int>::value), "" ); |
| 417 | #endif |
| 418 | |
| 419 | ASSERT_SAME_TYPE(decltype(isnan(0)), bool); |
| 420 | ASSERT_SAME_TYPE(decltype(isnan((long double)0)), bool); |
| 421 | assert(isnan(-1.0) == false); |
| 422 | } |
| 423 | |
| 424 | void test_isunordered() { |
| 425 | #ifdef isunordered |
| 426 | #error isunordered defined |
| 427 | #endif |
| 428 | ASSERT_SAME_TYPE(decltype(isunordered(Ambiguous(), Ambiguous())), Ambiguous); |
| 429 | assert(isunordered(-1.0, 0.F) == false); |
| 430 | } |
| 431 | |
| 432 | void test_acosh() { |
| 433 | ASSERT_SAME_TYPE(decltype(acoshf(0)), float); |
| 434 | ASSERT_SAME_TYPE(decltype(acoshl(0)), long double); |
| 435 | ASSERT_SAME_TYPE(decltype(acosh(Ambiguous())), Ambiguous); |
| 436 | assert(acosh(1) == 0); |
| 437 | } |
| 438 | |
| 439 | void test_asinh() { |
| 440 | ASSERT_SAME_TYPE(decltype(asinhf(0)), float); |
| 441 | ASSERT_SAME_TYPE(decltype(asinhl(0)), long double); |
| 442 | ASSERT_SAME_TYPE(decltype(asinh(Ambiguous())), Ambiguous); |
| 443 | assert(asinh(0) == 0); |
| 444 | } |
| 445 | |
| 446 | void test_atanh() { |
| 447 | ASSERT_SAME_TYPE(decltype(atanhf(0)), float); |
| 448 | ASSERT_SAME_TYPE(decltype(atanhl(0)), long double); |
| 449 | ASSERT_SAME_TYPE(decltype(atanh(Ambiguous())), Ambiguous); |
| 450 | assert(atanh(0) == 0); |
| 451 | } |
| 452 | |
| 453 | void test_cbrt() { |
| 454 | ASSERT_SAME_TYPE(decltype(cbrtf(0)), float); |
| 455 | ASSERT_SAME_TYPE(decltype(cbrtl(0)), long double); |
| 456 | ASSERT_SAME_TYPE(decltype(cbrt(Ambiguous())), Ambiguous); |
| 457 | assert(truncate_fp(cbrt(1)) == 1); |
| 458 | } |
| 459 | |
| 460 | void test_copysign() { |
| 461 | ASSERT_SAME_TYPE(decltype(copysignf(0,0)), float); |
| 462 | ASSERT_SAME_TYPE(decltype(copysignl(0,0)), long double); |
| 463 | ASSERT_SAME_TYPE(decltype(copysign((int)0, (int)0)), double); |
| 464 | ASSERT_SAME_TYPE(decltype(copysign(Ambiguous(), Ambiguous())), Ambiguous); |
| 465 | assert(copysign(1,1) == 1); |
| 466 | } |
| 467 | |
| 468 | void test_erf() { |
| 469 | ASSERT_SAME_TYPE(decltype(erff(0)), float); |
| 470 | ASSERT_SAME_TYPE(decltype(erfl(0)), long double); |
| 471 | ASSERT_SAME_TYPE(decltype(erf(Ambiguous())), Ambiguous); |
| 472 | assert(erf(0) == 0); |
| 473 | } |
| 474 | |
| 475 | void test_erfc() { |
| 476 | ASSERT_SAME_TYPE(decltype(erfcf(0)), float); |
| 477 | ASSERT_SAME_TYPE(decltype(erfcl(0)), long double); |
| 478 | ASSERT_SAME_TYPE(decltype(erfc(Ambiguous())), Ambiguous); |
| 479 | assert(erfc(0) == 1); |
| 480 | } |
| 481 | |
| 482 | void test_exp2() { |
| 483 | ASSERT_SAME_TYPE(decltype(exp2f(0)), float); |
| 484 | ASSERT_SAME_TYPE(decltype(exp2l(0)), long double); |
| 485 | ASSERT_SAME_TYPE(decltype(exp2(Ambiguous())), Ambiguous); |
| 486 | assert(exp2(1) == 2); |
| 487 | } |
| 488 | |
| 489 | void test_expm1() { |
| 490 | ASSERT_SAME_TYPE(decltype(expm1f(0)), float); |
| 491 | ASSERT_SAME_TYPE(decltype(expm1l(0)), long double); |
| 492 | ASSERT_SAME_TYPE(decltype(expm1(Ambiguous())), Ambiguous); |
| 493 | assert(expm1(0) == 0); |
| 494 | } |
| 495 | |
| 496 | void test_fdim() { |
| 497 | ASSERT_SAME_TYPE(decltype(fdimf(0,0)), float); |
| 498 | ASSERT_SAME_TYPE(decltype(fdiml(0,0)), long double); |
| 499 | ASSERT_SAME_TYPE(decltype(fdim((int)0, (int)0)), double); |
| 500 | ASSERT_SAME_TYPE(decltype(fdim(Ambiguous(), Ambiguous())), Ambiguous); |
| 501 | assert(fdim(1,0) == 1); |
| 502 | } |
| 503 | |
| 504 | void test_fma() { |
| 505 | ASSERT_SAME_TYPE(decltype(fma((bool)0, (float)0, (float)0)), double); |
| 506 | ASSERT_SAME_TYPE(decltype(fma((float)0, (float)0, (double)0)), double); |
| 507 | ASSERT_SAME_TYPE(decltype(fma((float)0, (float)0, (long double)0)), long double); |
| 508 | ASSERT_SAME_TYPE(decltype(fma((float)0, (float)0, (float)0)), float); |
| 509 | |
| 510 | ASSERT_SAME_TYPE(decltype(fma((bool)0, (double)0, (double)0)), double); |
| 511 | ASSERT_SAME_TYPE(decltype(fma((double)0, (double)0, (float)0)), double); |
| 512 | ASSERT_SAME_TYPE(decltype(fma((double)0, (double)0, (long double)0)), long double); |
| 513 | ASSERT_SAME_TYPE(decltype(fma((double)0, (double)0, (double)0)), double); |
| 514 | |
| 515 | ASSERT_SAME_TYPE(decltype(fma((long double)0, (long double)0, (float)0)), long double); |
| 516 | ASSERT_SAME_TYPE(decltype(fma((double)0, (long double)0, (long double)0)), long double); |
| 517 | ASSERT_SAME_TYPE(decltype(fma((long double)0, (long double)0, (long double)0)), long double); |
| 518 | |
| 519 | ASSERT_SAME_TYPE(decltype(fmaf(0,0,0)), float); |
| 520 | ASSERT_SAME_TYPE(decltype(fmal(0,0,0)), long double); |
| 521 | ASSERT_SAME_TYPE(decltype(fma(Ambiguous(), Ambiguous(), Ambiguous())), Ambiguous); |
| 522 | assert(fma(1,1,1) == 2); |
| 523 | } |
| 524 | |
| 525 | void test_fmax() { |
| 526 | ASSERT_SAME_TYPE(decltype(fmaxf(0,0)), float); |
| 527 | ASSERT_SAME_TYPE(decltype(fmaxl(0,0)), long double); |
| 528 | ASSERT_SAME_TYPE(decltype(fmax((int)0, (int)0)), double); |
| 529 | ASSERT_SAME_TYPE(decltype(fmax(Ambiguous(), Ambiguous())), Ambiguous); |
| 530 | assert(fmax(1,0) == 1); |
| 531 | } |
| 532 | |
| 533 | void test_fmin() { |
| 534 | ASSERT_SAME_TYPE(decltype(fminf(0,0)), float); |
| 535 | ASSERT_SAME_TYPE(decltype(fminl(0,0)), long double); |
| 536 | ASSERT_SAME_TYPE(decltype(fmin((int)0, (int)0)), double); |
| 537 | ASSERT_SAME_TYPE(decltype(fmin(Ambiguous(), Ambiguous())), Ambiguous); |
| 538 | assert(fmin(1,0) == 0); |
| 539 | } |
| 540 | |
| 541 | void test_hypot() { |
| 542 | ASSERT_SAME_TYPE(decltype(hypotf(0,0)), float); |
| 543 | ASSERT_SAME_TYPE(decltype(hypotl(0,0)), long double); |
| 544 | ASSERT_SAME_TYPE(decltype(hypot((int)0, (int)0)), double); |
| 545 | ASSERT_SAME_TYPE(decltype(hypot(Ambiguous(), Ambiguous())), Ambiguous); |
| 546 | assert(hypot(3,4) == 5); |
| 547 | } |
| 548 | |
| 549 | void test_ilogb() { |
| 550 | ASSERT_SAME_TYPE(decltype(ilogbf(0)), int); |
| 551 | ASSERT_SAME_TYPE(decltype(ilogbl(0)), int); |
| 552 | ASSERT_SAME_TYPE(decltype(ilogb(Ambiguous())), Ambiguous); |
| 553 | assert(ilogb(1) == 0); |
| 554 | } |
| 555 | |
| 556 | void test_lgamma() { |
| 557 | ASSERT_SAME_TYPE(decltype(lgammaf(0)), float); |
| 558 | ASSERT_SAME_TYPE(decltype(lgammal(0)), long double); |
| 559 | ASSERT_SAME_TYPE(decltype(lgamma(Ambiguous())), Ambiguous); |
| 560 | assert(lgamma(1) == 0); |
| 561 | } |
| 562 | |
| 563 | void test_llrint() { |
| 564 | ASSERT_SAME_TYPE(decltype(llrintf(0)), long long); |
| 565 | ASSERT_SAME_TYPE(decltype(llrintl(0)), long long); |
| 566 | ASSERT_SAME_TYPE(decltype(llrint(Ambiguous())), Ambiguous); |
| 567 | assert(llrint(1) == 1LL); |
| 568 | } |
| 569 | |
| 570 | void test_llround() { |
| 571 | ASSERT_SAME_TYPE(decltype(llroundf(0)), long long); |
| 572 | ASSERT_SAME_TYPE(decltype(llroundl(0)), long long); |
| 573 | ASSERT_SAME_TYPE(decltype(llround(Ambiguous())), Ambiguous); |
| 574 | assert(llround(1) == 1LL); |
| 575 | } |
| 576 | |
| 577 | void test_log1p() { |
| 578 | ASSERT_SAME_TYPE(decltype(log1pf(0)), float); |
| 579 | ASSERT_SAME_TYPE(decltype(log1pl(0)), long double); |
| 580 | ASSERT_SAME_TYPE(decltype(log1p(Ambiguous())), Ambiguous); |
| 581 | assert(log1p(0) == 0); |
| 582 | } |
| 583 | |
| 584 | void test_log2() { |
| 585 | ASSERT_SAME_TYPE(decltype(log2f(0)), float); |
| 586 | ASSERT_SAME_TYPE(decltype(log2l(0)), long double); |
| 587 | ASSERT_SAME_TYPE(decltype(log2(Ambiguous())), Ambiguous); |
| 588 | assert(log2(1) == 0); |
| 589 | } |
| 590 | |
| 591 | void test_logb() { |
| 592 | ASSERT_SAME_TYPE(decltype(logbf(0)), float); |
| 593 | ASSERT_SAME_TYPE(decltype(logbl(0)), long double); |
| 594 | ASSERT_SAME_TYPE(decltype(logb(Ambiguous())), Ambiguous); |
| 595 | assert(logb(1) == 0); |
| 596 | } |
| 597 | |
| 598 | void test_lrint() { |
| 599 | ASSERT_SAME_TYPE(decltype(lrintf(0)), long); |
| 600 | ASSERT_SAME_TYPE(decltype(lrintl(0)), long); |
| 601 | ASSERT_SAME_TYPE(decltype(lrint(Ambiguous())), Ambiguous); |
| 602 | assert(lrint(1) == 1L); |
| 603 | } |
| 604 | |
| 605 | void test_lround() { |
| 606 | ASSERT_SAME_TYPE(decltype(lroundf(0)), long); |
| 607 | ASSERT_SAME_TYPE(decltype(lroundl(0)), long); |
| 608 | ASSERT_SAME_TYPE(decltype(lround(Ambiguous())), Ambiguous); |
| 609 | assert(lround(1) == 1L); |
| 610 | } |
| 611 | |
| 612 | void test_nan() { |
| 613 | ASSERT_SAME_TYPE(decltype(nan("" )), double); |
| 614 | ASSERT_SAME_TYPE(decltype(nanf("" )), float); |
| 615 | ASSERT_SAME_TYPE(decltype(nanl("" )), long double); |
| 616 | } |
| 617 | |
| 618 | void test_nearbyint() { |
| 619 | ASSERT_SAME_TYPE(decltype(nearbyintf(0)), float); |
| 620 | ASSERT_SAME_TYPE(decltype(nearbyintl(0)), long double); |
| 621 | ASSERT_SAME_TYPE(decltype(nearbyint(Ambiguous())), Ambiguous); |
| 622 | assert(nearbyint(1) == 1); |
| 623 | } |
| 624 | |
| 625 | void test_nextafter() { |
| 626 | ASSERT_SAME_TYPE(decltype(nextafterf(0,0)), float); |
| 627 | ASSERT_SAME_TYPE(decltype(nextafterl(0,0)), long double); |
| 628 | ASSERT_SAME_TYPE(decltype(nextafter((int)0, (int)0)), double); |
| 629 | ASSERT_SAME_TYPE(decltype(nextafter(Ambiguous(), Ambiguous())), Ambiguous); |
| 630 | assert(nextafter(0,1) == hexfloat<double>(0x1, 0, -1074)); |
| 631 | } |
| 632 | |
| 633 | void test_nexttoward() { |
| 634 | ASSERT_SAME_TYPE(decltype(nexttoward((float)0, (long double)0)), float); |
| 635 | ASSERT_SAME_TYPE(decltype(nexttoward((bool)0, (long double)0)), double); |
| 636 | ASSERT_SAME_TYPE(decltype(nexttoward((unsigned short)0, (long double)0)), double); |
| 637 | ASSERT_SAME_TYPE(decltype(nexttoward((int)0, (long double)0)), double); |
| 638 | ASSERT_SAME_TYPE(decltype(nexttoward((unsigned int)0, (long double)0)), double); |
| 639 | ASSERT_SAME_TYPE(decltype(nexttoward((long)0, (long double)0)), double); |
| 640 | ASSERT_SAME_TYPE(decltype(nexttoward((unsigned long)0, (long double)0)), double); |
| 641 | ASSERT_SAME_TYPE(decltype(nexttoward((long long)0, (long double)0)), double); |
| 642 | ASSERT_SAME_TYPE(decltype(nexttoward((unsigned long long)0, (long double)0)), double); |
| 643 | ASSERT_SAME_TYPE(decltype(nexttoward((double)0, (long double)0)), double); |
| 644 | ASSERT_SAME_TYPE(decltype(nexttoward((long double)0, (long double)0)), long double); |
| 645 | ASSERT_SAME_TYPE(decltype(nexttowardf(0, (long double)0)), float); |
| 646 | ASSERT_SAME_TYPE(decltype(nexttowardl(0, (long double)0)), long double); |
| 647 | ASSERT_SAME_TYPE(decltype(nexttoward(Ambiguous(), Ambiguous())), Ambiguous); |
| 648 | assert(nexttoward(0, 1) == hexfloat<double>(0x1, 0, -1074)); |
| 649 | } |
| 650 | |
| 651 | void test_remainder() { |
| 652 | ASSERT_SAME_TYPE(decltype(remainderf(0,0)), float); |
| 653 | ASSERT_SAME_TYPE(decltype(remainderl(0,0)), long double); |
| 654 | ASSERT_SAME_TYPE(decltype(remainder((int)0, (int)0)), double); |
| 655 | ASSERT_SAME_TYPE(decltype(remainder(Ambiguous(), Ambiguous())), Ambiguous); |
| 656 | assert(remainder(0.5,1) == 0.5); |
| 657 | } |
| 658 | |
| 659 | void test_remquo() { |
| 660 | int ip; |
| 661 | ASSERT_SAME_TYPE(decltype(remquof(0,0, &ip)), float); |
| 662 | ASSERT_SAME_TYPE(decltype(remquol(0,0, &ip)), long double); |
| 663 | ASSERT_SAME_TYPE(decltype(remquo((int)0, (int)0, &ip)), double); |
| 664 | ASSERT_SAME_TYPE(decltype(remquo(Ambiguous(), Ambiguous(), &ip)), Ambiguous); |
| 665 | assert(remquo(0.5,1, &ip) == 0.5); |
| 666 | } |
| 667 | |
| 668 | void test_rint() { |
| 669 | ASSERT_SAME_TYPE(decltype(rintf(0)), float); |
| 670 | ASSERT_SAME_TYPE(decltype(rintl(0)), long double); |
| 671 | ASSERT_SAME_TYPE(decltype(rint(Ambiguous())), Ambiguous); |
| 672 | assert(rint(1) == 1); |
| 673 | } |
| 674 | |
| 675 | void test_round() { |
| 676 | ASSERT_SAME_TYPE(decltype(roundf(0)), float); |
| 677 | ASSERT_SAME_TYPE(decltype(roundl(0)), long double); |
| 678 | ASSERT_SAME_TYPE(decltype(round(Ambiguous())), Ambiguous); |
| 679 | assert(round(1) == 1); |
| 680 | } |
| 681 | |
| 682 | void test_scalbln() { |
| 683 | ASSERT_SAME_TYPE(decltype(scalbln((float)0, (long)0)), float); |
| 684 | ASSERT_SAME_TYPE(decltype(scalbln((bool)0, (long)0)), double); |
| 685 | ASSERT_SAME_TYPE(decltype(scalbln((unsigned short)0, (long)0)), double); |
| 686 | ASSERT_SAME_TYPE(decltype(scalbln((int)0, (long)0)), double); |
| 687 | ASSERT_SAME_TYPE(decltype(scalbln((unsigned int)0, (long)0)), double); |
| 688 | ASSERT_SAME_TYPE(decltype(scalbln((long)0, (long)0)), double); |
| 689 | ASSERT_SAME_TYPE(decltype(scalbln((unsigned long)0, (long)0)), double); |
| 690 | ASSERT_SAME_TYPE(decltype(scalbln((long long)0, (long)0)), double); |
| 691 | ASSERT_SAME_TYPE(decltype(scalbln((unsigned long long)0, (long)0)), double); |
| 692 | ASSERT_SAME_TYPE(decltype(scalbln((double)0, (long)0)), double); |
| 693 | ASSERT_SAME_TYPE(decltype(scalbln((long double)0, (long)0)), long double); |
| 694 | ASSERT_SAME_TYPE(decltype(scalblnf(0, (long)0)), float); |
| 695 | ASSERT_SAME_TYPE(decltype(scalblnl(0, (long)0)), long double); |
| 696 | ASSERT_SAME_TYPE(decltype(scalbln(Ambiguous(), Ambiguous())), Ambiguous); |
| 697 | assert(scalbln(1, 1) == 2); |
| 698 | } |
| 699 | |
| 700 | void test_scalbn() { |
| 701 | ASSERT_SAME_TYPE(decltype(scalbn((float)0, (int)0)), float); |
| 702 | ASSERT_SAME_TYPE(decltype(scalbn((bool)0, (int)0)), double); |
| 703 | ASSERT_SAME_TYPE(decltype(scalbn((unsigned short)0, (int)0)), double); |
| 704 | ASSERT_SAME_TYPE(decltype(scalbn((int)0, (int)0)), double); |
| 705 | ASSERT_SAME_TYPE(decltype(scalbn((unsigned int)0, (int)0)), double); |
| 706 | ASSERT_SAME_TYPE(decltype(scalbn((long)0, (int)0)), double); |
| 707 | ASSERT_SAME_TYPE(decltype(scalbn((unsigned long)0, (int)0)), double); |
| 708 | ASSERT_SAME_TYPE(decltype(scalbn((long long)0, (int)0)), double); |
| 709 | ASSERT_SAME_TYPE(decltype(scalbn((unsigned long long)0, (int)0)), double); |
| 710 | ASSERT_SAME_TYPE(decltype(scalbn((double)0, (int)0)), double); |
| 711 | ASSERT_SAME_TYPE(decltype(scalbn((long double)0, (int)0)), long double); |
| 712 | ASSERT_SAME_TYPE(decltype(scalbnf(0, (int)0)), float); |
| 713 | ASSERT_SAME_TYPE(decltype(scalbnl(0, (int)0)), long double); |
| 714 | ASSERT_SAME_TYPE(decltype(scalbn(Ambiguous(), Ambiguous())), Ambiguous); |
| 715 | assert(scalbn(1, 1) == 2); |
| 716 | } |
| 717 | |
| 718 | void test_tgamma() { |
| 719 | ASSERT_SAME_TYPE(decltype(tgammaf(0)), float); |
| 720 | ASSERT_SAME_TYPE(decltype(tgammal(0)), long double); |
| 721 | ASSERT_SAME_TYPE(decltype(tgamma(Ambiguous())), Ambiguous); |
| 722 | assert(tgamma(1) == 1); |
| 723 | } |
| 724 | |
| 725 | void test_trunc() { |
| 726 | ASSERT_SAME_TYPE(decltype(truncf(0)), float); |
| 727 | ASSERT_SAME_TYPE(decltype(truncl(0)), long double); |
| 728 | ASSERT_SAME_TYPE(decltype(trunc(Ambiguous())), Ambiguous); |
| 729 | assert(trunc(1) == 1); |
| 730 | } |
| 731 | |
| 732 | template <class PromoteResult, class Arg = void> |
| 733 | struct test_single_arg { |
| 734 | template <class T = Arg> |
| 735 | void operator()() { |
| 736 | ASSERT_SAME_TYPE(decltype(::acos(T())), PromoteResult); |
| 737 | (void)::acos(T()); |
| 738 | ASSERT_SAME_TYPE(decltype(::asin(T())), PromoteResult); |
| 739 | (void)::asin(T()); |
| 740 | ASSERT_SAME_TYPE(decltype(::atan(T())), PromoteResult); |
| 741 | (void)::atan(T()); |
| 742 | ASSERT_SAME_TYPE(decltype(::ceil(T())), PromoteResult); |
| 743 | (void)::ceil(T()); |
| 744 | ASSERT_SAME_TYPE(decltype(::cos(T())), PromoteResult); |
| 745 | (void)::cos(T()); |
| 746 | ASSERT_SAME_TYPE(decltype(::cosh(T())), PromoteResult); |
| 747 | (void)::cosh(T()); |
| 748 | ASSERT_SAME_TYPE(decltype(::exp(T())), PromoteResult); |
| 749 | (void)::exp(T()); |
| 750 | ASSERT_SAME_TYPE(decltype(::fabs(T())), PromoteResult); |
| 751 | (void)::fabs(T()); |
| 752 | ASSERT_SAME_TYPE(decltype(::floor(T())), PromoteResult); |
| 753 | (void)::floor(T()); |
| 754 | int ip; |
| 755 | ASSERT_SAME_TYPE(decltype(::frexp(T(), &ip)), PromoteResult); |
| 756 | (void)::frexp(T(), &ip); |
| 757 | ASSERT_SAME_TYPE(decltype(::ldexp(T(), ip)), PromoteResult); |
| 758 | (void)::ldexp(T(), ip); |
| 759 | ASSERT_SAME_TYPE(decltype(::log(T())), PromoteResult); |
| 760 | (void)::log(T()); |
| 761 | ASSERT_SAME_TYPE(decltype(::log10(T())), PromoteResult); |
| 762 | (void)::log10(T()); |
| 763 | ASSERT_SAME_TYPE(decltype(::sin(T())), PromoteResult); |
| 764 | (void)::sin(T()); |
| 765 | ASSERT_SAME_TYPE(decltype(::sinh(T())), PromoteResult); |
| 766 | (void)::sinh(T()); |
| 767 | ASSERT_SAME_TYPE(decltype(::sqrt(T())), PromoteResult); |
| 768 | (void)::sqrt(T()); |
| 769 | ASSERT_SAME_TYPE(decltype(::tan(T())), PromoteResult); |
| 770 | (void)::tan(T()); |
| 771 | ASSERT_SAME_TYPE(decltype(::tanh(T())), PromoteResult); |
| 772 | (void)::tanh(T()); |
| 773 | ASSERT_SAME_TYPE(decltype(::signbit(T())), bool); |
| 774 | (void)::signbit(T()); |
| 775 | ASSERT_SAME_TYPE(decltype(::fpclassify(T())), int); |
| 776 | (void)::fpclassify(T()); |
| 777 | ASSERT_SAME_TYPE(decltype(::isfinite(T())), bool); |
| 778 | (void)::isfinite(T()); |
| 779 | ASSERT_SAME_TYPE(decltype(::isnormal(T())), bool); |
| 780 | (void)::isnormal(T()); |
| 781 | ASSERT_SAME_TYPE(decltype(::acosh(T())), PromoteResult); |
| 782 | (void)::acosh(T()); |
| 783 | ASSERT_SAME_TYPE(decltype(::asinh(T())), PromoteResult); |
| 784 | (void)::asinh(T()); |
| 785 | ASSERT_SAME_TYPE(decltype(::atanh(T())), PromoteResult); |
| 786 | (void)::atanh(T()); |
| 787 | ASSERT_SAME_TYPE(decltype(::cbrt(T())), PromoteResult); |
| 788 | (void)::cbrt(T()); |
| 789 | ASSERT_SAME_TYPE(decltype(::erf(T())), PromoteResult); |
| 790 | (void)::erf(T()); |
| 791 | ASSERT_SAME_TYPE(decltype(::erfc(T())), PromoteResult); |
| 792 | (void)::erfc(T()); |
| 793 | ASSERT_SAME_TYPE(decltype(::exp2(T())), PromoteResult); |
| 794 | (void)::exp2(T()); |
| 795 | ASSERT_SAME_TYPE(decltype(::expm1(T())), PromoteResult); |
| 796 | (void)::expm1(T()); |
| 797 | ASSERT_SAME_TYPE(decltype(::ilogb(T())), int); |
| 798 | (void)::ilogb(T()); |
| 799 | ASSERT_SAME_TYPE(decltype(::lgamma(T())), PromoteResult); |
| 800 | (void)::lgamma(T()); |
| 801 | ASSERT_SAME_TYPE(decltype(::llrint(T())), long long); |
| 802 | (void)::llrint(T()); |
| 803 | ASSERT_SAME_TYPE(decltype(::llround(T())), long long); |
| 804 | (void)::llround(T()); |
| 805 | ASSERT_SAME_TYPE(decltype(::log1p(T())), PromoteResult); |
| 806 | (void)::log1p(T()); |
| 807 | ASSERT_SAME_TYPE(decltype(::log2(T())), PromoteResult); |
| 808 | (void)::log2(T()); |
| 809 | ASSERT_SAME_TYPE(decltype(::logb(T())), PromoteResult); |
| 810 | (void)::logb(T()); |
| 811 | ASSERT_SAME_TYPE(decltype(::lrint(T())), long); |
| 812 | (void)::lrint(T()); |
| 813 | ASSERT_SAME_TYPE(decltype(::lround(T())), long); |
| 814 | (void)::lround(T()); |
| 815 | ASSERT_SAME_TYPE(decltype(::nearbyint(T())), PromoteResult); |
| 816 | (void)::nearbyint(T()); |
| 817 | ASSERT_SAME_TYPE(decltype(::rint(T())), PromoteResult); |
| 818 | (void)::rint(T()); |
| 819 | ASSERT_SAME_TYPE(decltype(::round(T())), PromoteResult); |
| 820 | (void)::round(T()); |
| 821 | ASSERT_SAME_TYPE(decltype(::trunc(T())), PromoteResult); |
| 822 | (void)::trunc(T()); |
| 823 | ASSERT_SAME_TYPE(decltype(::tgamma(T())), PromoteResult); |
| 824 | (void)::tgamma(T()); |
| 825 | } |
| 826 | }; |
| 827 | |
| 828 | template <class PromoteResult, class Arg1 = void, class Arg2 = void> |
| 829 | struct test_two_args { |
| 830 | template <class T = Arg1, class U = Arg2> |
| 831 | void operator()() { |
| 832 | ASSERT_SAME_TYPE(decltype(::atan2(T(), U())), PromoteResult); |
| 833 | (void)::atan2(T(), U()); |
| 834 | ASSERT_SAME_TYPE(decltype(::fmod(T(), U())), PromoteResult); |
| 835 | (void)::fmod(T(), U()); |
| 836 | ASSERT_SAME_TYPE(decltype(::pow(T(), U())), PromoteResult); |
| 837 | (void)::pow(T(), U()); |
| 838 | ASSERT_SAME_TYPE(decltype(::isgreater(T(), U())), bool); |
| 839 | (void)::isgreater(T(), U()); |
| 840 | ASSERT_SAME_TYPE(decltype(::isgreaterequal(T(), U())), bool); |
| 841 | (void)::isgreaterequal(T(), U()); |
| 842 | ASSERT_SAME_TYPE(decltype(::isless(T(), U())), bool); |
| 843 | (void)::isless(T(), U()); |
| 844 | ASSERT_SAME_TYPE(decltype(::islessequal(T(), U())), bool); |
| 845 | (void)::islessequal(T(), U()); |
| 846 | ASSERT_SAME_TYPE(decltype(::islessgreater(T(), U())), bool); |
| 847 | (void)::islessgreater(T(), U()); |
| 848 | ASSERT_SAME_TYPE(decltype(::isunordered(T(), U())), bool); |
| 849 | (void)::isunordered(T(), U()); |
| 850 | ASSERT_SAME_TYPE(decltype(::copysign(T(), U())), PromoteResult); |
| 851 | (void)::copysign(T(), U()); |
| 852 | ASSERT_SAME_TYPE(decltype(::fdim(T(), U())), PromoteResult); |
| 853 | (void)::fdim(T(), U()); |
| 854 | ASSERT_SAME_TYPE(decltype(::fmax(T(), U())), PromoteResult); |
| 855 | (void)::fmax(T(), U()); |
| 856 | ASSERT_SAME_TYPE(decltype(::fmin(T(), U())), PromoteResult); |
| 857 | (void)::fmin(T(), U()); |
| 858 | ASSERT_SAME_TYPE(decltype(::hypot(T(), U())), PromoteResult); |
| 859 | (void)::hypot(T(), U()); |
| 860 | ASSERT_SAME_TYPE(decltype(::nextafter(T(), U())), PromoteResult); |
| 861 | (void)::nextafter(T(), U()); |
| 862 | ASSERT_SAME_TYPE(decltype(::remainder(T(), U())), PromoteResult); |
| 863 | (void)::remainder(T(), U()); |
| 864 | int ip; |
| 865 | ASSERT_SAME_TYPE(decltype(::remquo(T(), U(), &ip)), PromoteResult); |
| 866 | ::remquo(T(), U(), &ip); |
| 867 | } |
| 868 | }; |
| 869 | |
| 870 | template <class PromoteResult, class Arg1 = void, class Arg2 = void, class Arg3 = void> |
| 871 | struct test_three_args { |
| 872 | template <class T = Arg1, class U = Arg2, class V = Arg3> |
| 873 | void operator()() { |
| 874 | ASSERT_SAME_TYPE(decltype(::fma(T(), U(), V())), PromoteResult); |
| 875 | (void)::fma(T(), U(), V()); |
| 876 | } |
| 877 | }; |
| 878 | |
| 879 | struct CallTwoArgs { |
| 880 | using integral_float_double = types::concatenate_t<types::integral_types, types::type_list<float, double> >; |
| 881 | |
| 882 | template <class Arg2> |
| 883 | void operator()() { |
| 884 | types::for_each(integral_float_double(), test_two_args</*PromoteResult=*/double, /*Iterate*/void, Arg2>()); |
| 885 | } |
| 886 | }; |
| 887 | |
| 888 | template <class T> |
| 889 | struct CallThreeArgs { |
| 890 | using integral_float_double = types::concatenate_t<types::integral_types, types::type_list<float, double> >; |
| 891 | |
| 892 | template <class Arg3> |
| 893 | struct Helper { |
| 894 | |
| 895 | template <class Arg2> |
| 896 | void operator()() { |
| 897 | types::for_each(integral_float_double(), test_three_args</*PromoteResult=*/double, /*Iterate*/void, Arg2, Arg3>()); |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | template <class Arg3> |
| 902 | void operator()() { |
| 903 | types::for_each(integral_float_double(), Helper<Arg3>()); |
| 904 | } |
| 905 | }; |
| 906 | |
| 907 | int main(int, char**) { |
| 908 | types::for_each(types::integral_types(), test_single_arg</*PromoteResult=*/double>()); |
| 909 | test_single_arg</*PromoteResult=*/float, /*Arg=*/float>(); |
| 910 | test_single_arg</*PromoteResult=*/double, /*Arg=*/double>(); |
| 911 | test_single_arg</*PromoteResult=*/long double, /*Arg=*/long double>(); |
| 912 | |
| 913 | types::for_each(types::integral_types(), CallTwoArgs()); |
| 914 | |
| 915 | types::for_each( |
| 916 | types::integral_types(), test_two_args</*PromoteResult=*/long double, /*Arg1=*/void, /*Arg2=*/long double>()); |
| 917 | |
| 918 | test_two_args</*PromoteResult=*/float, /*Args=*/float, float>(); |
| 919 | test_two_args</*PromoteResult=*/float, /*Args=*/double, double>(); |
| 920 | test_two_args</*PromoteResult=*/double, /*Args=*/float, double>(); |
| 921 | test_two_args</*PromoteResult=*/double, /*Args=*/double, double>(); |
| 922 | |
| 923 | types::for_each(types::integral_types(), CallThreeArgs<double>()); |
| 924 | types::for_each( |
| 925 | types::integral_types(), test_three_args</*PromoteResult=*/long double, /*Iterate*/ void, long double, double>()); |
| 926 | |
| 927 | test_three_args</*PromoteResult=*/float, /*Args=*/float, float, float>(); |
| 928 | test_three_args</*PromoteResult=*/double, /*Args=*/double, double, double>(); |
| 929 | test_three_args</*PromoteResult=*/long double, /*Args=*/long double, long double, long double>(); |
| 930 | |
| 931 | test_abs(); |
| 932 | test_acos(); |
| 933 | test_asin(); |
| 934 | test_atan(); |
| 935 | test_atan2(); |
| 936 | test_ceil(); |
| 937 | test_cos(); |
| 938 | test_cosh(); |
| 939 | test_exp(); |
| 940 | test_fabs(); |
| 941 | test_floor(); |
| 942 | test_fmod(); |
| 943 | test_frexp(); |
| 944 | test_ldexp(); |
| 945 | test_log(); |
| 946 | test_log10(); |
| 947 | test_modf(); |
| 948 | test_pow(); |
| 949 | test_sin(); |
| 950 | test_sinh(); |
| 951 | test_sqrt(); |
| 952 | test_tan(); |
| 953 | test_tanh(); |
| 954 | test_signbit(); |
| 955 | test_fpclassify(); |
| 956 | test_isfinite(); |
| 957 | test_isnormal(); |
| 958 | test_isgreater(); |
| 959 | test_isgreaterequal(); |
| 960 | test_isinf(); |
| 961 | test_isless(); |
| 962 | test_islessequal(); |
| 963 | test_islessgreater(); |
| 964 | test_isnan(); |
| 965 | test_isunordered(); |
| 966 | test_acosh(); |
| 967 | test_asinh(); |
| 968 | test_atanh(); |
| 969 | test_cbrt(); |
| 970 | test_copysign(); |
| 971 | test_erf(); |
| 972 | test_erfc(); |
| 973 | test_exp2(); |
| 974 | test_expm1(); |
| 975 | test_fdim(); |
| 976 | test_fma(); |
| 977 | test_fmax(); |
| 978 | test_fmin(); |
| 979 | test_hypot(); |
| 980 | test_ilogb(); |
| 981 | test_lgamma(); |
| 982 | test_llrint(); |
| 983 | test_llround(); |
| 984 | test_log1p(); |
| 985 | test_log2(); |
| 986 | test_logb(); |
| 987 | test_lrint(); |
| 988 | test_lround(); |
| 989 | test_nan(); |
| 990 | test_nearbyint(); |
| 991 | test_nextafter(); |
| 992 | test_nexttoward(); |
| 993 | test_remainder(); |
| 994 | test_remquo(); |
| 995 | test_rint(); |
| 996 | test_round(); |
| 997 | test_scalbln(); |
| 998 | test_scalbn(); |
| 999 | test_tgamma(); |
| 1000 | test_trunc(); |
| 1001 | |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |