1 #include <glm/ext/vector_ulp.hpp>
2 #include <glm/ext/vector_relational.hpp>
3 #include <glm/ext/vector_float4.hpp>
4 #include <glm/ext/vector_double4.hpp>
5 #include <glm/ext/vector_int4.hpp>
6
test_ulp_float_dist()7 static int test_ulp_float_dist()
8 {
9 int Error = 0;
10
11 glm::vec4 const A(1.0f);
12
13 glm::vec4 const B = glm::nextFloat(A);
14 Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
15 glm::vec4 const C = glm::prevFloat(B);
16 Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
17
18 glm::ivec4 const D = glm::floatDistance(A, B);
19 Error += D == glm::ivec4(1) ? 0 : 1;
20 glm::ivec4 const E = glm::floatDistance(A, C);
21 Error += E == glm::ivec4(0) ? 0 : 1;
22
23 return Error;
24 }
25
test_ulp_float_step()26 static int test_ulp_float_step()
27 {
28 int Error = 0;
29
30 glm::vec4 const A(1.0f);
31
32 for(int i = 10; i < 1000; i *= 10)
33 {
34 glm::vec4 const B = glm::nextFloat(A, i);
35 Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
36 glm::vec4 const C = glm::prevFloat(B, i);
37 Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
38
39 glm::ivec4 const D = glm::floatDistance(A, B);
40 Error += D == glm::ivec4(i) ? 0 : 1;
41 glm::ivec4 const E = glm::floatDistance(A, C);
42 Error += E == glm::ivec4(0) ? 0 : 1;
43 }
44
45 return Error;
46 }
47
test_ulp_double_dist()48 static int test_ulp_double_dist()
49 {
50 int Error = 0;
51
52 glm::dvec4 const A(1.0);
53
54 glm::dvec4 const B = glm::nextFloat(A);
55 Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
56 glm::dvec4 const C = glm::prevFloat(B);
57 Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
58
59 glm::ivec4 const D(glm::floatDistance(A, B));
60 Error += D == glm::ivec4(1) ? 0 : 1;
61 glm::ivec4 const E = glm::floatDistance(A, C);
62 Error += E == glm::ivec4(0) ? 0 : 1;
63
64 return Error;
65 }
66
test_ulp_double_step()67 static int test_ulp_double_step()
68 {
69 int Error = 0;
70
71 glm::dvec4 const A(1.0);
72
73 for(int i = 10; i < 1000; i *= 10)
74 {
75 glm::dvec4 const B = glm::nextFloat(A, i);
76 Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
77 glm::dvec4 const C = glm::prevFloat(B, i);
78 Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
79
80 glm::ivec4 const D(glm::floatDistance(A, B));
81 Error += D == glm::ivec4(i) ? 0 : 1;
82 glm::ivec4 const E(glm::floatDistance(A, C));
83 Error += E == glm::ivec4(0) ? 0 : 1;
84 }
85
86 return Error;
87 }
88
main()89 int main()
90 {
91 int Error = 0;
92
93 Error += test_ulp_float_dist();
94 Error += test_ulp_float_step();
95 Error += test_ulp_double_dist();
96 Error += test_ulp_double_step();
97
98 return Error;
99 }
100