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