Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
cmath982 linesDownload Raw Back to include
1// -*- C++ -*-2//===---------------------------- cmath -----------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_CMATH11#define _LIBCUDACXX_CMATH12 13/*14    cmath synopsis15 16Macros:17 18    HUGE_VAL19    HUGE_VALF               // C9920    HUGE_VALL               // C9921    INFINITY                // C9922    NAN                     // C9923    FP_INFINITE             // C9924    FP_NAN                  // C9925    FP_NORMAL               // C9926    FP_SUBNORMAL            // C9927    FP_ZERO                 // C9928    FP_FAST_FMA             // C9929    FP_FAST_FMAF            // C9930    FP_FAST_FMAL            // C9931    FP_ILOGB0               // C9932    FP_ILOGBNAN             // C9933    MATH_ERRNO              // C9934    MATH_ERREXCEPT          // C9935    math_errhandling        // C9936 37namespace std38{39 40Types:41 42    float_t                 // C9943    double_t                // C9944 45// C9046 47floating_point abs(floating_point x);48 49floating_point acos (arithmetic x);50float          acosf(float x);51long double    acosl(long double x);52 53floating_point asin (arithmetic x);54float          asinf(float x);55long double    asinl(long double x);56 57floating_point atan (arithmetic x);58float          atanf(float x);59long double    atanl(long double x);60 61floating_point atan2 (arithmetic y, arithmetic x);62float          atan2f(float y, float x);63long double    atan2l(long double y, long double x);64 65floating_point ceil (arithmetic x);66float          ceilf(float x);67long double    ceill(long double x);68 69floating_point cos (arithmetic x);70float          cosf(float x);71long double    cosl(long double x);72 73floating_point cosh (arithmetic x);74float          coshf(float x);75long double    coshl(long double x);76 77floating_point exp (arithmetic x);78float          expf(float x);79long double    expl(long double x);80 81floating_point fabs (arithmetic x);82float          fabsf(float x);83long double    fabsl(long double x);84 85floating_point floor (arithmetic x);86float          floorf(float x);87long double    floorl(long double x);88 89floating_point fmod (arithmetic x, arithmetic y);90float          fmodf(float x, float y);91long double    fmodl(long double x, long double y);92 93floating_point frexp (arithmetic value, int* exp);94float          frexpf(float value, int* exp);95long double    frexpl(long double value, int* exp);96 97floating_point ldexp (arithmetic value, int exp);98float          ldexpf(float value, int exp);99long double    ldexpl(long double value, int exp);100 101floating_point log (arithmetic x);102float          logf(float x);103long double    logl(long double x);104 105floating_point log10 (arithmetic x);106float          log10f(float x);107long double    log10l(long double x);108 109floating_point modf (floating_point value, floating_point* iptr);110float          modff(float value, float* iptr);111long double    modfl(long double value, long double* iptr);112 113floating_point pow (arithmetic x, arithmetic y);114float          powf(float x, float y);115long double    powl(long double x, long double y);116 117floating_point sin (arithmetic x);118float          sinf(float x);119long double    sinl(long double x);120 121floating_point sinh (arithmetic x);122float          sinhf(float x);123long double    sinhl(long double x);124 125floating_point sqrt (arithmetic x);126float          sqrtf(float x);127long double    sqrtl(long double x);128 129floating_point tan (arithmetic x);130float          tanf(float x);131long double    tanl(long double x);132 133floating_point tanh (arithmetic x);134float          tanhf(float x);135long double    tanhl(long double x);136 137//  C99138 139bool signbit(arithmetic x);140 141int fpclassify(arithmetic x);142 143bool isfinite(arithmetic x);144bool isinf(arithmetic x);145bool isnan(arithmetic x);146bool isnormal(arithmetic x);147 148bool isgreater(arithmetic x, arithmetic y);149bool isgreaterequal(arithmetic x, arithmetic y);150bool isless(arithmetic x, arithmetic y);151bool islessequal(arithmetic x, arithmetic y);152bool islessgreater(arithmetic x, arithmetic y);153bool isunordered(arithmetic x, arithmetic y);154 155floating_point acosh (arithmetic x);156float          acoshf(float x);157long double    acoshl(long double x);158 159floating_point asinh (arithmetic x);160float          asinhf(float x);161long double    asinhl(long double x);162 163floating_point atanh (arithmetic x);164float          atanhf(float x);165long double    atanhl(long double x);166 167floating_point cbrt (arithmetic x);168float          cbrtf(float x);169long double    cbrtl(long double x);170 171floating_point copysign (arithmetic x, arithmetic y);172float          copysignf(float x, float y);173long double    copysignl(long double x, long double y);174 175floating_point erf (arithmetic x);176float          erff(float x);177long double    erfl(long double x);178 179floating_point erfc (arithmetic x);180float          erfcf(float x);181long double    erfcl(long double x);182 183floating_point exp2 (arithmetic x);184float          exp2f(float x);185long double    exp2l(long double x);186 187floating_point expm1 (arithmetic x);188float          expm1f(float x);189long double    expm1l(long double x);190 191floating_point fdim (arithmetic x, arithmetic y);192float          fdimf(float x, float y);193long double    fdiml(long double x, long double y);194 195floating_point fma (arithmetic x, arithmetic y, arithmetic z);196float          fmaf(float x, float y, float z);197long double    fmal(long double x, long double y, long double z);198 199floating_point fmax (arithmetic x, arithmetic y);200float          fmaxf(float x, float y);201long double    fmaxl(long double x, long double y);202 203floating_point fmin (arithmetic x, arithmetic y);204float          fminf(float x, float y);205long double    fminl(long double x, long double y);206 207floating_point hypot (arithmetic x, arithmetic y);208float          hypotf(float x, float y);209long double    hypotl(long double x, long double y);210 211double       hypot(double x, double y, double z);                // C++17212float        hypot(float x, float y, float z);                   // C++17213long double  hypot(long double x, long double y, long double z); // C++17214 215int ilogb (arithmetic x);216int ilogbf(float x);217int ilogbl(long double x);218 219floating_point lgamma (arithmetic x);220float          lgammaf(float x);221long double    lgammal(long double x);222 223long long llrint (arithmetic x);224long long llrintf(float x);225long long llrintl(long double x);226 227long long llround (arithmetic x);228long long llroundf(float x);229long long llroundl(long double x);230 231floating_point log1p (arithmetic x);232float          log1pf(float x);233long double    log1pl(long double x);234 235floating_point log2 (arithmetic x);236float          log2f(float x);237long double    log2l(long double x);238 239floating_point logb (arithmetic x);240float          logbf(float x);241long double    logbl(long double x);242 243long lrint (arithmetic x);244long lrintf(float x);245long lrintl(long double x);246 247long lround (arithmetic x);248long lroundf(float x);249long lroundl(long double x);250 251double      nan (const char* str);252float       nanf(const char* str);253long double nanl(const char* str);254 255floating_point nearbyint (arithmetic x);256float          nearbyintf(float x);257long double    nearbyintl(long double x);258 259floating_point nextafter (arithmetic x, arithmetic y);260float          nextafterf(float x, float y);261long double    nextafterl(long double x, long double y);262 263floating_point nexttoward (arithmetic x, long double y);264float          nexttowardf(float x, long double y);265long double    nexttowardl(long double x, long double y);266 267floating_point remainder (arithmetic x, arithmetic y);268float          remainderf(float x, float y);269long double    remainderl(long double x, long double y);270 271floating_point remquo (arithmetic x, arithmetic y, int* pquo);272float          remquof(float x, float y, int* pquo);273long double    remquol(long double x, long double y, int* pquo);274 275floating_point rint (arithmetic x);276float          rintf(float x);277long double    rintl(long double x);278 279floating_point round (arithmetic x);280float          roundf(float x);281long double    roundl(long double x);282 283floating_point scalbln (arithmetic x, long ex);284float          scalblnf(float x, long ex);285long double    scalblnl(long double x, long ex);286 287floating_point scalbn (arithmetic x, int ex);288float          scalbnf(float x, int ex);289long double    scalbnl(long double x, int ex);290 291floating_point tgamma (arithmetic x);292float          tgammaf(float x);293long double    tgammal(long double x);294 295floating_point trunc (arithmetic x);296float          truncf(float x);297long double    truncl(long double x);298 299}  // std300 301*/302 303#ifndef __cuda_std__304#include <__config>305#endif // __cuda_std__306 307#if !defined(__CUDACC_RTC__) || !defined(__cuda_std__)308#include <math.h>309#endif310 311#if defined(__cuda_std__) && defined(_LIBCUDACXX_COMPILER_NVHPC)312#include <cmath>313#endif314 315#include "limits"316#include "type_traits"317#include "version"318 319#ifndef __cuda_std__320#include <__pragma_push>321#endif // __cuda_std__322 323#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)324#  pragma GCC system_header325#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)326#  pragma clang system_header327#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)328#  pragma system_header329#endif // no system header330 331#ifdef _LIBCUDACXX_COMPILER_NVRTC332#include "climits"333#define INFINITY __builtin_huge_val()334#define NAN      __builtin_nan()335#endif336 337_LIBCUDACXX_BEGIN_NAMESPACE_STD338 339using ::signbit;340using ::isfinite;341using ::isinf;342using ::isnan;343 344using ::acos;345using ::acosf;346using ::asin;347using ::asinf;348using ::atan;349using ::atanf;350using ::atan2;351using ::atan2f;352using ::ceil;353using ::ceilf;354using ::cos;355using ::cosf;356using ::cosh;357using ::coshf;358 359using ::exp;360using ::expf;361 362using ::pow;363using ::powf;364 365using ::sin;366using ::sinf;367using ::sinh;368using ::sinhf;369 370using ::sqrt;371using ::sqrtf;372using ::tan;373using ::tanf;374 375using ::tanh;376using ::tanhf;377 378using ::acosh;379using ::acoshf;380using ::asinh;381using ::asinhf;382using ::atanh;383using ::atanhf;384 385using ::log;386using ::logf;387 388using ::hypot;389using ::hypotf;390 391#ifndef _AIX392using ::abs;393#endif394 395#ifndef _LIBCUDACXX_COMPILER_NVRTC396 397using ::fpclassify;398using ::isnormal;399using ::isgreater;400using ::isgreaterequal;401using ::isless;402using ::islessequal;403using ::islessgreater;404 405using ::isunordered;406 407using ::float_t;408using ::double_t;409 410using ::fabs;411using ::fabsf;412using ::floor;413using ::floorf;414 415using ::fmod;416using ::fmodf;417 418using ::frexp;419using ::frexpf;420using ::ldexp;421using ::ldexpf;422 423using ::log;424using ::logf;425 426using ::log10;427using ::log10f;428using ::modf;429using ::modff;430 431using ::pow;432using ::powf;433 434using ::sin;435using ::sinf;436using ::sinh;437using ::sinhf;438 439using ::sqrt;440using ::sqrtf;441using ::tan;442using ::tanf;443 444using ::tanh;445using ::tanhf;446 447using ::acosh;448using ::acoshf;449using ::asinh;450using ::asinhf;451using ::atanh;452using ::atanhf;453using ::cbrt;454using ::cbrtf;455 456using ::copysign;457using ::copysignf;458 459using ::erf;460using ::erff;461using ::erfc;462using ::erfcf;463using ::exp2;464using ::exp2f;465using ::expm1;466using ::expm1f;467using ::fdim;468using ::fdimf;469using ::fmaf;470using ::fma;471using ::fmax;472using ::fmaxf;473using ::fmin;474using ::fminf;475using ::ilogb;476using ::ilogbf;477using ::lgamma;478using ::lgammaf;479using ::llrint;480using ::llrintf;481using ::llround;482using ::llroundf;483using ::log1p;484using ::log1pf;485using ::log2;486using ::log2f;487using ::logb;488using ::logbf;489using ::lrint;490using ::lrintf;491using ::lround;492using ::lroundf;493 494using ::nan;495using ::nanf;496 497using ::nearbyint;498using ::nearbyintf;499using ::nextafter;500using ::nextafterf;501using ::nexttoward;502using ::nexttowardf;503using ::remainder;504using ::remainderf;505using ::remquo;506using ::remquof;507using ::rint;508using ::rintf;509using ::round;510using ::roundf;511using ::scalbln;512using ::scalblnf;513using ::scalbn;514using ::scalbnf;515using ::tgamma;516using ::tgammaf;517using ::trunc;518using ::truncf;519 520using ::acosl;521using ::asinl;522using ::atanl;523using ::atan2l;524using ::ceill;525using ::cosl;526using ::coshl;527using ::expl;528using ::fabsl;529using ::floorl;530using ::fmodl;531using ::frexpl;532using ::ldexpl;533using ::logl;534using ::log10l;535using ::modfl;536using ::powl;537using ::sinl;538using ::sinhl;539using ::sqrtl;540using ::tanl;541 542using ::tanhl;543using ::acoshl;544using ::asinhl;545using ::atanhl;546using ::cbrtl;547 548using ::copysignl;549 550using ::erfl;551using ::erfcl;552using ::exp2l;553using ::expm1l;554using ::fdiml;555using ::fmal;556using ::fmaxl;557using ::fminl;558using ::hypotl;559using ::ilogbl;560using ::lgammal;561using ::llrintl;562using ::llroundl;563using ::log1pl;564using ::log2l;565using ::logbl;566using ::lrintl;567using ::lroundl;568using ::nanl;569using ::nearbyintl;570using ::nextafterl;571using ::nexttowardl;572using ::remainderl;573using ::remquol;574using ::rintl;575using ::roundl;576using ::scalblnl;577using ::scalbnl;578using ::tgammal;579using ::truncl;580 581#endif // _LIBCUDACXX_COMPILER_NVRTC582 583#if _LIBCUDACXX_STD_VER > 14 && !defined(__cuda_std__)584inline _LIBCUDACXX_INLINE_VISIBILITY float       hypot(       float x,       float y,       float z ) { return sqrt(x*x + y*y + z*z); }585inline _LIBCUDACXX_INLINE_VISIBILITY double      hypot(      double x,      double y,      double z ) { return sqrt(x*x + y*y + z*z); }586#ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE587inline _LIBCUDACXX_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }588#endif589 590template <class _A1, class _A2, class _A3>591inline _LIBCUDACXX_INLINE_VISIBILITY592__enable_if_t593<594    is_arithmetic<_A1>::value &&595    is_arithmetic<_A2>::value &&596    is_arithmetic<_A3>::value,597    __promote<_A1, _A2, _A3>598>599hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) noexcept600{601    typedef typename __promote<_A1, _A2, _A3>::type __result_type;602    static_assert((!(is_same<_A1, __result_type>::value &&603                     is_same<_A2, __result_type>::value &&604                     is_same<_A3, __result_type>::value)), "");605    return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);606}607#endif608 609#ifndef _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS610#define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX _LIBCUDACXX_CONSTEXPR_AFTER_CXX11611#else612#define _LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX613#endif // _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS614 615template <class _A1>616_LIBCUDACXX_INLINE_VISIBILITY617constexpr __enable_if_t<is_floating_point<_A1>::value, bool>618__constexpr_isnan(_A1 __lcpp_x) noexcept619{620#if defined(_LIBCUDACXX_CUDACC_BELOW_11_8)621    return __isnan(__lcpp_x);622#elif __has_builtin(__builtin_isnan)623    return __builtin_isnan(__lcpp_x);624#else625    return isnan(__lcpp_x);626#endif627}628 629template <class _A1>630_LIBCUDACXX_INLINE_VISIBILITY631constexpr __enable_if_t<!is_floating_point<_A1>::value, bool>632__constexpr_isnan(_A1 __lcpp_x) noexcept633{634    return isnan(__lcpp_x);635}636 637template <class _A1>638_LIBCUDACXX_INLINE_VISIBILITY639constexpr __enable_if_t<is_floating_point<_A1>::value, bool>640__constexpr_isinf(_A1 __lcpp_x) noexcept641{642#if defined(_LIBCUDACXX_CUDACC_BELOW_11_8)643    return __isinf(__lcpp_x);644#elif __has_builtin(__builtin_isinf)645    return __builtin_isinf(__lcpp_x);646#else647    return isinf(__lcpp_x);648#endif649}650 651template <class _A1>652_LIBCUDACXX_INLINE_VISIBILITY653constexpr __enable_if_t<!is_floating_point<_A1>::value, bool>654__constexpr_isinf(_A1 __lcpp_x) noexcept655{656    return isinf(__lcpp_x);657}658 659template <class _A1>660_LIBCUDACXX_INLINE_VISIBILITY661constexpr __enable_if_t<is_floating_point<_A1>::value, bool>662__constexpr_isfinite(_A1 __lcpp_x) noexcept663{664#if defined(_LIBCUDACXX_CUDACC_BELOW_11_8)665    return !__isinf(__lcpp_x) && !__isnan(__lcpp_x);666#elif __has_builtin(__builtin_isfinite)667    return __builtin_isfinite(__lcpp_x);668#else669    return isfinite(__lcpp_x);670#endif671}672 673template <class _A1>674_LIBCUDACXX_INLINE_VISIBILITY675constexpr __enable_if_t<!is_floating_point<_A1>::value, bool>676__constexpr_isfinite(_A1 __lcpp_x) noexcept677{678    return isfinite(__lcpp_x);679}680 681#if defined(_MSC_VER) || defined(__CUDACC_RTC__) || defined(_LIBCUDACXX_COMPILER_CLANG_CUDA)682template <class _A1>683_LIBCUDACXX_INLINE_VISIBILITY684_A1 __constexpr_copysign(_A1 __x, _A1 __y) noexcept685{686    return copysign(__x, __y);687}688#else689inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY690_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 float __constexpr_copysign(float __x, float __y) noexcept {691    return __builtin_copysignf(__x, __y);692}693 694inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY695_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 double __constexpr_copysign(double __x, double __y) noexcept {696    return __builtin_copysign(__x, __y);697}698 699inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY700_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 long double __constexpr_copysign(long double __x, long double __y) noexcept {701    return __builtin_copysignl(__x, __y);702}703 704template <class _A1, class _A2>705inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY706_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 typename __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value,707                                __promote<_A1, _A2> >::type708    __constexpr_copysign(_A1 __x, _A2 __y) noexcept {709    typedef typename __promote<_A1, _A2>::type __result_type;710    static_assert((!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value)), "");711    return __builtin_copysign((__result_type)__x, (__result_type)__y);712}713#endif // !_MSC_VER714 715#if defined(_MSC_VER) || defined(__CUDACC_RTC__) || defined(_LIBCUDACXX_COMPILER_CLANG_CUDA)716template <class _A1>717_LIBCUDACXX_INLINE_VISIBILITY718_A1 __constexpr_fabs(_A1 __x) noexcept719{720    return fabs(__x);721}722#else723inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY724_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 float __constexpr_fabs(float __x) noexcept {725    return __builtin_fabsf(__x);726}727 728inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY729_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 double __constexpr_fabs(double __x) noexcept {730    return __builtin_fabs(__x);731}732 733inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY734_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 long double __constexpr_fabs(long double __x) noexcept {735    return __builtin_fabsl(__x);736}737 738template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>739inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY740_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 double __constexpr_fabs(_Tp __x) noexcept {741    return __builtin_fabs(static_cast<double>(__x));742}743#endif // !_MSC_VER744 745#if defined(_MSC_VER) || defined(__CUDACC_RTC__) || defined(_LIBCUDACXX_COMPILER_CLANG_CUDA)746template <class _A1>747_LIBCUDACXX_INLINE_VISIBILITY748_A1 __constexpr_fmax(_A1 __x, _A1 __y) noexcept749{750    return fmax(__x, __y);751}752#else753inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY754_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX float __constexpr_fmax(float __x, float __y) noexcept {755#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS)756  if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) {757    if (__constexpr_isnan(__x))758      return __y;759    if (__constexpr_isnan(__y))760      return __x;761    return __x < __y ? __y : __x;762  }763#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED)764  return __builtin_fmaxf(__x, __y);765}766 767inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY768_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX double __constexpr_fmax(double __x, double __y) noexcept {769#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS)770  if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) {771    if (__constexpr_isnan(__x))772      return __y;773    if (__constexpr_isnan(__y))774      return __x;775    return __x < __y ? __y : __x;776  }777#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED)778  return __builtin_fmax(__x, __y);779}780 781inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY782_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX long double __constexpr_fmax(long double __x, long double __y) noexcept {783#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS)784  if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) {785    if (__constexpr_isnan(__x))786      return __y;787    if (__constexpr_isnan(__y))788      return __x;789    return __x < __y ? __y : __x;790  }791#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED)792  return __builtin_fmax(__x, __y);793}794 795template <class _Tp, class _Up, __enable_if_t<is_arithmetic<_Tp>::value && is_arithmetic<_Up>::value, int> = 0>796inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY797_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX typename __promote<_Tp, _Up>::type798__constexpr_fmax(_Tp __x, _Up __y) noexcept {799  using __result_type = typename __promote<_Tp, _Up>::type;800  return _CUDA_VSTD::__constexpr_fmax(static_cast<__result_type>(__x), static_cast<__result_type>(__y));801}802#endif // !_MSC_VER803 804#if defined(_MSC_VER) || defined(__CUDACC_RTC__) || defined(_LIBCUDACXX_COMPILER_CLANG_CUDA)805template <class _A1>806_LIBCUDACXX_INLINE_VISIBILITY807_A1 __constexpr_logb(_A1 __x)808{809    return logb(__x);810}811#else812template <class _Tp>813inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY814_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX _Tp __constexpr_logb(_Tp __x) {815#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS)816  if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) {817    if (__x == _Tp(0)) {818      // raise FE_DIVBYZERO819      return -numeric_limits<_Tp>::infinity();820    }821 822    if (__constexpr_isinf(__x))823      return numeric_limits<_Tp>::infinity();824 825    if (__constexpr_isnan(__x))826      return numeric_limits<_Tp>::quiet_NaN();827 828    __x = __constexpr_fabs(__x);829    unsigned long long __exp = 0;830    while (__x >= numeric_limits<_Tp>::radix) {831      __x /= numeric_limits<_Tp>::radix;832      __exp += 1;833    }834    return _Tp(__exp);835  }836#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED)837  return __builtin_logb(__x);838}839#endif // !_MSVC840 841#if defined(_MSC_VER) || defined(__CUDACC_RTC__) || defined(_LIBCUDACXX_COMPILER_CLANG_CUDA)842template <class _Tp>843inline _LIBCUDACXX_INLINE_VISIBILITY844_Tp __constexpr_scalbn(_Tp __x, int __i) {845    return static_cast<_Tp>(scalbn(static_cast<double>(__x), __i));846}847 848template <>849inline _LIBCUDACXX_INLINE_VISIBILITY850float __constexpr_scalbn<float>(float __x, int __i) {851    return scalbnf(__x, __i);852}853 854template <>855inline _LIBCUDACXX_INLINE_VISIBILITY856double __constexpr_scalbn<double>(double __x, int __i) {857    return scalbn(__x, __i);858}859 860#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE861template <>862inline _LIBCUDACXX_INLINE_VISIBILITY863long double __constexpr_scalbn<long double>(long double __x, int __i) {864    return scalbnl(__x, __i);865}866#endif // _LIBCUDACXX_HAS_NO_LONG_DOUBLE867#else868template <class _Tp>869inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY870_LIBCUDACXX_CONSTEXPR_AFTER_CXX11_COMPLEX _Tp __constexpr_scalbn(_Tp __x, int __exp) {871#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS)872 if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) {873    if (__x == _Tp(0))874      return __x;875 876    if (__constexpr_isinf(__x))877      return __x;878 879    if (__exp == _Tp(0))880      return __x;881 882    if (__constexpr_isnan(__x))883      return numeric_limits<_Tp>::quiet_NaN();884 885    _Tp __mult(1);886    if (__exp > 0) {887      __mult = numeric_limits<_Tp>::radix;888      --__exp;889    } else {890      ++__exp;891      __exp = -__exp;892      __mult /= numeric_limits<_Tp>::radix;893    }894 895    while (__exp > 0) {896      if (!(__exp & 1)) {897        __mult *= __mult;898        __exp >>= 1;899      } else {900        __x *= __mult;901        --__exp;902      }903    }904    return __x;905  }906#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED)907  return __builtin_scalbn(__x, __exp);908}909#endif // !_MSC_VER910 911#if _LIBCUDACXX_STD_VER > 17912template <typename _Fp>913_LIBCUDACXX_INLINE_VISIBILITY914constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {915    if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))916        return __t * __b + (1 - __t) * __a;917 918    if (__t == 1) return __b;919    const _Fp __x = __a + __t * (__b - __a);920    if (__t > 1 == __b > __a)921    	return __b < __x ? __x : __b;922    else923    	return __x < __b ? __x : __b;924}925 926_LIBCUDACXX_INLINE_VISIBILITY927constexpr float928lerp(float __a, float __b, float __t)                   noexcept { return __lerp(__a, __b, __t); }929 930_LIBCUDACXX_INLINE_VISIBILITY931constexpr double932lerp(double __a, double __b, double __t)                noexcept { return __lerp(__a, __b, __t); }933 934_LIBCUDACXX_INLINE_VISIBILITY935constexpr long double936lerp(long double __a, long double __b, long double __t) noexcept { return __lerp(__a, __b, __t); }937 938#endif // _LIBCUDACXX_STD_VER > 17939 940template <class _IntT, class _FloatT,941    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),942    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>943_LIBCUDACXX_INLINE_VISIBILITY944constexpr _IntT __max_representable_int_for_float() noexcept {945  static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");946  static_assert(is_integral<_IntT>::value, "must be an integral type");947  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");948#ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE949  static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value950                 || _IsSame<_FloatT,long double>::value), "unsupported floating point type");951#else952  static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value),953                 "unsupported floating point type");954#endif955  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);956}957 958// Convert a floating point number to the specified integral type after959// clamping to the integral types representable range.960//961// The behavior is undefined if `__r` is NaN.962template <class _IntT, class _RealT>963_LIBCUDACXX_INLINE_VISIBILITY964_IntT __clamp_to_integral(_RealT __r) noexcept {965  using _Lim = _CUDA_VSTD::numeric_limits<_IntT>;966  const _IntT _MaxVal = _CUDA_VSTD::__max_representable_int_for_float<_IntT, _RealT>();967  if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {968    return _Lim::max();969  } else if (__r <= _Lim::lowest()) {970    return _Lim::min();971  }972  return static_cast<_IntT>(__r);973}974 975_LIBCUDACXX_END_NAMESPACE_STD976 977#ifndef __cuda_std__978#include <__pragma_pop>979#endif // __cuda_std__980 981#endif  // _LIBCUDACXX_CMATH982 
codekingpro/portable-devtools · Team Ai