core_func_common.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-01-15
  5. // Updated : 2011-09-13
  6. // Licence : This source is under MIT licence
  7. // File : test/core/func_common.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. //#include <boost/array.hpp>
  10. //#include <boost/date_time/posix_time/posix_time.hpp>
  11. //#include <boost/thread/thread.hpp>
  12. #include <glm/gtc/constants.hpp>
  13. #include <glm/gtc/epsilon.hpp>
  14. #include <cstdio>
  15. #include <cmath>
  16. int test_modf()
  17. {
  18. int Error(0);
  19. {
  20. float X(1.5f);
  21. float I(0.0f);
  22. float A = glm::modf(X, I);
  23. Error += I == 1.0f ? 0 : 1;
  24. Error += A == 0.5f ? 0 : 1;
  25. }
  26. {
  27. glm::vec4 X(1.1f, 1.2f, 1.5f, 1.7f);
  28. glm::vec4 I(0.0f);
  29. glm::vec4 A = glm::modf(X, I);
  30. Error += I == glm::vec4(1.0f) ? 0 : 1;
  31. Error += glm::all(glm::epsilonEqual(A, glm::vec4(0.1f, 0.2f, 0.5f, 0.7f), 0.00001f)) ? 0 : 1;
  32. }
  33. {
  34. glm::dvec4 X(1.1, 1.2, 1.5, 1.7);
  35. glm::dvec4 I(0.0);
  36. glm::dvec4 A = glm::modf(X, I);
  37. Error += I == glm::dvec4(1.0) ? 0 : 1;
  38. Error += glm::all(glm::epsilonEqual(A, glm::dvec4(0.1, 0.2, 0.5, 0.7), 0.000000001)) ? 0 : 1;
  39. }
  40. {
  41. double X(1.5);
  42. double I(0.0);
  43. double A = glm::modf(X, I);
  44. Error += I == 1.0 ? 0 : 1;
  45. Error += A == 0.5 ? 0 : 1;
  46. }
  47. return Error;
  48. }
  49. int test_floatBitsToInt()
  50. {
  51. int Error = 0;
  52. {
  53. float A = 1.0f;
  54. int B = glm::floatBitsToInt(A);
  55. float C = glm::intBitsToFloat(B);
  56. int D = *(int*)&A;
  57. Error += B == D ? 0 : 1;
  58. Error += A == C ? 0 : 1;
  59. }
  60. {
  61. glm::vec2 A(1.0f, 2.0f);
  62. glm::ivec2 B = glm::floatBitsToInt(A);
  63. glm::vec2 C = glm::intBitsToFloat(B);
  64. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  65. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  66. Error += A == C? 0 : 1;
  67. }
  68. {
  69. glm::vec3 A(1.0f, 2.0f, 3.0f);
  70. glm::ivec3 B = glm::floatBitsToInt(A);
  71. glm::vec3 C = glm::intBitsToFloat(B);
  72. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  73. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  74. Error += B.z == *(int*)&(A.z) ? 0 : 1;
  75. Error += A == C? 0 : 1;
  76. }
  77. {
  78. glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
  79. glm::ivec4 B = glm::floatBitsToInt(A);
  80. glm::vec4 C = glm::intBitsToFloat(B);
  81. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  82. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  83. Error += B.z == *(int*)&(A.z) ? 0 : 1;
  84. Error += B.w == *(int*)&(A.w) ? 0 : 1;
  85. Error += A == C? 0 : 1;
  86. }
  87. return Error;
  88. }
  89. int test_floatBitsToUint()
  90. {
  91. int Error = 0;
  92. {
  93. float A = 1.0f;
  94. glm::uint B = glm::floatBitsToUint(A);
  95. float C = glm::intBitsToFloat(B);
  96. Error += B == *(glm::uint*)&A ? 0 : 1;
  97. Error += A == C? 0 : 1;
  98. }
  99. {
  100. glm::vec2 A(1.0f, 2.0f);
  101. glm::uvec2 B = glm::floatBitsToUint(A);
  102. glm::vec2 C = glm::uintBitsToFloat(B);
  103. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  104. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  105. Error += A == C ? 0 : 1;
  106. }
  107. {
  108. glm::vec3 A(1.0f, 2.0f, 3.0f);
  109. glm::uvec3 B = glm::floatBitsToUint(A);
  110. glm::vec3 C = glm::uintBitsToFloat(B);
  111. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  112. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  113. Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
  114. Error += A == C? 0 : 1;
  115. }
  116. {
  117. glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
  118. glm::uvec4 B = glm::floatBitsToUint(A);
  119. glm::vec4 C = glm::uintBitsToFloat(B);
  120. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  121. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  122. Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
  123. Error += B.w == *(glm::uint*)&(A.w) ? 0 : 1;
  124. Error += A == C? 0 : 1;
  125. }
  126. return Error;
  127. }
  128. namespace test_mix
  129. {
  130. template <typename T, typename B>
  131. struct test
  132. {
  133. T x;
  134. T y;
  135. B a;
  136. T Result;
  137. };
  138. test<float, bool> TestBool[] =
  139. {
  140. {0.0f, 1.0f, false, 0.0f},
  141. {0.0f, 1.0f, true, 1.0f},
  142. {-1.0f, 1.0f, false, -1.0f},
  143. {-1.0f, 1.0f, true, 1.0f}
  144. };
  145. test<float, float> TestFloat[] =
  146. {
  147. {0.0f, 1.0f, 0.0f, 0.0f},
  148. {0.0f, 1.0f, 1.0f, 1.0f},
  149. {-1.0f, 1.0f, 0.0f, -1.0f},
  150. {-1.0f, 1.0f, 1.0f, 1.0f}
  151. };
  152. test<glm::vec2, bool> TestVec2Bool[] =
  153. {
  154. {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
  155. {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
  156. {glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)},
  157. {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
  158. };
  159. test<glm::vec2, glm::bvec2> TestBVec2[] =
  160. {
  161. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
  162. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  163. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)},
  164. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  165. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
  166. };
  167. test<glm::vec3, bool> TestVec3Bool[] =
  168. {
  169. {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
  170. {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
  171. {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)},
  172. {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
  173. };
  174. test<glm::vec3, glm::bvec3> TestBVec3[] =
  175. {
  176. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
  177. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  178. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)},
  179. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  180. {glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)}
  181. };
  182. test<glm::vec4, bool> TestVec4Bool[] =
  183. {
  184. {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
  185. {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
  186. {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)},
  187. {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
  188. };
  189. test<glm::vec4, glm::bvec4> TestBVec4[] =
  190. {
  191. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)},
  192. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  193. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)},
  194. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  195. {glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)}
  196. };
  197. int run()
  198. {
  199. int Error = 0;
  200. // Float with bool
  201. {
  202. for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(test<float, bool>); ++i)
  203. {
  204. float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
  205. Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
  206. }
  207. }
  208. // Float with float
  209. {
  210. for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(test<float, float>); ++i)
  211. {
  212. float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
  213. Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
  214. }
  215. }
  216. // vec2 with bool
  217. {
  218. for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(test<glm::vec2, bool>); ++i)
  219. {
  220. glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
  221. Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  222. Error += glm::epsilonEqual(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  223. }
  224. }
  225. // vec2 with bvec2
  226. {
  227. for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(test<glm::vec2, glm::bvec2>); ++i)
  228. {
  229. glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
  230. Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  231. Error += glm::epsilonEqual(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  232. }
  233. }
  234. // vec3 with bool
  235. {
  236. for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(test<glm::vec3, bool>); ++i)
  237. {
  238. glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
  239. Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  240. Error += glm::epsilonEqual(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  241. Error += glm::epsilonEqual(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  242. }
  243. }
  244. // vec3 with bvec3
  245. {
  246. for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(test<glm::vec3, glm::bvec3>); ++i)
  247. {
  248. glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
  249. Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  250. Error += glm::epsilonEqual(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  251. Error += glm::epsilonEqual(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  252. }
  253. }
  254. // vec4 with bool
  255. {
  256. for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(test<glm::vec4, bool>); ++i)
  257. {
  258. glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
  259. Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  260. Error += glm::epsilonEqual(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  261. Error += glm::epsilonEqual(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  262. Error += glm::epsilonEqual(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  263. }
  264. }
  265. // vec4 with bvec4
  266. {
  267. for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(test<glm::vec4, glm::bvec4>); ++i)
  268. {
  269. glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
  270. Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  271. Error += glm::epsilonEqual(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  272. Error += glm::epsilonEqual(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  273. Error += glm::epsilonEqual(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  274. }
  275. }
  276. return Error;
  277. }
  278. }//namespace test_mix
  279. namespace test_step
  280. {
  281. template <typename EDGE, typename VEC>
  282. struct test
  283. {
  284. EDGE edge;
  285. VEC x;
  286. VEC result;
  287. };
  288. test<float, glm::vec4> TestVec4Scalar [] =
  289. {
  290. { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  291. { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  292. { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
  293. };
  294. test<glm::vec4, glm::vec4> TestVec4Vector [] =
  295. {
  296. { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
  297. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  298. { glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
  299. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
  300. };
  301. int run()
  302. {
  303. int Error = 0;
  304. // vec4 and float
  305. {
  306. for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(test<float, glm::vec4>); ++i)
  307. {
  308. glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
  309. Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
  310. }
  311. }
  312. // vec4 and vec4
  313. {
  314. for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(test<glm::vec4, glm::vec4>); ++i)
  315. {
  316. glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
  317. Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
  318. }
  319. }
  320. return Error;
  321. }
  322. }//namespace test_step
  323. int test_round()
  324. {
  325. int Error = 0;
  326. {
  327. float A = glm::round(0.0f);
  328. Error += A == 0.0f ? 0 : 1;
  329. float B = glm::round(0.5f);
  330. Error += B == 1.0f ? 0 : 1;
  331. float C = glm::round(1.0f);
  332. Error += C == 1.0f ? 0 : 1;
  333. float D = glm::round(0.1f);
  334. Error += D == 0.0f ? 0 : 1;
  335. float E = glm::round(0.9f);
  336. Error += E == 1.0f ? 0 : 1;
  337. float F = glm::round(1.5f);
  338. Error += F == 2.0f ? 0 : 1;
  339. float G = glm::round(1.9f);
  340. Error += G == 2.0f ? 0 : 1;
  341. #if GLM_LANG >= GLM_LANG_CXX11
  342. float A1 = glm::round(0.0f);
  343. Error += A1 == A ? 0 : 1;
  344. float B1 = glm::round(0.5f);
  345. Error += B1 == B ? 0 : 1;
  346. float C1 = glm::round(1.0f);
  347. Error += C1 == C ? 0 : 1;
  348. float D1 = glm::round(0.1f);
  349. Error += D1 == D ? 0 : 1;
  350. float E1 = glm::round(0.9f);
  351. Error += E1 == E ? 0 : 1;
  352. float F1 = glm::round(1.5f);
  353. Error += F == F ? 0 : 1;
  354. float G1 = glm::round(1.9f);
  355. Error += G1 == G ? 0 : 1;
  356. #endif // GLM_LANG >= GLM_CXX0X
  357. }
  358. {
  359. float A = glm::round(-0.0f);
  360. Error += A == 0.0f ? 0 : 1;
  361. float B = glm::round(-0.5f);
  362. Error += B == -1.0f ? 0 : 1;
  363. float C = glm::round(-1.0f);
  364. Error += C == -1.0f ? 0 : 1;
  365. float D = glm::round(-0.1f);
  366. Error += D == 0.0f ? 0 : 1;
  367. float E = glm::round(-0.9f);
  368. Error += E == -1.0f ? 0 : 1;
  369. float F = glm::round(-1.5f);
  370. Error += F == -2.0f ? 0 : 1;
  371. float G = glm::round(-1.9f);
  372. Error += G == -2.0f ? 0 : 1;
  373. }
  374. return Error;
  375. }
  376. int test_roundEven()
  377. {
  378. int Error = 0;
  379. {
  380. float A = glm::roundEven(-1.5f);
  381. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  382. Error += 0;
  383. }
  384. {
  385. float A = glm::roundEven(1.5f);
  386. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  387. Error += 0;
  388. }
  389. {
  390. float A = glm::roundEven(-3.5f);
  391. Error += glm::epsilonEqual(A, -4.0f, 0.0001f) ? 0 : 1;
  392. Error += 0;
  393. }
  394. {
  395. float A = glm::roundEven(3.5f);
  396. Error += glm::epsilonEqual(A, 4.0f, 0.0001f) ? 0 : 1;
  397. Error += 0;
  398. }
  399. {
  400. float A = glm::roundEven(-2.5f);
  401. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  402. Error += 0;
  403. }
  404. {
  405. float A = glm::roundEven(2.5f);
  406. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  407. Error += 0;
  408. }
  409. {
  410. float A = glm::roundEven(-2.4f);
  411. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  412. Error += 0;
  413. }
  414. {
  415. float A = glm::roundEven(2.4f);
  416. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  417. Error += 0;
  418. }
  419. {
  420. float A = glm::roundEven(-2.6f);
  421. Error += glm::epsilonEqual(A, -3.0f, 0.0001f) ? 0 : 1;
  422. Error += 0;
  423. }
  424. {
  425. float A = glm::roundEven(2.6f);
  426. Error += glm::epsilonEqual(A, 3.0f, 0.0001f) ? 0 : 1;
  427. Error += 0;
  428. }
  429. {
  430. float A = glm::roundEven(-2.0f);
  431. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  432. Error += 0;
  433. }
  434. {
  435. float A = glm::roundEven(2.0f);
  436. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  437. Error += 0;
  438. }
  439. {
  440. float A = glm::roundEven(0.0f);
  441. Error += A == 0.0f ? 0 : 1;
  442. float B = glm::roundEven(0.5f);
  443. Error += B == 0.0f ? 0 : 1;
  444. float C = glm::roundEven(1.0f);
  445. Error += C == 1.0f ? 0 : 1;
  446. float D = glm::roundEven(0.1f);
  447. Error += D == 0.0f ? 0 : 1;
  448. float E = glm::roundEven(0.9f);
  449. Error += E == 1.0f ? 0 : 1;
  450. float F = glm::roundEven(1.5f);
  451. Error += F == 2.0f ? 0 : 1;
  452. float G = glm::roundEven(1.9f);
  453. Error += G == 2.0f ? 0 : 1;
  454. }
  455. {
  456. float A = glm::roundEven(-0.0f);
  457. Error += A == 0.0f ? 0 : 1;
  458. float B = glm::roundEven(-0.5f);
  459. Error += B == -0.0f ? 0 : 1;
  460. float C = glm::roundEven(-1.0f);
  461. Error += C == -1.0f ? 0 : 1;
  462. float D = glm::roundEven(-0.1f);
  463. Error += D == 0.0f ? 0 : 1;
  464. float E = glm::roundEven(-0.9f);
  465. Error += E == -1.0f ? 0 : 1;
  466. float F = glm::roundEven(-1.5f);
  467. Error += F == -2.0f ? 0 : 1;
  468. float G = glm::roundEven(-1.9f);
  469. Error += G == -2.0f ? 0 : 1;
  470. }
  471. {
  472. float A = glm::roundEven(1.5f);
  473. Error += A == 2.0f ? 0 : 1;
  474. float B = glm::roundEven(2.5f);
  475. Error += B == 2.0f ? 0 : 1;
  476. float C = glm::roundEven(3.5f);
  477. Error += C == 4.0f ? 0 : 1;
  478. float D = glm::roundEven(4.5f);
  479. Error += D == 4.0f ? 0 : 1;
  480. float E = glm::roundEven(5.5f);
  481. Error += E == 6.0f ? 0 : 1;
  482. float F = glm::roundEven(6.5f);
  483. Error += F == 6.0f ? 0 : 1;
  484. float G = glm::roundEven(7.5f);
  485. Error += G == 8.0f ? 0 : 1;
  486. }
  487. {
  488. float A = glm::roundEven(-1.5f);
  489. Error += A == -2.0f ? 0 : 1;
  490. float B = glm::roundEven(-2.5f);
  491. Error += B == -2.0f ? 0 : 1;
  492. float C = glm::roundEven(-3.5f);
  493. Error += C == -4.0f ? 0 : 1;
  494. float D = glm::roundEven(-4.5f);
  495. Error += D == -4.0f ? 0 : 1;
  496. float E = glm::roundEven(-5.5f);
  497. Error += E == -6.0f ? 0 : 1;
  498. float F = glm::roundEven(-6.5f);
  499. Error += F == -6.0f ? 0 : 1;
  500. float G = glm::roundEven(-7.5f);
  501. Error += G == -8.0f ? 0 : 1;
  502. }
  503. return Error;
  504. }
  505. int test_isnan()
  506. {
  507. int Error = 0;
  508. float Zero_f = 0.0;
  509. double Zero_d = 0.0;
  510. {
  511. Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
  512. Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
  513. Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
  514. Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
  515. }
  516. {
  517. Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
  518. Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
  519. Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
  520. Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
  521. }
  522. return Error;
  523. }
  524. int test_isinf()
  525. {
  526. int Error = 0;
  527. float Zero_f = 0.0;
  528. double Zero_d = 0.0;
  529. {
  530. Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
  531. Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
  532. Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
  533. Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
  534. Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
  535. Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
  536. Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
  537. Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
  538. }
  539. {
  540. Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
  541. Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
  542. Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
  543. Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
  544. Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
  545. Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
  546. Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
  547. Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
  548. }
  549. return Error;
  550. }
  551. int main()
  552. {
  553. int Error(0);
  554. Error += test_modf();
  555. Error += test_floatBitsToInt();
  556. Error += test_floatBitsToUint();
  557. Error += test_step::run();
  558. Error += test_mix::run();
  559. Error += test_round();
  560. Error += test_roundEven();
  561. Error += test_isnan();
  562. //Error += test_isinf();
  563. return Error;
  564. }