core_func_common.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 <glm/gtc/vec1.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. int test_min()
  130. {
  131. int Error = 0;
  132. glm::vec1 A0 = glm::min(glm::vec1(1), glm::vec1(1));
  133. glm::vec2 B0 = glm::min(glm::vec2(1), glm::vec2(1));
  134. glm::vec2 B1 = glm::min(glm::vec2(1), 1.0f);
  135. bool B2 = glm::all(glm::equal(B0, B1));
  136. Error += B2 ? 0 : 1;
  137. glm::vec3 C0 = glm::min(glm::vec3(1), glm::vec3(1));
  138. glm::vec3 C1 = glm::min(glm::vec3(1), 1.0f);
  139. bool C2 = glm::all(glm::equal(C0, C1));
  140. Error += C2 ? 0 : 1;
  141. glm::vec4 D0 = glm::min(glm::vec4(1), glm::vec4(1));
  142. glm::vec4 D1 = glm::min(glm::vec4(1), 1.0f);
  143. bool D2 = glm::all(glm::equal(D0, D1));
  144. Error += D2 ? 0 : 1;
  145. return Error;
  146. }
  147. int test_max()
  148. {
  149. int Error = 0;
  150. glm::vec1 A0 = glm::max(glm::vec1(1), glm::vec1(1));
  151. glm::vec2 B0 = glm::max(glm::vec2(1), glm::vec2(1));
  152. glm::vec2 B1 = glm::max(glm::vec2(1), 1.0f);
  153. bool B2 = glm::all(glm::equal(B0, B1));
  154. Error += B2 ? 0 : 1;
  155. glm::vec3 C0 = glm::max(glm::vec3(1), glm::vec3(1));
  156. glm::vec3 C1 = glm::max(glm::vec3(1), 1.0f);
  157. bool C2 = glm::all(glm::equal(C0, C1));
  158. Error += C2 ? 0 : 1;
  159. glm::vec4 D0 = glm::max(glm::vec4(1), glm::vec4(1));
  160. glm::vec4 D1 = glm::max(glm::vec4(1), 1.0f);
  161. bool D2 = glm::all(glm::equal(D0, D1));
  162. Error += D2 ? 0 : 1;
  163. return Error;
  164. }
  165. int test_clamp()
  166. {
  167. int Error = 0;
  168. return Error;
  169. }
  170. namespace test_mix
  171. {
  172. template <typename T, typename B>
  173. struct test
  174. {
  175. T x;
  176. T y;
  177. B a;
  178. T Result;
  179. };
  180. test<float, bool> TestBool[] =
  181. {
  182. {0.0f, 1.0f, false, 0.0f},
  183. {0.0f, 1.0f, true, 1.0f},
  184. {-1.0f, 1.0f, false, -1.0f},
  185. {-1.0f, 1.0f, true, 1.0f}
  186. };
  187. test<float, float> TestFloat[] =
  188. {
  189. {0.0f, 1.0f, 0.0f, 0.0f},
  190. {0.0f, 1.0f, 1.0f, 1.0f},
  191. {-1.0f, 1.0f, 0.0f, -1.0f},
  192. {-1.0f, 1.0f, 1.0f, 1.0f}
  193. };
  194. test<glm::vec2, bool> TestVec2Bool[] =
  195. {
  196. {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
  197. {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
  198. {glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)},
  199. {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
  200. };
  201. test<glm::vec2, glm::bvec2> TestBVec2[] =
  202. {
  203. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
  204. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  205. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)},
  206. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  207. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
  208. };
  209. test<glm::vec3, bool> TestVec3Bool[] =
  210. {
  211. {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
  212. {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
  213. {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)},
  214. {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
  215. };
  216. test<glm::vec3, glm::bvec3> TestBVec3[] =
  217. {
  218. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
  219. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  220. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)},
  221. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  222. {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)}
  223. };
  224. test<glm::vec4, bool> TestVec4Bool[] =
  225. {
  226. {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
  227. {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
  228. {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)},
  229. {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
  230. };
  231. test<glm::vec4, glm::bvec4> TestBVec4[] =
  232. {
  233. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)},
  234. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  235. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)},
  236. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  237. {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)}
  238. };
  239. int run()
  240. {
  241. int Error = 0;
  242. // Float with bool
  243. {
  244. for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(test<float, bool>); ++i)
  245. {
  246. float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
  247. Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
  248. }
  249. }
  250. // Float with float
  251. {
  252. for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(test<float, float>); ++i)
  253. {
  254. float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
  255. Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
  256. }
  257. }
  258. // vec2 with bool
  259. {
  260. for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(test<glm::vec2, bool>); ++i)
  261. {
  262. glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
  263. Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  264. Error += glm::epsilonEqual(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  265. }
  266. }
  267. // vec2 with bvec2
  268. {
  269. for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(test<glm::vec2, glm::bvec2>); ++i)
  270. {
  271. glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
  272. Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  273. Error += glm::epsilonEqual(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  274. }
  275. }
  276. // vec3 with bool
  277. {
  278. for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(test<glm::vec3, bool>); ++i)
  279. {
  280. glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
  281. Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  282. Error += glm::epsilonEqual(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  283. Error += glm::epsilonEqual(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  284. }
  285. }
  286. // vec3 with bvec3
  287. {
  288. for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(test<glm::vec3, glm::bvec3>); ++i)
  289. {
  290. glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
  291. Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  292. Error += glm::epsilonEqual(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  293. Error += glm::epsilonEqual(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  294. }
  295. }
  296. // vec4 with bool
  297. {
  298. for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(test<glm::vec4, bool>); ++i)
  299. {
  300. glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
  301. Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  302. Error += glm::epsilonEqual(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  303. Error += glm::epsilonEqual(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  304. Error += glm::epsilonEqual(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  305. }
  306. }
  307. // vec4 with bvec4
  308. {
  309. for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(test<glm::vec4, glm::bvec4>); ++i)
  310. {
  311. glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
  312. Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  313. Error += glm::epsilonEqual(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  314. Error += glm::epsilonEqual(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  315. Error += glm::epsilonEqual(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  316. }
  317. }
  318. return Error;
  319. }
  320. }//namespace test_mix
  321. namespace test_step
  322. {
  323. template <typename EDGE, typename VEC>
  324. struct test
  325. {
  326. EDGE edge;
  327. VEC x;
  328. VEC result;
  329. };
  330. test<float, glm::vec4> TestVec4Scalar [] =
  331. {
  332. { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  333. { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  334. { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
  335. };
  336. test<glm::vec4, glm::vec4> TestVec4Vector [] =
  337. {
  338. { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
  339. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  340. { glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
  341. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
  342. };
  343. int run()
  344. {
  345. int Error = 0;
  346. // vec4 and float
  347. {
  348. for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(test<float, glm::vec4>); ++i)
  349. {
  350. glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
  351. Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
  352. }
  353. }
  354. // vec4 and vec4
  355. {
  356. for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(test<glm::vec4, glm::vec4>); ++i)
  357. {
  358. glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
  359. Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
  360. }
  361. }
  362. return Error;
  363. }
  364. }//namespace test_step
  365. int test_round()
  366. {
  367. int Error = 0;
  368. {
  369. float A = glm::round(0.0f);
  370. Error += A == 0.0f ? 0 : 1;
  371. float B = glm::round(0.5f);
  372. Error += B == 1.0f ? 0 : 1;
  373. float C = glm::round(1.0f);
  374. Error += C == 1.0f ? 0 : 1;
  375. float D = glm::round(0.1f);
  376. Error += D == 0.0f ? 0 : 1;
  377. float E = glm::round(0.9f);
  378. Error += E == 1.0f ? 0 : 1;
  379. float F = glm::round(1.5f);
  380. Error += F == 2.0f ? 0 : 1;
  381. float G = glm::round(1.9f);
  382. Error += G == 2.0f ? 0 : 1;
  383. #if GLM_LANG >= GLM_LANG_CXX11
  384. float A1 = glm::round(0.0f);
  385. Error += A1 == A ? 0 : 1;
  386. float B1 = glm::round(0.5f);
  387. Error += B1 == B ? 0 : 1;
  388. float C1 = glm::round(1.0f);
  389. Error += C1 == C ? 0 : 1;
  390. float D1 = glm::round(0.1f);
  391. Error += D1 == D ? 0 : 1;
  392. float E1 = glm::round(0.9f);
  393. Error += E1 == E ? 0 : 1;
  394. float F1 = glm::round(1.5f);
  395. Error += F == F ? 0 : 1;
  396. float G1 = glm::round(1.9f);
  397. Error += G1 == G ? 0 : 1;
  398. #endif // GLM_LANG >= GLM_CXX0X
  399. }
  400. {
  401. float A = glm::round(-0.0f);
  402. Error += A == 0.0f ? 0 : 1;
  403. float B = glm::round(-0.5f);
  404. Error += B == -1.0f ? 0 : 1;
  405. float C = glm::round(-1.0f);
  406. Error += C == -1.0f ? 0 : 1;
  407. float D = glm::round(-0.1f);
  408. Error += D == 0.0f ? 0 : 1;
  409. float E = glm::round(-0.9f);
  410. Error += E == -1.0f ? 0 : 1;
  411. float F = glm::round(-1.5f);
  412. Error += F == -2.0f ? 0 : 1;
  413. float G = glm::round(-1.9f);
  414. Error += G == -2.0f ? 0 : 1;
  415. }
  416. return Error;
  417. }
  418. int test_roundEven()
  419. {
  420. int Error = 0;
  421. {
  422. float A = glm::roundEven(-1.5f);
  423. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  424. Error += 0;
  425. }
  426. {
  427. float A = glm::roundEven(1.5f);
  428. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  429. Error += 0;
  430. }
  431. {
  432. float A = glm::roundEven(-3.5f);
  433. Error += glm::epsilonEqual(A, -4.0f, 0.0001f) ? 0 : 1;
  434. Error += 0;
  435. }
  436. {
  437. float A = glm::roundEven(3.5f);
  438. Error += glm::epsilonEqual(A, 4.0f, 0.0001f) ? 0 : 1;
  439. Error += 0;
  440. }
  441. {
  442. float A = glm::roundEven(-2.5f);
  443. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  444. Error += 0;
  445. }
  446. {
  447. float A = glm::roundEven(2.5f);
  448. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  449. Error += 0;
  450. }
  451. {
  452. float A = glm::roundEven(-2.4f);
  453. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  454. Error += 0;
  455. }
  456. {
  457. float A = glm::roundEven(2.4f);
  458. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  459. Error += 0;
  460. }
  461. {
  462. float A = glm::roundEven(-2.6f);
  463. Error += glm::epsilonEqual(A, -3.0f, 0.0001f) ? 0 : 1;
  464. Error += 0;
  465. }
  466. {
  467. float A = glm::roundEven(2.6f);
  468. Error += glm::epsilonEqual(A, 3.0f, 0.0001f) ? 0 : 1;
  469. Error += 0;
  470. }
  471. {
  472. float A = glm::roundEven(-2.0f);
  473. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  474. Error += 0;
  475. }
  476. {
  477. float A = glm::roundEven(2.0f);
  478. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  479. Error += 0;
  480. }
  481. {
  482. float A = glm::roundEven(0.0f);
  483. Error += A == 0.0f ? 0 : 1;
  484. float B = glm::roundEven(0.5f);
  485. Error += B == 0.0f ? 0 : 1;
  486. float C = glm::roundEven(1.0f);
  487. Error += C == 1.0f ? 0 : 1;
  488. float D = glm::roundEven(0.1f);
  489. Error += D == 0.0f ? 0 : 1;
  490. float E = glm::roundEven(0.9f);
  491. Error += E == 1.0f ? 0 : 1;
  492. float F = glm::roundEven(1.5f);
  493. Error += F == 2.0f ? 0 : 1;
  494. float G = glm::roundEven(1.9f);
  495. Error += G == 2.0f ? 0 : 1;
  496. }
  497. {
  498. float A = glm::roundEven(-0.0f);
  499. Error += A == 0.0f ? 0 : 1;
  500. float B = glm::roundEven(-0.5f);
  501. Error += B == -0.0f ? 0 : 1;
  502. float C = glm::roundEven(-1.0f);
  503. Error += C == -1.0f ? 0 : 1;
  504. float D = glm::roundEven(-0.1f);
  505. Error += D == 0.0f ? 0 : 1;
  506. float E = glm::roundEven(-0.9f);
  507. Error += E == -1.0f ? 0 : 1;
  508. float F = glm::roundEven(-1.5f);
  509. Error += F == -2.0f ? 0 : 1;
  510. float G = glm::roundEven(-1.9f);
  511. Error += G == -2.0f ? 0 : 1;
  512. }
  513. {
  514. float A = glm::roundEven(1.5f);
  515. Error += A == 2.0f ? 0 : 1;
  516. float B = glm::roundEven(2.5f);
  517. Error += B == 2.0f ? 0 : 1;
  518. float C = glm::roundEven(3.5f);
  519. Error += C == 4.0f ? 0 : 1;
  520. float D = glm::roundEven(4.5f);
  521. Error += D == 4.0f ? 0 : 1;
  522. float E = glm::roundEven(5.5f);
  523. Error += E == 6.0f ? 0 : 1;
  524. float F = glm::roundEven(6.5f);
  525. Error += F == 6.0f ? 0 : 1;
  526. float G = glm::roundEven(7.5f);
  527. Error += G == 8.0f ? 0 : 1;
  528. }
  529. {
  530. float A = glm::roundEven(-1.5f);
  531. Error += A == -2.0f ? 0 : 1;
  532. float B = glm::roundEven(-2.5f);
  533. Error += B == -2.0f ? 0 : 1;
  534. float C = glm::roundEven(-3.5f);
  535. Error += C == -4.0f ? 0 : 1;
  536. float D = glm::roundEven(-4.5f);
  537. Error += D == -4.0f ? 0 : 1;
  538. float E = glm::roundEven(-5.5f);
  539. Error += E == -6.0f ? 0 : 1;
  540. float F = glm::roundEven(-6.5f);
  541. Error += F == -6.0f ? 0 : 1;
  542. float G = glm::roundEven(-7.5f);
  543. Error += G == -8.0f ? 0 : 1;
  544. }
  545. return Error;
  546. }
  547. int test_isnan()
  548. {
  549. int Error = 0;
  550. float Zero_f = 0.0;
  551. double Zero_d = 0.0;
  552. {
  553. Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
  554. Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
  555. Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
  556. Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
  557. }
  558. {
  559. Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
  560. Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
  561. Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
  562. Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
  563. }
  564. return Error;
  565. }
  566. int test_isinf()
  567. {
  568. int Error = 0;
  569. float Zero_f = 0.0;
  570. double Zero_d = 0.0;
  571. {
  572. Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
  573. Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
  574. Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
  575. Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
  576. Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
  577. Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
  578. Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
  579. Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
  580. }
  581. {
  582. Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
  583. Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
  584. Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
  585. Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
  586. Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
  587. Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
  588. Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
  589. Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
  590. }
  591. return Error;
  592. }
  593. int main()
  594. {
  595. int Error(0);
  596. Error += test_modf();
  597. Error += test_floatBitsToInt();
  598. Error += test_floatBitsToUint();
  599. Error += test_step::run();
  600. Error += test_max();
  601. Error += test_min();
  602. Error += test_mix::run();
  603. Error += test_round();
  604. Error += test_roundEven();
  605. Error += test_isnan();
  606. //Error += test_isinf();
  607. return Error;
  608. }