2
0

core_func_common.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 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/glm.hpp>
  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. int test_round()
  281. {
  282. int Error = 0;
  283. {
  284. float A = glm::round(0.0f);
  285. Error += A == 0.0f ? 0 : 1;
  286. float B = glm::round(0.5f);
  287. Error += B == 1.0f ? 0 : 1;
  288. float C = glm::round(1.0f);
  289. Error += C == 1.0f ? 0 : 1;
  290. float D = glm::round(0.1f);
  291. Error += D == 0.0f ? 0 : 1;
  292. float E = glm::round(0.9f);
  293. Error += E == 1.0f ? 0 : 1;
  294. float F = glm::round(1.5f);
  295. Error += F == 2.0f ? 0 : 1;
  296. float G = glm::round(1.9f);
  297. Error += G == 2.0f ? 0 : 1;
  298. #if GLM_LANG >= GLM_LANG_CXX11
  299. float A1 = std::round(0.0f);
  300. Error += A1 == A ? 0 : 1;
  301. float B1 = std::round(0.5f);
  302. Error += B1 == B ? 0 : 1;
  303. float C1 = std::round(1.0f);
  304. Error += C1 == C ? 0 : 1;
  305. float D1 = std::round(0.1f);
  306. Error += D1 == D ? 0 : 1;
  307. float E1 = std::round(0.9f);
  308. Error += E1 == E ? 0 : 1;
  309. float F1 = std::round(1.5f);
  310. Error += F == F ? 0 : 1;
  311. float G1 = std::round(1.9f);
  312. Error += G1 == G ? 0 : 1;
  313. #endif // GLM_LANG >= GLM_CXX0X
  314. }
  315. {
  316. float A = glm::round(-0.0f);
  317. Error += A == 0.0f ? 0 : 1;
  318. float B = glm::round(-0.5f);
  319. Error += B == -1.0f ? 0 : 1;
  320. float C = glm::round(-1.0f);
  321. Error += C == -1.0f ? 0 : 1;
  322. float D = glm::round(-0.1f);
  323. Error += D == 0.0f ? 0 : 1;
  324. float E = glm::round(-0.9f);
  325. Error += E == -1.0f ? 0 : 1;
  326. float F = glm::round(-1.5f);
  327. Error += F == -2.0f ? 0 : 1;
  328. float G = glm::round(-1.9f);
  329. Error += G == -2.0f ? 0 : 1;
  330. }
  331. return Error;
  332. }
  333. int test_roundEven()
  334. {
  335. int Error = 0;
  336. {
  337. float A = glm::roundEven(-1.5f);
  338. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  339. Error += 0;
  340. }
  341. {
  342. float A = glm::roundEven(1.5f);
  343. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  344. Error += 0;
  345. }
  346. {
  347. float A = glm::roundEven(-3.5f);
  348. Error += glm::epsilonEqual(A, -4.0f, 0.0001f) ? 0 : 1;
  349. Error += 0;
  350. }
  351. {
  352. float A = glm::roundEven(3.5f);
  353. Error += glm::epsilonEqual(A, 4.0f, 0.0001f) ? 0 : 1;
  354. Error += 0;
  355. }
  356. {
  357. float A = glm::roundEven(-2.5f);
  358. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  359. Error += 0;
  360. }
  361. {
  362. float A = glm::roundEven(2.5f);
  363. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  364. Error += 0;
  365. }
  366. {
  367. float A = glm::roundEven(-2.4f);
  368. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  369. Error += 0;
  370. }
  371. {
  372. float A = glm::roundEven(2.4f);
  373. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  374. Error += 0;
  375. }
  376. {
  377. float A = glm::roundEven(-2.6f);
  378. Error += glm::epsilonEqual(A, -3.0f, 0.0001f) ? 0 : 1;
  379. Error += 0;
  380. }
  381. {
  382. float A = glm::roundEven(2.6f);
  383. Error += glm::epsilonEqual(A, 3.0f, 0.0001f) ? 0 : 1;
  384. Error += 0;
  385. }
  386. {
  387. float A = glm::roundEven(-2.0f);
  388. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  389. Error += 0;
  390. }
  391. {
  392. float A = glm::roundEven(2.0f);
  393. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  394. Error += 0;
  395. }
  396. {
  397. float A = glm::roundEven(0.0f);
  398. Error += A == 0.0f ? 0 : 1;
  399. float B = glm::roundEven(0.5f);
  400. Error += B == 0.0f ? 0 : 1;
  401. float C = glm::roundEven(1.0f);
  402. Error += C == 1.0f ? 0 : 1;
  403. float D = glm::roundEven(0.1f);
  404. Error += D == 0.0f ? 0 : 1;
  405. float E = glm::roundEven(0.9f);
  406. Error += E == 1.0f ? 0 : 1;
  407. float F = glm::roundEven(1.5f);
  408. Error += F == 2.0f ? 0 : 1;
  409. float G = glm::roundEven(1.9f);
  410. Error += G == 2.0f ? 0 : 1;
  411. }
  412. {
  413. float A = glm::roundEven(-0.0f);
  414. Error += A == 0.0f ? 0 : 1;
  415. float B = glm::roundEven(-0.5f);
  416. Error += B == -0.0f ? 0 : 1;
  417. float C = glm::roundEven(-1.0f);
  418. Error += C == -1.0f ? 0 : 1;
  419. float D = glm::roundEven(-0.1f);
  420. Error += D == 0.0f ? 0 : 1;
  421. float E = glm::roundEven(-0.9f);
  422. Error += E == -1.0f ? 0 : 1;
  423. float F = glm::roundEven(-1.5f);
  424. Error += F == -2.0f ? 0 : 1;
  425. float G = glm::roundEven(-1.9f);
  426. Error += G == -2.0f ? 0 : 1;
  427. }
  428. {
  429. float A = glm::roundEven(1.5f);
  430. Error += A == 2.0f ? 0 : 1;
  431. float B = glm::roundEven(2.5f);
  432. Error += B == 2.0f ? 0 : 1;
  433. float C = glm::roundEven(3.5f);
  434. Error += C == 4.0f ? 0 : 1;
  435. float D = glm::roundEven(4.5f);
  436. Error += D == 4.0f ? 0 : 1;
  437. float E = glm::roundEven(5.5f);
  438. Error += E == 6.0f ? 0 : 1;
  439. float F = glm::roundEven(6.5f);
  440. Error += F == 6.0f ? 0 : 1;
  441. float G = glm::roundEven(7.5f);
  442. Error += G == 8.0f ? 0 : 1;
  443. }
  444. {
  445. float A = glm::roundEven(-1.5f);
  446. Error += A == -2.0f ? 0 : 1;
  447. float B = glm::roundEven(-2.5f);
  448. Error += B == -2.0f ? 0 : 1;
  449. float C = glm::roundEven(-3.5f);
  450. Error += C == -4.0f ? 0 : 1;
  451. float D = glm::roundEven(-4.5f);
  452. Error += D == -4.0f ? 0 : 1;
  453. float E = glm::roundEven(-5.5f);
  454. Error += E == -6.0f ? 0 : 1;
  455. float F = glm::roundEven(-6.5f);
  456. Error += F == -6.0f ? 0 : 1;
  457. float G = glm::roundEven(-7.5f);
  458. Error += G == -8.0f ? 0 : 1;
  459. }
  460. return Error;
  461. }
  462. int test_isnan()
  463. {
  464. int Error = 0;
  465. float Zero_f = 0.0;
  466. double Zero_d = 0.0;
  467. {
  468. Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
  469. Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
  470. Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
  471. Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
  472. }
  473. {
  474. Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
  475. Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
  476. Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
  477. Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
  478. }
  479. return Error;
  480. }
  481. int test_isinf()
  482. {
  483. int Error = 0;
  484. float Zero_f = 0.0;
  485. double Zero_d = 0.0;
  486. {
  487. Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
  488. Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
  489. Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
  490. Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
  491. Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
  492. Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
  493. Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
  494. Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
  495. }
  496. {
  497. Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
  498. Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
  499. Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
  500. Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
  501. Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
  502. Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
  503. Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
  504. Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
  505. }
  506. return Error;
  507. }
  508. int main()
  509. {
  510. int Error(0);
  511. Error += test_modf();
  512. Error += test_floatBitsToInt();
  513. Error += test_floatBitsToUint();
  514. Error += test_mix::run();
  515. Error += test_round();
  516. Error += test_roundEven();
  517. Error += test_isnan();
  518. //Error += test_isinf();
  519. return Error;
  520. }