core_func_common.cpp 21 KB

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