core_func_common.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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. #if GLM_LANG >= GLM_LANG_CXX11
  437. float A1 = glm::round(0.0f);
  438. Error += A1 == A ? 0 : 1;
  439. float B1 = glm::round(0.5f);
  440. Error += B1 == B ? 0 : 1;
  441. float C1 = glm::round(1.0f);
  442. Error += C1 == C ? 0 : 1;
  443. float D1 = glm::round(0.1f);
  444. Error += D1 == D ? 0 : 1;
  445. float E1 = glm::round(0.9f);
  446. Error += E1 == E ? 0 : 1;
  447. float F1 = glm::round(1.5f);
  448. Error += F == F ? 0 : 1;
  449. float G1 = glm::round(1.9f);
  450. Error += G1 == G ? 0 : 1;
  451. #endif // GLM_LANG >= GLM_CXX0X
  452. }
  453. {
  454. float A = glm::round(-0.0f);
  455. Error += A == 0.0f ? 0 : 1;
  456. float B = glm::round(-0.5f);
  457. Error += B == -1.0f ? 0 : 1;
  458. float C = glm::round(-1.0f);
  459. Error += C == -1.0f ? 0 : 1;
  460. float D = glm::round(-0.1f);
  461. Error += D == 0.0f ? 0 : 1;
  462. float E = glm::round(-0.9f);
  463. Error += E == -1.0f ? 0 : 1;
  464. float F = glm::round(-1.5f);
  465. Error += F == -2.0f ? 0 : 1;
  466. float G = glm::round(-1.9f);
  467. Error += G == -2.0f ? 0 : 1;
  468. }
  469. return Error;
  470. }
  471. int test_roundEven()
  472. {
  473. int Error = 0;
  474. {
  475. float A = glm::roundEven(-1.5f);
  476. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  477. Error += 0;
  478. }
  479. {
  480. float A = glm::roundEven(1.5f);
  481. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  482. Error += 0;
  483. }
  484. {
  485. float A = glm::roundEven(-3.5f);
  486. Error += glm::epsilonEqual(A, -4.0f, 0.0001f) ? 0 : 1;
  487. Error += 0;
  488. }
  489. {
  490. float A = glm::roundEven(3.5f);
  491. Error += glm::epsilonEqual(A, 4.0f, 0.0001f) ? 0 : 1;
  492. Error += 0;
  493. }
  494. {
  495. float A = glm::roundEven(-2.5f);
  496. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  497. Error += 0;
  498. }
  499. {
  500. float A = glm::roundEven(2.5f);
  501. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  502. Error += 0;
  503. }
  504. {
  505. float A = glm::roundEven(-2.4f);
  506. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  507. Error += 0;
  508. }
  509. {
  510. float A = glm::roundEven(2.4f);
  511. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  512. Error += 0;
  513. }
  514. {
  515. float A = glm::roundEven(-2.6f);
  516. Error += glm::epsilonEqual(A, -3.0f, 0.0001f) ? 0 : 1;
  517. Error += 0;
  518. }
  519. {
  520. float A = glm::roundEven(2.6f);
  521. Error += glm::epsilonEqual(A, 3.0f, 0.0001f) ? 0 : 1;
  522. Error += 0;
  523. }
  524. {
  525. float A = glm::roundEven(-2.0f);
  526. Error += glm::epsilonEqual(A, -2.0f, 0.0001f) ? 0 : 1;
  527. Error += 0;
  528. }
  529. {
  530. float A = glm::roundEven(2.0f);
  531. Error += glm::epsilonEqual(A, 2.0f, 0.0001f) ? 0 : 1;
  532. Error += 0;
  533. }
  534. {
  535. float A = glm::roundEven(0.0f);
  536. Error += A == 0.0f ? 0 : 1;
  537. float B = glm::roundEven(0.5f);
  538. Error += B == 0.0f ? 0 : 1;
  539. float C = glm::roundEven(1.0f);
  540. Error += C == 1.0f ? 0 : 1;
  541. float D = glm::roundEven(0.1f);
  542. Error += D == 0.0f ? 0 : 1;
  543. float E = glm::roundEven(0.9f);
  544. Error += E == 1.0f ? 0 : 1;
  545. float F = glm::roundEven(1.5f);
  546. Error += F == 2.0f ? 0 : 1;
  547. float G = glm::roundEven(1.9f);
  548. Error += G == 2.0f ? 0 : 1;
  549. }
  550. {
  551. float A = glm::roundEven(-0.0f);
  552. Error += A == 0.0f ? 0 : 1;
  553. float B = glm::roundEven(-0.5f);
  554. Error += B == -0.0f ? 0 : 1;
  555. float C = glm::roundEven(-1.0f);
  556. Error += C == -1.0f ? 0 : 1;
  557. float D = glm::roundEven(-0.1f);
  558. Error += D == 0.0f ? 0 : 1;
  559. float E = glm::roundEven(-0.9f);
  560. Error += E == -1.0f ? 0 : 1;
  561. float F = glm::roundEven(-1.5f);
  562. Error += F == -2.0f ? 0 : 1;
  563. float G = glm::roundEven(-1.9f);
  564. Error += G == -2.0f ? 0 : 1;
  565. }
  566. {
  567. float A = glm::roundEven(1.5f);
  568. Error += A == 2.0f ? 0 : 1;
  569. float B = glm::roundEven(2.5f);
  570. Error += B == 2.0f ? 0 : 1;
  571. float C = glm::roundEven(3.5f);
  572. Error += C == 4.0f ? 0 : 1;
  573. float D = glm::roundEven(4.5f);
  574. Error += D == 4.0f ? 0 : 1;
  575. float E = glm::roundEven(5.5f);
  576. Error += E == 6.0f ? 0 : 1;
  577. float F = glm::roundEven(6.5f);
  578. Error += F == 6.0f ? 0 : 1;
  579. float G = glm::roundEven(7.5f);
  580. Error += G == 8.0f ? 0 : 1;
  581. }
  582. {
  583. float A = glm::roundEven(-1.5f);
  584. Error += A == -2.0f ? 0 : 1;
  585. float B = glm::roundEven(-2.5f);
  586. Error += B == -2.0f ? 0 : 1;
  587. float C = glm::roundEven(-3.5f);
  588. Error += C == -4.0f ? 0 : 1;
  589. float D = glm::roundEven(-4.5f);
  590. Error += D == -4.0f ? 0 : 1;
  591. float E = glm::roundEven(-5.5f);
  592. Error += E == -6.0f ? 0 : 1;
  593. float F = glm::roundEven(-6.5f);
  594. Error += F == -6.0f ? 0 : 1;
  595. float G = glm::roundEven(-7.5f);
  596. Error += G == -8.0f ? 0 : 1;
  597. }
  598. return Error;
  599. }
  600. int test_isnan()
  601. {
  602. int Error = 0;
  603. float Zero_f = 0.0;
  604. double Zero_d = 0.0;
  605. {
  606. Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
  607. Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
  608. Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
  609. Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
  610. }
  611. {
  612. Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
  613. Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
  614. Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
  615. Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
  616. }
  617. return Error;
  618. }
  619. int test_isinf()
  620. {
  621. int Error = 0;
  622. float Zero_f = 0.0;
  623. double Zero_d = 0.0;
  624. {
  625. Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
  626. Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
  627. Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
  628. Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
  629. Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
  630. Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
  631. Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
  632. Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
  633. }
  634. {
  635. Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
  636. Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
  637. Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
  638. Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
  639. Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
  640. Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
  641. Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
  642. Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
  643. }
  644. return Error;
  645. }
  646. int main()
  647. {
  648. int Error(0);
  649. Error += test_floor();
  650. Error += test_modf();
  651. Error += test_floatBitsToInt();
  652. Error += test_floatBitsToUint();
  653. Error += test_step::run();
  654. Error += test_max();
  655. Error += test_min();
  656. Error += test_mix::run();
  657. Error += test_round();
  658. Error += test_roundEven();
  659. Error += test_isnan();
  660. //Error += test_isinf();
  661. return Error;
  662. }