| 0.9.9 API documenation

compute_common.hpp
1 #pragma once
2
3 #include "setup.hpp"
4 #include <limits>
5
6 namespace glm{
7 namespace detail
8 {
9 template<typename genFIType, bool /*signed*/>
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 GLM_STATIC_ASSERT(
19 std::numeric_limits<genFIType>::is_iec559 || 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 // TODO, perf comp with: *(((int *) &x) + 1) &= 0x7fffffff;
24 }
25 };
26
27 #if GLM_COMPILER & GLM_COMPILER_CUDA
28 template<>
29 struct compute_abs<float, true>
30 {
31 GLM_FUNC_QUALIFIER GLM_CONSTEXPR 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 GLM_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 }//namespace detail
50 }//namespace glm
glm
Definition: common.hpp:20