core_func_common.cpp 18 KB

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