-
Notifications
You must be signed in to change notification settings - Fork 2
Add most common math functions from standard library #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.