Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
79 changes: 79 additions & 0 deletions include/math/abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
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
47 changes: 47 additions & 0 deletions include/math/acos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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) {
Copy link

@VinInn VinInn Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry This is utterly wrong! Did you check "assembly"?
please call ::acosf at least for cuda and hip.
said that I wish to remind that both cuda and hip support templated std::acos and produce correct code.

v.

return acos(arg);
}

XTD_DEVICE_FUNCTION
inline constexpr long double acosl(long double arg) {
return acos(arg);
}

template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
XTD_DEVICE_FUNCTION
inline constexpr double acos(T arg) {
return acos(static_cast<double>(arg));
}

} // namespace xtd
47 changes: 47 additions & 0 deletions include/math/acosh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
XTD_DEVICE_FUNCTION
inline constexpr double acosh(T arg) {
return acosh(static_cast<double>(arg));
}

} // namespace xtd
47 changes: 47 additions & 0 deletions include/math/asin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
XTD_DEVICE_FUNCTION
inline constexpr double asinf(T arg) {
return asin(static_cast<double>(arg));
}

} // namespace xtd
47 changes: 47 additions & 0 deletions include/math/asinh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
XTD_DEVICE_FUNCTION
inline constexpr double asinhf(T arg) {
return asinh(static_cast<double>(arg));
}

} // namespace xtd
47 changes: 47 additions & 0 deletions include/math/atan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once

#include "internal/defines.h"
#include <type_traits>

#if !defined(XTD_TARGET_CUDA) && !defined(XTD_TARGET_HIP) && !defined(XTD_TARGET_SYCL)
#include <cmath>
#endif

namespace xtd {

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
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 <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
XTD_DEVICE_FUNCTION
inline constexpr double atan(T arg) {
return atan(static_cast<double>(arg));
}

} // namespace xtd
Loading