Clutter Engine 0.0.1
Loading...
Searching...
No Matches
ulp.inl
1
2
4
5namespace glm
6{
7 template<>
8 GLM_FUNC_QUALIFIER float next_float(float x)
9 {
10# if GLM_HAS_CXX11_STL
11 return std::nextafter(x, std::numeric_limits<float>::max());
12# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
13 return detail::nextafterf(x, FLT_MAX);
14# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
15 return __builtin_nextafterf(x, FLT_MAX);
16# else
17 return nextafterf(x, FLT_MAX);
18# endif
19 }
20
21 template<>
22 GLM_FUNC_QUALIFIER double next_float(double x)
23 {
24# if GLM_HAS_CXX11_STL
25 return std::nextafter(x, std::numeric_limits<double>::max());
26# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
27 return detail::nextafter(x, std::numeric_limits<double>::max());
28# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
29 return __builtin_nextafter(x, DBL_MAX);
30# else
31 return nextafter(x, DBL_MAX);
32# endif
33 }
34
35 template<typename T>
36 GLM_FUNC_QUALIFIER T next_float(T x, int ULPs)
37 {
38 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'next_float' only accept floating-point input");
39 assert(ULPs >= 0);
40
41 T temp = x;
42 for (int i = 0; i < ULPs; ++i)
43 temp = next_float(temp);
44 return temp;
45 }
46
47 GLM_FUNC_QUALIFIER float prev_float(float x)
48 {
49# if GLM_HAS_CXX11_STL
50 return std::nextafter(x, std::numeric_limits<float>::min());
51# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
52 return detail::nextafterf(x, FLT_MIN);
53# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
54 return __builtin_nextafterf(x, FLT_MIN);
55# else
56 return nextafterf(x, FLT_MIN);
57# endif
58 }
59
60 GLM_FUNC_QUALIFIER double prev_float(double x)
61 {
62# if GLM_HAS_CXX11_STL
63 return std::nextafter(x, std::numeric_limits<double>::min());
64# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS)))
65 return _nextafter(x, DBL_MIN);
66# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
67 return __builtin_nextafter(x, DBL_MIN);
68# else
69 return nextafter(x, DBL_MIN);
70# endif
71 }
72
73 template<typename T>
74 GLM_FUNC_QUALIFIER T prev_float(T x, int ULPs)
75 {
76 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'prev_float' only accept floating-point input");
77 assert(ULPs >= 0);
78
79 T temp = x;
80 for (int i = 0; i < ULPs; ++i)
81 temp = prev_float(temp);
82 return temp;
83 }
84
85 GLM_FUNC_QUALIFIER int float_distance(float x, float y)
86 {
87 detail::float_t<float> const a(x);
88 detail::float_t<float> const b(y);
89
90 return abs(a.i - b.i);
91 }
92
93 GLM_FUNC_QUALIFIER int64 float_distance(double x, double y)
94 {
95 detail::float_t<double> const a(x);
96 detail::float_t<double> const b(y);
97
98 return abs(a.i - b.i);
99 }
100
101 template<length_t L, typename T, qualifier Q>
102 GLM_FUNC_QUALIFIER vec<L, T, Q> next_float(vec<L, T, Q> const& x)
103 {
104 vec<L, T, Q> Result;
105 for (length_t i = 0, n = Result.length(); i < n; ++i)
106 Result[i] = next_float(x[i]);
107 return Result;
108 }
109
110 template<length_t L, typename T, qualifier Q>
111 GLM_FUNC_QUALIFIER vec<L, T, Q> next_float(vec<L, T, Q> const& x, int ULPs)
112 {
113 vec<L, T, Q> Result;
114 for (length_t i = 0, n = Result.length(); i < n; ++i)
115 Result[i] = next_float(x[i], ULPs);
116 return Result;
117 }
118
119 template<length_t L, typename T, qualifier Q>
120 GLM_FUNC_QUALIFIER vec<L, T, Q> next_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs)
121 {
122 vec<L, T, Q> Result;
123 for (length_t i = 0, n = Result.length(); i < n; ++i)
124 Result[i] = next_float(x[i], ULPs[i]);
125 return Result;
126 }
127
128 template<length_t L, typename T, qualifier Q>
129 GLM_FUNC_QUALIFIER vec<L, T, Q> prev_float(vec<L, T, Q> const& x)
130 {
131 vec<L, T, Q> Result;
132 for (length_t i = 0, n = Result.length(); i < n; ++i)
133 Result[i] = prev_float(x[i]);
134 return Result;
135 }
136
137 template<length_t L, typename T, qualifier Q>
138 GLM_FUNC_QUALIFIER vec<L, T, Q> prev_float(vec<L, T, Q> const& x, int ULPs)
139 {
140 vec<L, T, Q> Result;
141 for (length_t i = 0, n = Result.length(); i < n; ++i)
142 Result[i] = prev_float(x[i], ULPs);
143 return Result;
144 }
145
146 template<length_t L, typename T, qualifier Q>
147 GLM_FUNC_QUALIFIER vec<L, T, Q> prev_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs)
148 {
149 vec<L, T, Q> Result;
150 for (length_t i = 0, n = Result.length(); i < n; ++i)
151 Result[i] = prev_float(x[i], ULPs[i]);
152 return Result;
153 }
154
155 template<length_t L, qualifier Q>
156 GLM_FUNC_QUALIFIER vec<L, int, Q> float_distance(vec<L, float, Q> const& x, vec<L, float, Q> const& y)
157 {
158 vec<L, int, Q> Result;
159 for (length_t i = 0, n = Result.length(); i < n; ++i)
160 Result[i] = float_distance(x[i], y[i]);
161 return Result;
162 }
163
164 template<length_t L, qualifier Q>
165 GLM_FUNC_QUALIFIER vec<L, int64, Q> float_distance(vec<L, double, Q> const& x, vec<L, double, Q> const& y)
166 {
167 vec<L, int64, Q> Result;
168 for (length_t i = 0, n = Result.length(); i < n; ++i)
169 Result[i] = float_distance(x[i], y[i]);
170 return Result;
171 }
172}//namespace glm
173
GLM_FUNC_DECL GLM_CONSTEXPR genType abs(genType x)
detail::int64 int64
64 bit signed integer type.
Definition scalar_int_sized.hpp:67
Core features
Definition common.hpp:21
GLM_FUNC_DECL int float_distance(float x, float y)
Definition ulp.inl:85
GLM_FUNC_DECL genType next_float(genType x)
GLM_FUNC_DECL genType prev_float(genType x)
Definition qualifier.hpp:35
Definition type_float.hpp:15