From cb782ea48041ba68319c514c13b3e8b6e80eb3c3 Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Tue, 4 Mar 2025 14:24:16 +0100 Subject: [PATCH] Add most math functions from the standard library --- include/math.h | 31 ++++++++++++++++ include/math/abs.h | 79 ++++++++++++++++++++++++++++++++++++++++ include/math/acos.h | 47 ++++++++++++++++++++++++ include/math/acosh.h | 47 ++++++++++++++++++++++++ include/math/asin.h | 47 ++++++++++++++++++++++++ include/math/asinh.h | 47 ++++++++++++++++++++++++ include/math/atan.h | 47 ++++++++++++++++++++++++ include/math/atan2.h | 48 ++++++++++++++++++++++++ include/math/atanh.h | 47 ++++++++++++++++++++++++ include/math/cbrt.h | 42 +++++++++++++++++++++ include/math/ceil.h | 43 ++++++++++++++++++++++ include/math/cos.h | 47 ++++++++++++++++++++++++ include/math/cosh.h | 47 ++++++++++++++++++++++++ include/math/exp.h | 43 ++++++++++++++++++++++ include/math/exp2.h | 43 ++++++++++++++++++++++ include/math/expm1.h | 43 ++++++++++++++++++++++ include/math/floor.h | 43 ++++++++++++++++++++++ include/math/hypot.h | 38 +++++++++++++++++++ include/math/log.h | 43 ++++++++++++++++++++++ include/math/log10.h | 43 ++++++++++++++++++++++ include/math/log1p.h | 43 ++++++++++++++++++++++ include/math/log2.h | 43 ++++++++++++++++++++++ include/math/max.h | 46 +++++++++++++++++++++++ include/math/min.h | 46 +++++++++++++++++++++++ include/math/mod.h | 43 ++++++++++++++++++++++ include/math/pow.h | 38 +++++++++++++++++++ include/math/remainder.h | 43 ++++++++++++++++++++++ include/math/sin.h | 5 +++ include/math/sinh.h | 63 ++++++++++++++++++++++++++++++++ include/math/sqrt.h | 42 +++++++++++++++++++++ include/math/tan.h | 47 ++++++++++++++++++++++++ include/math/tanh.h | 48 ++++++++++++++++++++++++ include/math/trunc.h | 42 +++++++++++++++++++++ 33 files changed, 1464 insertions(+) create mode 100644 include/math/abs.h create mode 100644 include/math/acos.h create mode 100644 include/math/acosh.h create mode 100644 include/math/asin.h create mode 100644 include/math/asinh.h create mode 100644 include/math/atan.h create mode 100644 include/math/atan2.h create mode 100644 include/math/atanh.h create mode 100644 include/math/cbrt.h create mode 100644 include/math/ceil.h create mode 100644 include/math/cos.h create mode 100644 include/math/cosh.h create mode 100644 include/math/exp.h create mode 100644 include/math/exp2.h create mode 100644 include/math/expm1.h create mode 100644 include/math/floor.h create mode 100644 include/math/hypot.h create mode 100644 include/math/log.h create mode 100644 include/math/log10.h create mode 100644 include/math/log1p.h create mode 100644 include/math/log2.h create mode 100644 include/math/max.h create mode 100644 include/math/min.h create mode 100644 include/math/mod.h create mode 100644 include/math/pow.h create mode 100644 include/math/remainder.h create mode 100644 include/math/sinh.h create mode 100644 include/math/sqrt.h create mode 100644 include/math/tan.h create mode 100644 include/math/tanh.h create mode 100644 include/math/trunc.h diff --git a/include/math.h b/include/math.h index 1a0494a..89e558e 100644 --- a/include/math.h +++ b/include/math.h @@ -7,3 +7,34 @@ #pragma once #include "math/sin.h" +#include "math/cos.h" +#include "math/tan.h" +#include "math/asin.h" +#include "math/acos.h" +#include "math/atan.h" +#include "math/atan2.h" +#include "math/sinh.h" +#include "math/cosh.h" +#include "math/tanh.h" +#include "math/asinh.h" +#include "math/acosh.h" +#include "math/atanh.h" +#include "math/max.h" +#include "math/min.h" +#include "math/exp.h" +#include "math/exp2.h" +#include "math/expm1.h" +#include "math/log.h" +#include "math/log2.h" +#include "math/log10.h" +#include "math/log1p.h" +#include "math/pow.h" +#include "math/sqrt.h" +#include "math/cbrt.h" +#include "math/hypot.h" +#include "math/abs.h" +#include "math/mod.h" +#include "math/remainder.h" +#include "math/ceil.h" +#include "math/floor.h" +#include "math/trunc.h" diff --git a/include/math/abs.h b/include/math/abs.h new file mode 100644 index 0000000..93fb766 --- /dev/null +++ b/include/math/abs.h @@ -0,0 +1,79 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T abs(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::abs(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::abs(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::abs(x); +#else + // standard C++ code + return std::abs(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float fabsf(float x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::fabsf(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::fabsf(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::fabsf(x); +#else + // standard C++ code + return fabsf(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr long double fabsl(long double x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::fabsl(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::fabsl(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::fabsl(x); +#else + // standard C++ code + return fabsl(x); +#endif +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double fabs(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::fabs(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::fabs(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::fabs(x); +#else + // standard C++ code + return fabs(x); +#endif +} + +} // namespace xtd diff --git a/include/math/acos.h b/include/math/acos.h new file mode 100644 index 0000000..acd6bf3 --- /dev/null +++ b/include/math/acos.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr float acos(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::acos(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::acos(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::acos(arg); +#else + // standard C++ code + return std::acos(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float acosf(float arg) { + return acos(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double acosl(long double arg) { + return acos(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double acos(T arg) { + return acos(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/acosh.h b/include/math/acosh.h new file mode 100644 index 0000000..732a27c --- /dev/null +++ b/include/math/acosh.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr float acosh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::acosh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::acosh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::acosh(arg); +#else + // standard C++ code + return std::acosh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float acoshf(float arg) { + return acosh(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double acoshl(long double arg) { + return acosh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double acosh(T arg) { + return acosh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/asin.h b/include/math/asin.h new file mode 100644 index 0000000..4c64da7 --- /dev/null +++ b/include/math/asin.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T asin(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::asin(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::asin(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::asin(arg); +#else + // standard C++ code + return std::asin(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float asinf(float arg) { + return asin(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double asinl(long double arg) { + return asin(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double asinf(T arg) { + return asin(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/asinh.h b/include/math/asinh.h new file mode 100644 index 0000000..ebbc1f8 --- /dev/null +++ b/include/math/asinh.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T asinh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::asinh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::asinh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::asinh(arg); +#else + // standard C++ code + return std::asinh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float asinhf(float arg) { + return asinh(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double asinhl(long double arg) { + return asinh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double asinhf(T arg) { + return asinh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/atan.h b/include/math/atan.h new file mode 100644 index 0000000..bfa702b --- /dev/null +++ b/include/math/atan.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T atan(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::atan(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::atan(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::atan(arg); +#else + // standard C++ code + return std::atan(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float atanf(float arg) { + return atan(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double atanl(long double arg) { + return atan(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double atan(T arg) { + return atan(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/atan2.h b/include/math/atan2.h new file mode 100644 index 0000000..b0fbfff --- /dev/null +++ b/include/math/atan2.h @@ -0,0 +1,48 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T atan2(T x, T y) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::atan2(x, y); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::atan2(x, y); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::atan2(x, y); +#else + // standard C++ code + return std::atan2(x, y); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float atan2f(float x, float y) { + return atan2(x, y); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double atan2l(long double x, long double y) { + return atan2(x, y); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double atan2(T x, T y) { + return atan2(static_cast(x), static_cast(y)); + } + + +} // namespace xtd diff --git a/include/math/atanh.h b/include/math/atanh.h new file mode 100644 index 0000000..cfbc13f --- /dev/null +++ b/include/math/atanh.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T atanh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::atanh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::atanh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::atanh(arg); +#else + // standard C++ code + return std::atanh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float atanhf(float arg) { + return atanh(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double atanhl(long double arg) { + return atanh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double atanh(T arg) { + return atanh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/cbrt.h b/include/math/cbrt.h new file mode 100644 index 0000000..aac53e4 --- /dev/null +++ b/include/math/cbrt.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && \ + !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T cbrt(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::cbrt(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::cbrt(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::cbrt(x); +#else + // standard C++ code + return std::cbrt(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float cbrtf(float x) { return cbrt(x); } + +XTD_DEVICE_FUNCTION inline constexpr long double cbrtl(long double x) { + return cbrt(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double cbrt(T x) { + return cbrt(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/ceil.h b/include/math/ceil.h new file mode 100644 index 0000000..4dadd76 --- /dev/null +++ b/include/math/ceil.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T ceil(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::ceil(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::ceil(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::ceil(x); +#else + // standard C++ code + return std::ceil(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float ceilf(float x) { + return ceil(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double ceill(long double x) { + return ceil(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double ceil(T x) { + return ceil(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/cos.h b/include/math/cos.h new file mode 100644 index 0000000..0ce518c --- /dev/null +++ b/include/math/cos.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T cos(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::cos(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::cos(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::cos(arg); +#else + // standard C++ code + return std::cos(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float cosf(float arg) { + return cos(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double cosl(long double arg) { + return cos(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double cos(T arg) { + return cos(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/cosh.h b/include/math/cosh.h new file mode 100644 index 0000000..9945cfe --- /dev/null +++ b/include/math/cosh.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T cosh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::cosh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::cosh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::cosh(arg); +#else + // standard C++ code + return std::cosh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float coshf(float arg) { + return cosh(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double coshl(long double arg) { + return cosh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double cosh(T arg) { + return cosh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/exp.h b/include/math/exp.h new file mode 100644 index 0000000..038c06d --- /dev/null +++ b/include/math/exp.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T exp(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::exp(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::exp(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::exp(x); +#else + // standard C++ code + return std::exp(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float expf(float x) { + return exp(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double expl(long double x) { + return exp(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double exp(T x) { + return exp(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/exp2.h b/include/math/exp2.h new file mode 100644 index 0000000..3c70a31 --- /dev/null +++ b/include/math/exp2.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T exp2(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::exp2(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::exp2(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::exp2(x); +#else + // standard C++ code + return std::exp2(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float exp2f(float x) { + return exp2(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double exp2l(long double x) { + return exp2(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double exp2(T x) { + return exp2(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/expm1.h b/include/math/expm1.h new file mode 100644 index 0000000..8edeb90 --- /dev/null +++ b/include/math/expm1.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T expm1(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::expm1(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::expm1(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::expm1(x); +#else + // standard C++ code + return std::expm1(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float expm1f(float x) { + return expm1(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double expm1l(long double x) { + return expm1(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double expm1(T x) { + return expm1(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/floor.h b/include/math/floor.h new file mode 100644 index 0000000..7809626 --- /dev/null +++ b/include/math/floor.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T floor(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::floor(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::floor(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::floor(x); +#else + // standard C++ code + return std::floor(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float floorf(float x) { + return floor(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double floorl(long double x) { + return floor(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double floor(T x) { + return floor(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/hypot.h b/include/math/hypot.h new file mode 100644 index 0000000..ced491c --- /dev/null +++ b/include/math/hypot.h @@ -0,0 +1,38 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T hypot(T x, T y) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::hypot(x, y); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::hypot(x, y); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::hypot(x, y); +#else + // standard C++ code + return std::hypot(x, y); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float hypotf(float x, float y) { + return hypot(x, y); +} + +XTD_DEVICE_FUNCTION inline constexpr long double hypotl(long double x, long double y) { + return hypot(x, y); +} + +} // namespace xtd diff --git a/include/math/log.h b/include/math/log.h new file mode 100644 index 0000000..9f197a5 --- /dev/null +++ b/include/math/log.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T log(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::log(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::log(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::log(x); +#else + // standard C++ code + return std::log(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float logf(float x) { + return log(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double logl(long double x) { + return log(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double log(T x) { + return log(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/log10.h b/include/math/log10.h new file mode 100644 index 0000000..eca8cb9 --- /dev/null +++ b/include/math/log10.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T log10(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::log10(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::log10(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::log10(x); +#else + // standard C++ code + return std::log10(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float log10f(float x) { + return log10(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double log10l(long double x) { + return log10(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double log10(T x) { + return log10(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/log1p.h b/include/math/log1p.h new file mode 100644 index 0000000..0714030 --- /dev/null +++ b/include/math/log1p.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T log1p(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::log1p(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::log1p(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::log1p(x); +#else + // standard C++ code + return std::log1p(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float log1pf(float x) { + return std::log1p(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double log1pl(long double x) { + return std::log1p(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double log1p(T x) { + return log1p(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/log2.h b/include/math/log2.h new file mode 100644 index 0000000..1824c0b --- /dev/null +++ b/include/math/log2.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T log2(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::log2(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::log2(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::log2(x); +#else + // standard C++ code + return std::log2(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float log2f(float x) { + return log2(x); +} + +XTD_DEVICE_FUNCTION inline constexpr long double log2l(long double x) { + return log2(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double log2(T x) { + return log2(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/max.h b/include/math/max.h new file mode 100644 index 0000000..96e62a7 --- /dev/null +++ b/include/math/max.h @@ -0,0 +1,46 @@ + +#pragma once + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +#include "internal/defines.h" +#include + +namespace xtd { + +template XTD_DEVICE_FUNCTION inline constexpr const T& max(const T& a, const T& b) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::max(a, b); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::max(a, b); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::max(a, b); +#else + // standard C++ code + return std::max(a, b); +#endif +} + +template +XTD_DEVICE_FUNCTION inline constexpr const T& max(const T& a, const T& b, Compare comp) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::max(a, b, comp); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::max(a, b, comp); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::max(a, b, comp); +#else + // standard C++ code + return std::max(a, b, comp); +#endif +} + +} // namespace xtd diff --git a/include/math/min.h b/include/math/min.h new file mode 100644 index 0000000..d18744b --- /dev/null +++ b/include/math/min.h @@ -0,0 +1,46 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template XTD_DEVICE_FUNCTION inline constexpr const T& min(const T& a, const T& b) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::min(a, b); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::min(a, b); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::min(a, b); +#else + // standard C++ code + return std::min(a, b); +#endif +} + +template +XTD_DEVICE_FUNCTION inline constexpr const T& min(const T& a, const T& b, Compare comp) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::min(a, b, comp); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::min(a, b, comp); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::min(a, b, comp); +#else + // standard C++ code + return std::min(a, b, comp); +#endif +} + +} // namespace xtd diff --git a/include/math/mod.h b/include/math/mod.h new file mode 100644 index 0000000..e4c8477 --- /dev/null +++ b/include/math/mod.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T fmod(T x, T y) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::fmod(x, y); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::fmod(x, y); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::fmod(x, y); +#else + // standard C++ code + return std::fmod(x, y); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float fmodf(float x, float y) { + return fmodf(x, y); +} + +XTD_DEVICE_FUNCTION inline constexpr long double fmodl(long double x, long double y) { + return fmodl(x, y); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double fmod(T x, T y) { + return fmod(static_cast(x), static_cast(y)); +} + +} // namespace xtd diff --git a/include/math/pow.h b/include/math/pow.h new file mode 100644 index 0000000..4c9b1a0 --- /dev/null +++ b/include/math/pow.h @@ -0,0 +1,38 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T pow(T base, T exp) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::pow(base, exp); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::pow(base, exp); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::pow(base, exp); +#else + // standard C++ code + return std::pow(base, exp); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float powf(float base, float exp) { + return powf(base, exp); +} + +XTD_DEVICE_FUNCTION inline constexpr long double powl(long double base, long double exp) { + return powl(base, exp); +} + +} // namespace xtd diff --git a/include/math/remainder.h b/include/math/remainder.h new file mode 100644 index 0000000..960c818 --- /dev/null +++ b/include/math/remainder.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T remainder(T x, T y) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::remainder(x, y); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::remainder(x, y); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::remainder(x, y); +#else + // standard C++ code + return std::remainder(x, y); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float remainderf(float x, float y) { + return remainder(x, y); +} + +XTD_DEVICE_FUNCTION inline constexpr long double remainderl(long double x, long double y) { + return remainder(x, y); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double remainder(T x, T y) { + return remainder(static_cast(x), static_cast(y)); +} + +} // namespace xtd diff --git a/include/math/sin.h b/include/math/sin.h index 301969f..f2f447a 100644 --- a/include/math/sin.h +++ b/include/math/sin.h @@ -10,6 +10,11 @@ #include #include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif namespace xtd { diff --git a/include/math/sinh.h b/include/math/sinh.h new file mode 100644 index 0000000..4bc6c0d --- /dev/null +++ b/include/math/sinh.h @@ -0,0 +1,63 @@ +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T sinh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::sinh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::sinh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::sinh(arg); +#else + // standard C++ code + return std::sinh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr double sinh(double arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::sinh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::sinh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::sinh(arg); +#else + // standard C++ code + return std::sinh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float sinhf(float arg) { + return sinh(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double sinhl(long double arg) { + return sinh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double sinh(T arg) { + return sinh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/sqrt.h b/include/math/sqrt.h new file mode 100644 index 0000000..cb4088e --- /dev/null +++ b/include/math/sqrt.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && \ + !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T sqrt(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::sqrt(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::sqrt(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::sqrt(x); +#else + // standard C++ code + return std::sqrt(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float sqrtf(float x) { return sqrt(x); } + +XTD_DEVICE_FUNCTION inline constexpr long double sqrtl(long double x) { + return sqrt(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double sqrt(T x) { + return sqrt(static_cast(x)); +} + +} // namespace xtd diff --git a/include/math/tan.h b/include/math/tan.h new file mode 100644 index 0000000..088ad20 --- /dev/null +++ b/include/math/tan.h @@ -0,0 +1,47 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T tan(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::tan(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::tan(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::tan(arg); +#else + // standard C++ code + return std::tan(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float tanf(float arg) { + return tan(arg); + } + + XTD_DEVICE_FUNCTION + inline constexpr long double tanl(long double arg) { + return tan(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double tan(T arg) { + return tan(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/tanh.h b/include/math/tanh.h new file mode 100644 index 0000000..52ef56c --- /dev/null +++ b/include/math/tanh.h @@ -0,0 +1,48 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + + template >> + XTD_DEVICE_FUNCTION + inline constexpr T tanh(T arg) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::tanh(arg); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::tanh(arg); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::tanh(arg); +#else + // stanhdard C++ code + return std::tanh(arg); +#endif + } + + XTD_DEVICE_FUNCTION + inline constexpr float tanhf(float arg) { + return tanh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr long double tanhl(long double arg) { + return tanh(arg); + } + + template >> + XTD_DEVICE_FUNCTION + inline constexpr double tanh(T arg) { + return tanh(static_cast(arg)); + } + +} // namespace xtd diff --git a/include/math/trunc.h b/include/math/trunc.h new file mode 100644 index 0000000..d717657 --- /dev/null +++ b/include/math/trunc.h @@ -0,0 +1,42 @@ + +#pragma once + +#include "internal/defines.h" +#include + +#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && \ + !defined(XTD_TARGET_SYCL) +#include +#endif + +namespace xtd { + +template >> +XTD_DEVICE_FUNCTION inline constexpr T trunc(T x) { +#if defined(XTD_TARGET_CUDA) + // CUDA device code + return ::trunc(x); +#elif defined(XTD_TARGET_HIP) + // HIP/ROCm device code + return ::trunc(x); +#elif defined(XTD_TARGET_SYCL) + // SYCL device code + return sycl::trunc(x); +#else + // standard C++ code + return std::trunc(x); +#endif +} + +XTD_DEVICE_FUNCTION inline constexpr float truncf(float x) { return trunc(x); } + +XTD_DEVICE_FUNCTION inline constexpr long double truncl(long double x) { + return trunc(x); +} + +template >> +XTD_DEVICE_FUNCTION inline constexpr double trunc(T x) { + return trunc(static_cast(x)); +} + +} // namespace xtd