TDLS 0.2.0
Tiny Device-callable Linear Solvers
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1#ifndef TDLS_CORE_MATH_HPP
2#define TDLS_CORE_MATH_HPP
3
4
5
13
14
15
16#include <cmath>
17
18#include <tdls/core/macros.hpp>
19
20
21
22namespace tdls {
23
24
25
26namespace detail {
27
40template<typename T>
41[[nodiscard]] TDLS_HOST_DEVICE TDLS_FORCEINLINE constexpr T abs(const T x) noexcept {
42#if defined(__has_builtin)
43#if __has_builtin(__builtin_is_constant_evaluated)
44 if (__builtin_is_constant_evaluated()) return x < T(0) ? -x : x;
45#endif
46#elif defined(_MSC_VER) && _MSC_VER >= 1925
47 if (__builtin_is_constant_evaluated()) return x < T(0) ? -x : x;
48#endif
49 return std::fabs(x);
50}
51
52} // namespace detail
53
54
55
56} // namespace tdls
57
58
59
60#endif // TDLS_CORE_MATH_HPP
Toolchain detection and portability macros.
#define TDLS_HOST_DEVICE
__host__ __device__ under CUDA, the equivalent attributes under HIP, empty elsewhere.
Definition macros.hpp:45
#define TDLS_FORCEINLINE
__forceinline__ under CUDA, the equivalent attribute under HIP (see TDLS_HOST_DEVICE for why),...
Definition macros.hpp:67
TDLS_HOST_DEVICE TDLS_FORCEINLINE constexpr T abs(const T x) noexcept
Absolute value usable in constant expressions.
Definition math.hpp:41