| 1 | #pragma once |
| 2 | |
| 3 | #include "setup.hpp" |
| 4 | #include <limits> |
| 5 | |
| 6 | namespace glm{ |
| 7 | namespace detail |
| 8 | { |
| 9 | template<typename genFIType, bool > |
| 10 | struct compute_abs |
| 11 | {}; |
| 12 | |
| 13 | template<typename genFIType> |
| 14 | struct compute_abs<genFIType, true> |
| 15 | { |
| 16 | GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genFIType call(genFIType x) |
| 17 | { |
| 18 | static_assert( |
| 19 | std::numeric_limits<genFIType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT || std::numeric_limits<genFIType>::is_signed, |
| 20 | "'abs' only accept floating-point and integer scalar or vector inputs"); |
| 21 | |
| 22 | return x >= genFIType(0) ? x : -x; |
| 23 | |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | #if (GLM_COMPILER & GLM_COMPILER_CUDA) || (GLM_COMPILER & GLM_COMPILER_HIP) |
| 28 | template<> |
| 29 | struct compute_abs<float, true> |
| 30 | { |
| 31 | GLM_FUNC_QUALIFIER static float call(float x) |
| 32 | { |
| 33 | return fabsf(x); |
| 34 | } |
| 35 | }; |
| 36 | #endif |
| 37 | |
| 38 | template<typename genFIType> |
| 39 | struct compute_abs<genFIType, false> |
| 40 | { |
| 41 | GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genFIType call(genFIType x) |
| 42 | { |
| 43 | static_assert( |
| 44 | (!std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), |
| 45 | "'abs' only accept floating-point and integer scalar or vector inputs"); |
| 46 | return x; |
| 47 | } |
| 48 | }; |
| 49 | } |
| 50 | } |