core_func_common.cpp 16 KB

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