44 #ifndef KOKKOS_ARITHTRAITS_HPP
45 #define KOKKOS_ARITHTRAITS_HPP
53 #include <Kokkos_complex.hpp>
62 #include <math_constants.h>
67 #ifndef KOKKOS_FORCEINLINE_FUNCTION
69 # define KOKKOS_FORCEINLINE_FUNCTION inline __host__ __device__
71 # define KOKKOS_FORCEINLINE_FUNCTION
72 # endif // __CUDA_ARCH__
73 #endif // KOKKOS_FORCEINLINE_FUNCTION
85 template<
class IntType>
86 KOKKOS_FORCEINLINE_FUNCTION IntType
87 intPowImpl (
const IntType x,
const IntType y)
100 const IntType left = y - y_cur;
101 for (IntType k = 0; k < left; ++k) {
105 else if (y < y_cur) {
109 const IntType left = y_cur - y;
110 for (IntType k = 0; k < left; ++k) {
144 template<
class IntType>
145 KOKKOS_FORCEINLINE_FUNCTION IntType
146 intPowSigned (
const IntType x,
const IntType y)
160 return (y % 2 == 0) ? 1 : -1;
166 return intPowImpl<IntType> (x, y);
177 template<
class IntType>
178 KOKKOS_FORCEINLINE_FUNCTION IntType
179 intPowUnsigned (
const IntType x,
const IntType y)
189 return intPowImpl<IntType> (x, y);
368 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const T& x);
379 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const T& x);
382 static KOKKOS_FORCEINLINE_FUNCTION
mag_type abs (
const T& x);
385 static KOKKOS_FORCEINLINE_FUNCTION T
zero ();
388 static KOKKOS_FORCEINLINE_FUNCTION T
one ();
394 static KOKKOS_FORCEINLINE_FUNCTION T
min ();
397 static KOKKOS_FORCEINLINE_FUNCTION T
max ();
402 static KOKKOS_FORCEINLINE_FUNCTION
mag_type real (
const T& x);
407 static KOKKOS_FORCEINLINE_FUNCTION
mag_type imag (
const T&);
412 static KOKKOS_FORCEINLINE_FUNCTION T
conj (
const T&);
415 static KOKKOS_FORCEINLINE_FUNCTION T
pow (
const T& x,
const T& y);
428 static KOKKOS_FORCEINLINE_FUNCTION T
sqrt (
const T& x);
441 static KOKKOS_FORCEINLINE_FUNCTION T
log (
const T& x);
454 static KOKKOS_FORCEINLINE_FUNCTION T
log10 (
const T& x);
460 static KOKKOS_FORCEINLINE_FUNCTION T
nan ();
493 static const bool isComplex =
false;
494 static const bool isOrdinal =
false;
495 static const bool isComparable =
false;
506 static KOKKOS_FORCEINLINE_FUNCTION
mag_type eps ();
512 static KOKKOS_FORCEINLINE_FUNCTION
int base ();
518 static KOKKOS_FORCEINLINE_FUNCTION
int t ();
521 static KOKKOS_FORCEINLINE_FUNCTION
mag_type rnd ();
524 static KOKKOS_FORCEINLINE_FUNCTION
int emin ();
530 static KOKKOS_FORCEINLINE_FUNCTION
int emax ();
539 static KOKKOS_FORCEINLINE_FUNCTION T
conjugate (
const T& x);
544 static KOKKOS_FORCEINLINE_FUNCTION
bool isnaninf (
const T& x);
549 static std::string
name ();
552 static KOKKOS_FORCEINLINE_FUNCTION T
squareroot (
const T& x);
569 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const float x) {
571 return std::isinf (x);
576 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const float x) {
578 return std::isnan (x);
583 static KOKKOS_FORCEINLINE_FUNCTION
mag_type abs (
const float x) {
586 static KOKKOS_FORCEINLINE_FUNCTION
float zero () {
589 static KOKKOS_FORCEINLINE_FUNCTION
float one () {
592 static KOKKOS_FORCEINLINE_FUNCTION
float min () {
595 static KOKKOS_FORCEINLINE_FUNCTION
float max () {
598 static KOKKOS_FORCEINLINE_FUNCTION
mag_type real (
const float x) {
601 static KOKKOS_FORCEINLINE_FUNCTION
mag_type imag (
const float) {
604 static KOKKOS_FORCEINLINE_FUNCTION
float conj (
const float x) {
607 static KOKKOS_FORCEINLINE_FUNCTION
float pow (
const float x,
const float y) {
610 static KOKKOS_FORCEINLINE_FUNCTION
float sqrt (
const float x) {
613 static KOKKOS_FORCEINLINE_FUNCTION
float log (
const float x) {
616 static KOKKOS_FORCEINLINE_FUNCTION
float log10 (
const float x) {
629 static const bool isComplex =
false;
630 static const bool isOrdinal =
false;
631 static const bool isComparable =
true;
633 static KOKKOS_FORCEINLINE_FUNCTION
bool isnaninf (
const float x) {
639 static KOKKOS_FORCEINLINE_FUNCTION
float conjugate (
const float x) {
642 static std::string
name () {
645 static KOKKOS_FORCEINLINE_FUNCTION
float squareroot (
const float x) {
648 static KOKKOS_FORCEINLINE_FUNCTION
float nan () {
654 return strtof (
"NAN()", (
char**) NULL);
655 #endif // __CUDA_ARCH__
657 static KOKKOS_FORCEINLINE_FUNCTION
mag_type eps () {
663 static KOKKOS_FORCEINLINE_FUNCTION
int base () {
669 static KOKKOS_FORCEINLINE_FUNCTION
int t () {
672 static KOKKOS_FORCEINLINE_FUNCTION
mag_type rnd () {
675 static KOKKOS_FORCEINLINE_FUNCTION
int emin () {
681 static KOKKOS_FORCEINLINE_FUNCTION
int emax () {
692 template<
class RealFloatType>
693 class ArithTraits<std::complex<RealFloatType> > {
695 typedef ::Kokkos::complex<RealFloatType>
val_type;
704 static bool isInf (
const std::complex<RealFloatType>& x) {
705 #if defined(__CUDACC__) || defined(_CRAYC)
706 return isinf (
real (x)) || isinf (
imag (x));
708 return std::isinf (
real (x)) || std::isinf (
imag (x));
711 static bool isNan (
const std::complex<RealFloatType>& x) {
712 #if defined(__CUDACC__) || defined(_CRAYC)
713 return isnan (
real (x)) || isnan (
imag (x));
715 return std::isnan (
real (x)) || std::isnan (
imag (x));
718 static mag_type abs (
const std::complex<RealFloatType>& x) {
721 static std::complex<RealFloatType>
zero () {
724 static std::complex<RealFloatType>
one () {
727 static std::complex<RealFloatType>
min () {
730 static std::complex<RealFloatType>
max () {
733 static mag_type real (
const std::complex<RealFloatType>& x) {
734 return std::real (x);
736 static mag_type imag (
const std::complex<RealFloatType>& x) {
737 return std::imag (x);
739 static std::complex<RealFloatType>
conj (
const std::complex<RealFloatType>& x) {
740 return std::conj (x);
742 static std::complex<RealFloatType>
743 pow (
const std::complex<RealFloatType>& x,
const std::complex<RealFloatType>& y) {
747 }
else if (y ==
one () +
one ()) {
750 return std::pow (x, y);
753 static std::complex<RealFloatType>
sqrt (
const std::complex<RealFloatType>& x) {
754 return std::sqrt (x);
756 static std::complex<RealFloatType>
log (
const std::complex<RealFloatType>& x) {
759 static std::complex<RealFloatType>
log10 (
const std::complex<RealFloatType>& x) {
760 return std::log10 (x);
762 static std::complex<RealFloatType>
nan () {
764 return std::complex<RealFloatType> (mag_nan, mag_nan);
772 typedef std::complex<typename ArithTraits<mag_type>::halfPrecision>
halfPrecision;
773 typedef std::complex<typename ArithTraits<mag_type>::doublePrecision>
doublePrecision;
775 static const bool isComplex =
true;
776 static const bool isOrdinal =
false;
777 static const bool isComparable =
false;
779 static bool isnaninf (
const std::complex<RealFloatType>& x) {
785 static std::complex<RealFloatType>
conjugate (
const std::complex<RealFloatType>& x) {
788 static std::string
name () {
791 static std::complex<RealFloatType>
squareroot (
const std::complex<RealFloatType>& x) {
828 class ArithTraits<double> {
839 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
841 return std::isinf (x);
846 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
848 return std::isnan (x);
859 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
862 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
865 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
889 static KOKKOS_FORCEINLINE_FUNCTION
val_type nan () {
895 return strtod (
"NAN", (
char**) NULL);
896 #endif // __CUDA_ARCH__
909 #endif // __CUDA_ARCH__
910 static const bool isComplex =
false;
911 static const bool isOrdinal =
false;
912 static const bool isComparable =
true;
923 static std::string
name () {
929 static KOKKOS_FORCEINLINE_FUNCTION
mag_type eps () {
935 static KOKKOS_FORCEINLINE_FUNCTION
int base () {
941 static KOKKOS_FORCEINLINE_FUNCTION
int t () {
944 static KOKKOS_FORCEINLINE_FUNCTION
mag_type rnd () {
947 static KOKKOS_FORCEINLINE_FUNCTION
int emin () {
953 static KOKKOS_FORCEINLINE_FUNCTION
int emax () {
966 class ArithTraits<long double> {
978 #if defined(__CUDACC__) || defined(_CRAYC)
981 return std::isinf (x);
985 #if defined(__CUDACC__) || defined(_CRAYC)
988 return std::isnan (x);
1016 return ::pow (x, y);
1028 return strtold (
"NAN()", (
char**) NULL);
1031 return LDBL_EPSILON;
1041 static const bool isComplex =
false;
1042 static const bool isOrdinal =
false;
1043 static const bool isComparable =
true;
1054 static std::string
name () {
1055 return "long double";
1066 static int base () {
1073 return LDBL_MANT_DIG;
1078 static int emin () {
1079 return LDBL_MIN_EXP;
1084 static int emax () {
1085 return LDBL_MAX_EXP;
1096 typedef ::Kokkos::complex<float>
val_type;
1102 static const bool is_exact =
false;
1105 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1107 ArithTraits<mag_type>::isInf (x.imag ());
1109 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1111 ArithTraits<mag_type>::isNan (x.imag ());
1118 return val_type (ArithTraits<mag_type>::zero (), ArithTraits<mag_type>::zero ());
1120 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1121 return val_type (ArithTraits<mag_type>::one (), ArithTraits<mag_type>::zero ());
1123 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1124 return val_type (ArithTraits<mag_type>::min (), ArithTraits<mag_type>::min ());
1126 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1127 return val_type (ArithTraits<mag_type>::max (), ArithTraits<mag_type>::max ());
1136 return ::Kokkos::conj (x);
1150 static KOKKOS_FORCEINLINE_FUNCTION
val_type nan () {
1152 return val_type (ArithTraits<mag_type>::nan (), ArithTraits<mag_type>::nan ());
1160 typedef ::Kokkos::complex<ArithTraits<mag_type>::halfPrecision>
halfPrecision;
1161 typedef ::Kokkos::complex<ArithTraits<mag_type>::doublePrecision>
doublePrecision;
1163 static const bool isComplex =
true;
1164 static const bool isOrdinal =
false;
1165 static const bool isComparable =
false;
1176 static std::string
name () {
1177 return "Kokkos::complex<float>";
1182 static KOKKOS_FORCEINLINE_FUNCTION
mag_type eps () {
1188 static KOKKOS_FORCEINLINE_FUNCTION
int base () {
1194 static KOKKOS_FORCEINLINE_FUNCTION
int t () {
1197 static KOKKOS_FORCEINLINE_FUNCTION
mag_type rnd () {
1200 static KOKKOS_FORCEINLINE_FUNCTION
int emin () {
1206 static KOKKOS_FORCEINLINE_FUNCTION
int emax () {
1218 typedef ::Kokkos::complex<double>
val_type;
1224 static const bool is_exact =
false;
1227 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1229 ArithTraits<mag_type>::isInf (x.imag ());
1231 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1233 ArithTraits<mag_type>::isNan (x.imag ());
1236 return ::Kokkos::abs (x);
1239 return val_type (ArithTraits<mag_type>::zero (), ArithTraits<mag_type>::zero ());
1241 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1242 return val_type (ArithTraits<mag_type>::one (), ArithTraits<mag_type>::zero ());
1244 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1245 return val_type (ArithTraits<mag_type>::min (), ArithTraits<mag_type>::min ());
1247 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1248 return val_type (ArithTraits<mag_type>::max (), ArithTraits<mag_type>::max ());
1257 return ::Kokkos::conj (x);
1271 static KOKKOS_FORCEINLINE_FUNCTION
val_type nan () {
1273 return val_type (ArithTraits<mag_type>::nan (), ArithTraits<mag_type>::nan ());
1281 typedef ::Kokkos::complex<ArithTraits<mag_type>::halfPrecision>
halfPrecision;
1282 typedef ::Kokkos::complex<ArithTraits<mag_type>::doublePrecision>
doublePrecision;
1284 static const bool isComplex =
true;
1285 static const bool isOrdinal =
false;
1286 static const bool isComparable =
false;
1297 static std::string
name () {
1298 return "Kokkos::complex<double>";
1303 static KOKKOS_FORCEINLINE_FUNCTION
mag_type eps () {
1309 static KOKKOS_FORCEINLINE_FUNCTION
int base () {
1315 static KOKKOS_FORCEINLINE_FUNCTION
int t () {
1318 static KOKKOS_FORCEINLINE_FUNCTION
mag_type rnd () {
1321 static KOKKOS_FORCEINLINE_FUNCTION
int emin () {
1327 static KOKKOS_FORCEINLINE_FUNCTION
int emax () {
1337 class ArithTraits<char> {
1347 static const bool is_signed = std::numeric_limits<char>::is_signed;
1352 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1355 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1362 return x >= 0 ? x : -x;
1367 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1370 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1373 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1385 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1388 return intPowSigned<val_type> (x, y);
1390 return intPowUnsigned<val_type> (x, y);
1429 static const bool isComplex =
false;
1430 static const bool isOrdinal =
true;
1431 static const bool isComparable =
true;
1442 static std::string
name () {
1452 class ArithTraits<signed char> {
1463 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1466 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1470 return x >= 0 ? x : -x;
1475 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1478 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1481 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1493 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1495 return intPowSigned<val_type> (x, y);
1515 static const bool isComplex =
false;
1516 static const bool isOrdinal =
true;
1517 static const bool isComparable =
true;
1528 static std::string
name () {
1529 return "signed char";
1538 class ArithTraits<unsigned char> {
1549 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1552 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1561 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1564 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1567 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1579 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1581 return intPowUnsigned<val_type> (x, y);
1591 return static_cast<val_type> (
::log (static_cast<float> (x)));
1605 static const bool isComplex =
false;
1606 static const bool isOrdinal =
true;
1607 static const bool isComparable =
true;
1618 static std::string
name () {
1619 return "unsigned char";
1628 class ArithTraits<short> {
1639 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1642 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1651 return x >= 0 ? x : -x;
1656 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1659 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1665 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1678 return intPowSigned<val_type> (x, y);
1702 static const bool isComplex =
false;
1703 static const bool isOrdinal =
true;
1704 static const bool isComparable =
true;
1715 static std::string
name () {
1725 class ArithTraits<unsigned short> {
1736 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1739 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1748 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1751 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1754 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1766 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1768 return intPowUnsigned<val_type> (x, y);
1777 return static_cast<val_type> (
::log (static_cast<float> (x)));
1791 static const bool isComplex =
false;
1792 static const bool isOrdinal =
true;
1793 static const bool isComparable =
true;
1804 static std::string
name () {
1805 return "unsigned short";
1814 class ArithTraits<int> {
1825 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1828 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1837 return x >= 0 ? x : -x;
1842 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1845 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1851 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1863 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1865 return intPowSigned<val_type> (x, y);
1888 static const bool isComplex =
false;
1889 static const bool isOrdinal =
true;
1890 static const bool isComparable =
true;
1901 static std::string
name () {
1911 class ArithTraits<unsigned int> {
1922 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
1925 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
1934 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
1937 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
1940 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
1952 static KOKKOS_FORCEINLINE_FUNCTION
val_type
1954 return intPowUnsigned<val_type> (x, y);
1960 return static_cast<val_type> (
::sqrt (static_cast<double> (x)));
1963 return static_cast<val_type> (
::log (static_cast<double> (x)));
1977 static const bool isComplex =
false;
1978 static const bool isOrdinal =
true;
1979 static const bool isComparable =
true;
1990 static std::string
name () {
1991 return "unsigned int";
2000 class ArithTraits<long> {
2011 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
2014 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
2018 return x >= 0 ? x : -x;
2023 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
2026 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
2029 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
2041 static KOKKOS_FORCEINLINE_FUNCTION
val_type
2043 return intPowSigned<val_type> (x, y);
2046 #ifdef __CUDA_ARCH__
2050 #endif // __CUDA_ARCH__
2067 static const bool isComplex =
false;
2068 static const bool isOrdinal =
true;
2069 static const bool isComparable =
true;
2080 static std::string
name () {
2090 class ArithTraits<unsigned long> {
2101 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
2104 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
2113 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
2116 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
2119 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
2132 return intPowUnsigned<val_type> (x, y);
2135 #ifdef __CUDA_ARCH__
2136 return static_cast<val_type> (
::sqrt (static_cast<double> (x)));
2138 return static_cast<val_type> (
::sqrt (static_cast<long double> (x)));
2139 #endif // __CUDA_ARCH__
2142 return static_cast<long> (
::log (static_cast<double> (x)));
2145 return static_cast<long> (
::log10 (static_cast<double> (x)));
2156 static const bool isComplex =
false;
2157 static const bool isOrdinal =
true;
2158 static const bool isComparable =
true;
2169 static std::string
name () {
2170 return "unsigned long";
2179 class ArithTraits<long long> {
2190 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
2193 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
2197 return x >= 0 ? x : -x;
2202 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
2205 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
2208 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
2220 static KOKKOS_FORCEINLINE_FUNCTION
val_type
2222 return intPowSigned<val_type> (x, y);
2225 #ifdef __CUDA_ARCH__
2243 #endif // __CUDA_ARCH__
2260 static const bool isComplex =
false;
2261 static const bool isOrdinal =
true;
2262 static const bool isComparable =
true;
2273 static std::string
name () {
2283 class ArithTraits<unsigned long long> {
2285 typedef unsigned long long val_type;
2294 static KOKKOS_FORCEINLINE_FUNCTION
bool isInf (
const val_type x) {
2297 static KOKKOS_FORCEINLINE_FUNCTION
bool isNan (
const val_type x) {
2306 static KOKKOS_FORCEINLINE_FUNCTION
val_type one () {
2309 static KOKKOS_FORCEINLINE_FUNCTION
val_type min () {
2312 static KOKKOS_FORCEINLINE_FUNCTION
val_type max () {
2324 static KOKKOS_FORCEINLINE_FUNCTION
val_type
2326 return intPowUnsigned<val_type> (x, y);
2329 #ifdef __CUDA_ARCH__
2330 return static_cast<val_type> (
::sqrt (static_cast<double> (x)));
2332 return static_cast<val_type> (
::sqrt (static_cast<long double> (x)));
2333 #endif // __CUDA_ARCH__
2336 return static_cast<val_type> (
::log (static_cast<double> (x)));
2350 static const bool isComplex =
false;
2351 static const bool isOrdinal =
true;
2352 static const bool isComparable =
true;
2363 static std::string
name () {
2364 return "unsigned long long";
2385 #ifdef HAVE_KOKKOS_QD
2387 struct ScalarTraits<dd_real>
2389 typedef dd_real val_type;
2390 typedef dd_real mag_type;
2392 static const bool is_specialized =
true;
2393 static const bool is_signed =
true;
2394 static const bool is_integer =
false;
2395 static const bool is_exact =
false;
2396 static const bool is_complex =
false;
2398 static inline bool isInf (
const val_type& x) {
2401 static inline bool isNan (
const val_type& x) {
2404 static inline mag_type
abs (
const val_type& x) {
2407 static inline val_type zero () {
2408 return val_type (0.0);
2410 static inline val_type one () {
2411 return val_type (1.0);
2413 static inline val_type min () {
2414 return std::numeric_limits<val_type>::min ();
2416 static inline val_type max () {
2417 return std::numeric_limits<val_type>::max ();
2419 static inline mag_type
real (
const val_type& x) {
2422 static inline mag_type
imag (
const val_type&) {
2425 static inline val_type
conj (
const val_type& x) {
2428 static inline val_type pow (
const val_type& x,
const val_type& y) {
2431 static inline val_type sqrt (
const val_type& x) {
2434 static inline val_type log (
const val_type& x) {
2438 static inline val_type log10 (
const val_type& x) {
2441 static inline val_type nan () {
2442 return val_type::_nan;
2444 static val_type epsilon () {
2445 return std::numeric_limits<val_type>::epsilon ();
2448 typedef dd_real magnitudeType;
2449 typedef double halfPrecision;
2450 typedef qd_real doublePrecision;
2452 static const bool isComplex =
false;
2453 static const bool isOrdinal =
false;
2454 static const bool isComparable =
true;
2455 static const bool hasMachineParameters =
true;
2457 static mag_type eps () {
2460 static mag_type sfmin () {
2463 static int base () {
2464 return std::numeric_limits<val_type>::radix;
2466 static mag_type prec () {
2467 return eps () * base ();
2470 return std::numeric_limits<val_type>::digits;
2472 static mag_type rnd () {
2473 return std::numeric_limits<val_type>::round_style == std::round_to_nearest ?
2477 static int emin () {
2478 return std::numeric_limits<val_type>::min_exponent;
2480 static mag_type rmin () {
2481 return std::numeric_limits<val_type>::min ();
2483 static int emax () {
2484 return std::numeric_limits<val_type>::max_exponent;
2486 static mag_type rmax () {
2487 return std::numeric_limits<val_type>::max ();
2489 static mag_type magnitude (
const val_type& x) {
2492 static val_type conjugate (
const val_type& x) {
2495 static bool isnaninf (
const val_type& x) {
2496 return isNan (x) || isInf (x);
2498 static std::string name () {
return "dd_real"; }
2499 static val_type squareroot (
const val_type& x) {
2506 struct ScalarTraits<qd_real>
2508 typedef qd_real val_type;
2509 typedef qd_real mag_type;
2511 static const bool is_specialized =
true;
2512 static const bool is_signed =
true;
2513 static const bool is_integer =
false;
2514 static const bool is_exact =
false;
2515 static const bool is_complex =
false;
2517 static inline bool isInf (
const val_type& x) {
2520 static inline bool isNan (
const val_type& x) {
2523 static inline mag_type
abs (
const val_type& x) {
2526 static inline val_type zero () {
2527 return val_type (0.0);
2529 static inline val_type one () {
2530 return val_type (1.0);
2532 static inline val_type min () {
2533 return std::numeric_limits<val_type>::min ();
2535 static inline val_type max () {
2536 return std::numeric_limits<val_type>::max ();
2538 static inline mag_type
real (
const val_type& x) {
2541 static inline mag_type
imag (
const val_type&) {
2544 static inline val_type
conj (
const val_type& x) {
2547 static inline val_type pow (
const val_type& x,
const val_type& y) {
2548 return ::pow (x, y);
2550 static inline val_type sqrt (
const val_type& x) {
2553 static inline val_type log (
const val_type& x) {
2557 static inline val_type log10 (
const val_type& x) {
2560 static inline val_type nan () {
2561 return val_type::_nan;
2563 static inline val_type epsilon () {
2564 return std::numeric_limits<val_type>::epsilon ();
2567 typedef qd_real magnitudeType;
2568 typedef dd_real halfPrecision;
2573 typedef qd_real doublePrecision;
2575 static const bool isComplex =
false;
2576 static const bool isOrdinal =
false;
2577 static const bool isComparable =
true;
2578 static const bool hasMachineParameters =
true;
2580 static mag_type eps () {
2583 static mag_type sfmin () {
2586 static int base () {
2587 return std::numeric_limits<val_type>::radix;
2589 static mag_type prec () {
2590 return eps () * base ();
2593 return std::numeric_limits<val_type>::digits;
2595 static mag_type rnd () {
2596 return std::numeric_limits<val_type>::round_style == std::round_to_nearest ?
2600 static int emin () {
2601 return std::numeric_limits<val_type>::min_exponent;
2603 static mag_type rmin () {
2604 return std::numeric_limits<val_type>::min ();
2606 static int emax () {
2607 return std::numeric_limits<val_type>::max_exponent;
2609 static mag_type rmax () {
2610 return std::numeric_limits<val_type>::max ();
2612 static mag_type magnitude (
const val_type& x) {
2615 static val_type conjugate (
const val_type& x) {
2618 static bool isnaninf (
const val_type& x) {
2619 return isNan (x) || isInf (x);
2621 static std::string name () {
return "qd_real"; }
2622 static val_type squareroot (
const val_type& x) {
2626 #endif // HAVE_KOKKOS_QD
2631 #endif // KOKKOS_ARITHTRAITS_HPP
static const bool is_integer
Whether T is an integer type.
T val_type
A type that acts like T and works with Kokkos.
static KOKKOS_FORCEINLINE_FUNCTION mag_type epsilon()
Machine epsilon.
static KOKKOS_FORCEINLINE_FUNCTION T sqrt(const T &x)
The square root of x.
static KOKKOS_FORCEINLINE_FUNCTION T nan()
Return a silent NaN, if appropriate for T.
static KOKKOS_FORCEINLINE_FUNCTION mag_type abs(const T &x)
The absolute value (magnitude) of x.
static KOKKOS_FORCEINLINE_FUNCTION T conj(const T &)
The complex conjugate of x.
static KOKKOS_FORCEINLINE_FUNCTION mag_type rmax()
Overflow theshold: (base^emax)*(1-eps)
static KOKKOS_FORCEINLINE_FUNCTION T one()
The one value of T; the multiplicative identity.
static KOKKOS_FORCEINLINE_FUNCTION T squareroot(const T &x)
Same as sqrt(x); the square root of x.
Partial reimplementation of std::complex that works as the result of a Kokkos::parallel_reduce.
static KOKKOS_FORCEINLINE_FUNCTION mag_type real(const T &x)
The real part of x.
static KOKKOS_FORCEINLINE_FUNCTION mag_type rnd()
1.0 when rounding occurs in addition, else 0.0.
static KOKKOS_FORCEINLINE_FUNCTION int base()
Return the base of the scalar type T.
static KOKKOS_FORCEINLINE_FUNCTION int emax()
Returns the largest exponent before overflow.
static KOKKOS_FORCEINLINE_FUNCTION T pow(const T &x, const T &y)
x raised to the power y.
KOKKOS_INLINE_FUNCTION RealType abs(const complex< RealType > &x)
Absolute value (magnitude) of a complex number.
static const bool hasMachineParameters
True if this type T has floating-point parameters.
static KOKKOS_FORCEINLINE_FUNCTION T zero()
The zero value of T; the arithmetic identity.
static KOKKOS_FORCEINLINE_FUNCTION T max()
The maximum possible value of T.
static std::string name()
The string name of T.
static const bool is_complex
Whether T is a complex-valued type.
static KOKKOS_FORCEINLINE_FUNCTION int emin()
Returns the minimum exponent before (gradual) underflow.
static KOKKOS_FORCEINLINE_FUNCTION bool isnaninf(const T &x)
Whether x is (silent) NaN or Inf.
KOKKOS_INLINE_FUNCTION RealType real(const complex< RealType > &x)
Real part of a complex number.
T doublePrecision
The type with "twice the the precision" of T.
static const bool is_specialized
Whether ArithTraits has a specialization for T.
static KOKKOS_FORCEINLINE_FUNCTION int t()
Returns the number of (base) digits in the significand.
static KOKKOS_FORCEINLINE_FUNCTION bool isInf(const T &x)
Whether x is Inf.
static KOKKOS_FORCEINLINE_FUNCTION bool isNan(const T &x)
Whether x is NaN (not a number).
static KOKKOS_FORCEINLINE_FUNCTION T log(const T &x)
The natural (base e) logarithm of x.
static KOKKOS_FORCEINLINE_FUNCTION mag_type prec()
Return eps*base.
static KOKKOS_FORCEINLINE_FUNCTION mag_type sfmin()
Return safe minimum (sfmin), such that 1/sfmin does not overflow.
KOKKOS_INLINE_FUNCTION complex< RealType > conj(const complex< RealType > &x)
Conjugate of a complex number.
static const bool is_signed
Whether T is a signed type (has negative values).
static KOKKOS_FORCEINLINE_FUNCTION T conjugate(const T &x)
Same as conj(); return the complex conjugate of x.
T halfPrecision
The type with "half the precision" of T.
static KOKKOS_FORCEINLINE_FUNCTION mag_type rmin()
Returns the underflow threshold: base^(emin-1)
static const bool is_exact
Whether T "uses exact representations.".
static KOKKOS_FORCEINLINE_FUNCTION T min()
The minimum possible value of T.
static KOKKOS_FORCEINLINE_FUNCTION T log10(const T &x)
The base ten logarithm of the input.
T mag_type
The type of the magnitude (absolute value) of T.
static KOKKOS_FORCEINLINE_FUNCTION mag_type imag(const T &)
The imaginary part of x.
static KOKKOS_FORCEINLINE_FUNCTION magnitudeType magnitude(const T &x)
Same as abs(); return the magnitude of x.
Traits class for arithmetic on type T.
static KOKKOS_FORCEINLINE_FUNCTION mag_type eps()
Return relative machine precision.
T magnitudeType
Same as mag_type; the type of the absolute value (magnitude) of T.
KOKKOS_INLINE_FUNCTION RealType imag(const complex< RealType > &x)
Imaginary part of a complex number.