core_func_common.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// Restrictions:
  16. /// By making use of the Software for military purposes, you choose to make
  17. /// a Bunny unhappy.
  18. ///
  19. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. /// THE SOFTWARE.
  26. ///
  27. /// @file test/core/func_common.cpp
  28. /// @date 2011-01-15 / 2011-09-13
  29. /// @author Christophe Riccio
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #define GLM_FORCE_EXPLICIT_CTOR
  32. #include <glm/common.hpp>
  33. #include <glm/gtc/constants.hpp>
  34. #include <glm/gtc/epsilon.hpp>
  35. #include <glm/gtc/vec1.hpp>
  36. #include <glm/gtc/random.hpp>
  37. #include <vector>
  38. #include <cstdio>
  39. #include <cmath>
  40. #include <ctime>
  41. namespace floor_
  42. {
  43. int test()
  44. {
  45. int Error(0);
  46. {
  47. float A(1.1f);
  48. float B = glm::floor(A);
  49. }
  50. {
  51. double A(1.1f);
  52. double B = glm::floor(A);
  53. }
  54. {
  55. glm::vec1 A(1.1f);
  56. glm::vec1 B = glm::floor(A);
  57. Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.0), 0.0001f)) ? 0 : 1;
  58. }
  59. {
  60. glm::dvec1 A(1.1f);
  61. glm::dvec1 B = glm::floor(A);
  62. Error += glm::all(glm::epsilonEqual(B, glm::dvec1(1.0), 0.0001)) ? 0 : 1;
  63. }
  64. {
  65. glm::vec2 A(1.1f);
  66. glm::vec2 B = glm::floor(A);
  67. Error += glm::all(glm::epsilonEqual(B, glm::vec2(1.0), 0.0001f)) ? 0 : 1;
  68. }
  69. {
  70. glm::dvec2 A(1.1f);
  71. glm::dvec2 B = glm::floor(A);
  72. Error += glm::all(glm::epsilonEqual(B, glm::dvec2(1.0), 0.0001)) ? 0 : 1;
  73. }
  74. {
  75. glm::vec3 A(1.1f);
  76. glm::vec3 B = glm::floor(A);
  77. Error += glm::all(glm::epsilonEqual(B, glm::vec3(1.0), 0.0001f)) ? 0 : 1;
  78. }
  79. {
  80. glm::dvec3 A(1.1f);
  81. glm::dvec3 B = glm::floor(A);
  82. Error += glm::all(glm::epsilonEqual(B, glm::dvec3(1.0), 0.0001)) ? 0 : 1;
  83. }
  84. {
  85. glm::vec4 A(1.1f);
  86. glm::vec4 B = glm::floor(A);
  87. Error += glm::all(glm::epsilonEqual(B, glm::vec4(1.0), 0.0001f)) ? 0 : 1;
  88. }
  89. {
  90. glm::dvec4 A(1.1f);
  91. glm::dvec4 B = glm::floor(A);
  92. Error += glm::all(glm::epsilonEqual(B, glm::dvec4(1.0), 0.0001)) ? 0 : 1;
  93. }
  94. return Error;
  95. }
  96. }//namespace floor
  97. namespace modf_
  98. {
  99. int test()
  100. {
  101. int Error(0);
  102. {
  103. float X(1.5f);
  104. float I(0.0f);
  105. float A = glm::modf(X, I);
  106. Error += I == 1.0f ? 0 : 1;
  107. Error += A == 0.5f ? 0 : 1;
  108. }
  109. {
  110. glm::vec4 X(1.1f, 1.2f, 1.5f, 1.7f);
  111. glm::vec4 I(0.0f);
  112. glm::vec4 A = glm::modf(X, I);
  113. Error += I == glm::vec4(1.0f) ? 0 : 1;
  114. Error += glm::all(glm::epsilonEqual(A, glm::vec4(0.1f, 0.2f, 0.5f, 0.7f), 0.00001f)) ? 0 : 1;
  115. }
  116. {
  117. glm::dvec4 X(1.1, 1.2, 1.5, 1.7);
  118. glm::dvec4 I(0.0);
  119. glm::dvec4 A = glm::modf(X, I);
  120. Error += I == glm::dvec4(1.0) ? 0 : 1;
  121. Error += glm::all(glm::epsilonEqual(A, glm::dvec4(0.1, 0.2, 0.5, 0.7), 0.000000001)) ? 0 : 1;
  122. }
  123. {
  124. double X(1.5);
  125. double I(0.0);
  126. double A = glm::modf(X, I);
  127. Error += I == 1.0 ? 0 : 1;
  128. Error += A == 0.5 ? 0 : 1;
  129. }
  130. return Error;
  131. }
  132. }//namespace modf
  133. namespace mod_
  134. {
  135. int test()
  136. {
  137. int Error(0);
  138. {
  139. float A(3.0);
  140. float B(2.0f);
  141. float C = glm::mod(A, B);
  142. Error += glm::abs(C - 1.0f) < 0.00001f ? 0 : 1;
  143. }
  144. {
  145. glm::vec4 A(3.0);
  146. float B(2.0f);
  147. glm::vec4 C = glm::mod(A, B);
  148. Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
  149. }
  150. {
  151. glm::vec4 A(3.0);
  152. glm::vec4 B(2.0f);
  153. glm::vec4 C = glm::mod(A, B);
  154. Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
  155. }
  156. return Error;
  157. }
  158. }//namespace mod_
  159. namespace floatBitsToInt
  160. {
  161. int test()
  162. {
  163. int Error = 0;
  164. {
  165. float A = 1.0f;
  166. int B = glm::floatBitsToInt(A);
  167. float C = glm::intBitsToFloat(B);
  168. int D = *(int*)&A;
  169. Error += B == D ? 0 : 1;
  170. Error += A == C ? 0 : 1;
  171. }
  172. {
  173. glm::vec2 A(1.0f, 2.0f);
  174. glm::ivec2 B = glm::floatBitsToInt(A);
  175. glm::vec2 C = glm::intBitsToFloat(B);
  176. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  177. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  178. Error += A == C? 0 : 1;
  179. }
  180. {
  181. glm::vec3 A(1.0f, 2.0f, 3.0f);
  182. glm::ivec3 B = glm::floatBitsToInt(A);
  183. glm::vec3 C = glm::intBitsToFloat(B);
  184. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  185. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  186. Error += B.z == *(int*)&(A.z) ? 0 : 1;
  187. Error += A == C? 0 : 1;
  188. }
  189. {
  190. glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
  191. glm::ivec4 B = glm::floatBitsToInt(A);
  192. glm::vec4 C = glm::intBitsToFloat(B);
  193. Error += B.x == *(int*)&(A.x) ? 0 : 1;
  194. Error += B.y == *(int*)&(A.y) ? 0 : 1;
  195. Error += B.z == *(int*)&(A.z) ? 0 : 1;
  196. Error += B.w == *(int*)&(A.w) ? 0 : 1;
  197. Error += A == C? 0 : 1;
  198. }
  199. return Error;
  200. }
  201. }//namespace floatBitsToInt
  202. namespace floatBitsToUint
  203. {
  204. int test()
  205. {
  206. int Error = 0;
  207. {
  208. float A = 1.0f;
  209. glm::uint B = glm::floatBitsToUint(A);
  210. float C = glm::intBitsToFloat(B);
  211. Error += B == *(glm::uint*)&A ? 0 : 1;
  212. Error += A == C? 0 : 1;
  213. }
  214. {
  215. glm::vec2 A(1.0f, 2.0f);
  216. glm::uvec2 B = glm::floatBitsToUint(A);
  217. glm::vec2 C = glm::uintBitsToFloat(B);
  218. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  219. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  220. Error += A == C ? 0 : 1;
  221. }
  222. {
  223. glm::vec3 A(1.0f, 2.0f, 3.0f);
  224. glm::uvec3 B = glm::floatBitsToUint(A);
  225. glm::vec3 C = glm::uintBitsToFloat(B);
  226. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  227. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  228. Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
  229. Error += A == C? 0 : 1;
  230. }
  231. {
  232. glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
  233. glm::uvec4 B = glm::floatBitsToUint(A);
  234. glm::vec4 C = glm::uintBitsToFloat(B);
  235. Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1;
  236. Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1;
  237. Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1;
  238. Error += B.w == *(glm::uint*)&(A.w) ? 0 : 1;
  239. Error += A == C? 0 : 1;
  240. }
  241. return Error;
  242. }
  243. }//namespace floatBitsToUint
  244. namespace min_
  245. {
  246. int test()
  247. {
  248. int Error = 0;
  249. glm::vec1 A0 = glm::min(glm::vec1(1), glm::vec1(1));
  250. glm::vec2 B0 = glm::min(glm::vec2(1), glm::vec2(1));
  251. glm::vec2 B1 = glm::min(glm::vec2(1), 1.0f);
  252. bool B2 = glm::all(glm::equal(B0, B1));
  253. Error += B2 ? 0 : 1;
  254. glm::vec3 C0 = glm::min(glm::vec3(1), glm::vec3(1));
  255. glm::vec3 C1 = glm::min(glm::vec3(1), 1.0f);
  256. bool C2 = glm::all(glm::equal(C0, C1));
  257. Error += C2 ? 0 : 1;
  258. glm::vec4 D0 = glm::min(glm::vec4(1), glm::vec4(1));
  259. glm::vec4 D1 = glm::min(glm::vec4(1), 1.0f);
  260. bool D2 = glm::all(glm::equal(D0, D1));
  261. Error += D2 ? 0 : 1;
  262. return Error;
  263. }
  264. }//namespace min_
  265. namespace max_
  266. {
  267. int test()
  268. {
  269. int Error = 0;
  270. glm::vec1 A0 = glm::max(glm::vec1(1), glm::vec1(1));
  271. glm::vec2 B0 = glm::max(glm::vec2(1), glm::vec2(1));
  272. glm::vec2 B1 = glm::max(glm::vec2(1), 1.0f);
  273. bool B2 = glm::all(glm::equal(B0, B1));
  274. Error += B2 ? 0 : 1;
  275. glm::vec3 C0 = glm::max(glm::vec3(1), glm::vec3(1));
  276. glm::vec3 C1 = glm::max(glm::vec3(1), 1.0f);
  277. bool C2 = glm::all(glm::equal(C0, C1));
  278. Error += C2 ? 0 : 1;
  279. glm::vec4 D0 = glm::max(glm::vec4(1), glm::vec4(1));
  280. glm::vec4 D1 = glm::max(glm::vec4(1), 1.0f);
  281. bool D2 = glm::all(glm::equal(D0, D1));
  282. Error += D2 ? 0 : 1;
  283. return Error;
  284. }
  285. }//namespace max_
  286. namespace clamp_
  287. {
  288. int test()
  289. {
  290. int Error = 0;
  291. return Error;
  292. }
  293. }//namespace clamp_
  294. namespace mix_
  295. {
  296. template <typename T, typename B>
  297. struct entry
  298. {
  299. T x;
  300. T y;
  301. B a;
  302. T Result;
  303. };
  304. entry<float, bool> TestBool[] =
  305. {
  306. {0.0f, 1.0f, false, 0.0f},
  307. {0.0f, 1.0f, true, 1.0f},
  308. {-1.0f, 1.0f, false, -1.0f},
  309. {-1.0f, 1.0f, true, 1.0f}
  310. };
  311. entry<float, float> TestFloat[] =
  312. {
  313. {0.0f, 1.0f, 0.0f, 0.0f},
  314. {0.0f, 1.0f, 1.0f, 1.0f},
  315. {-1.0f, 1.0f, 0.0f, -1.0f},
  316. {-1.0f, 1.0f, 1.0f, 1.0f}
  317. };
  318. entry<glm::vec2, bool> TestVec2Bool[] =
  319. {
  320. {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
  321. {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
  322. {glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)},
  323. {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
  324. };
  325. entry<glm::vec2, glm::bvec2> TestBVec2[] =
  326. {
  327. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
  328. {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  329. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)},
  330. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
  331. {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
  332. };
  333. entry<glm::vec3, bool> TestVec3Bool[] =
  334. {
  335. {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
  336. {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
  337. {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)},
  338. {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
  339. };
  340. entry<glm::vec3, glm::bvec3> TestBVec3[] =
  341. {
  342. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
  343. {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  344. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)},
  345. {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
  346. {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)}
  347. };
  348. entry<glm::vec4, bool> TestVec4Bool[] =
  349. {
  350. {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
  351. {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
  352. {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)},
  353. {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
  354. };
  355. entry<glm::vec4, glm::bvec4> TestBVec4[] =
  356. {
  357. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)},
  358. {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  359. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)},
  360. {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
  361. {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)}
  362. };
  363. int test()
  364. {
  365. int Error = 0;
  366. // Float with bool
  367. {
  368. for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(entry<float, bool>); ++i)
  369. {
  370. float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
  371. Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
  372. }
  373. }
  374. // Float with float
  375. {
  376. for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(entry<float, float>); ++i)
  377. {
  378. float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
  379. Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
  380. }
  381. }
  382. // vec2 with bool
  383. {
  384. for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(entry<glm::vec2, bool>); ++i)
  385. {
  386. glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
  387. Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  388. Error += glm::epsilonEqual(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  389. }
  390. }
  391. // vec2 with bvec2
  392. {
  393. for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(entry<glm::vec2, glm::bvec2>); ++i)
  394. {
  395. glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
  396. Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  397. Error += glm::epsilonEqual(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  398. }
  399. }
  400. // vec3 with bool
  401. {
  402. for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(entry<glm::vec3, bool>); ++i)
  403. {
  404. glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
  405. Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  406. Error += glm::epsilonEqual(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  407. Error += glm::epsilonEqual(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  408. }
  409. }
  410. // vec3 with bvec3
  411. {
  412. for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(entry<glm::vec3, glm::bvec3>); ++i)
  413. {
  414. glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
  415. Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  416. Error += glm::epsilonEqual(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  417. Error += glm::epsilonEqual(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  418. }
  419. }
  420. // vec4 with bool
  421. {
  422. for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(entry<glm::vec4, bool>); ++i)
  423. {
  424. glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
  425. Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  426. Error += glm::epsilonEqual(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  427. Error += glm::epsilonEqual(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  428. Error += glm::epsilonEqual(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  429. }
  430. }
  431. // vec4 with bvec4
  432. {
  433. for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(entry<glm::vec4, glm::bvec4>); ++i)
  434. {
  435. glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
  436. Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
  437. Error += glm::epsilonEqual(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
  438. Error += glm::epsilonEqual(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
  439. Error += glm::epsilonEqual(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
  440. }
  441. }
  442. return Error;
  443. }
  444. }//namespace mix_
  445. namespace step_
  446. {
  447. template <typename EDGE, typename VEC>
  448. struct entry
  449. {
  450. EDGE edge;
  451. VEC x;
  452. VEC result;
  453. };
  454. entry<float, glm::vec4> TestVec4Scalar [] =
  455. {
  456. { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  457. { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  458. { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
  459. };
  460. entry<glm::vec4, glm::vec4> TestVec4Vector [] =
  461. {
  462. { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
  463. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
  464. { glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
  465. { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
  466. };
  467. int test()
  468. {
  469. int Error = 0;
  470. // vec4 and float
  471. {
  472. for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(entry<float, glm::vec4>); ++i)
  473. {
  474. glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
  475. Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
  476. }
  477. }
  478. // vec4 and vec4
  479. {
  480. for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(entry<glm::vec4, glm::vec4>); ++i)
  481. {
  482. glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
  483. Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
  484. }
  485. }
  486. return Error;
  487. }
  488. }//namespace step_
  489. namespace round_
  490. {
  491. int test()
  492. {
  493. int Error = 0;
  494. {
  495. float A = glm::round(0.0f);
  496. Error += A == 0.0f ? 0 : 1;
  497. float B = glm::round(0.5f);
  498. Error += B == 1.0f ? 0 : 1;
  499. float C = glm::round(1.0f);
  500. Error += C == 1.0f ? 0 : 1;
  501. float D = glm::round(0.1f);
  502. Error += D == 0.0f ? 0 : 1;
  503. float E = glm::round(0.9f);
  504. Error += E == 1.0f ? 0 : 1;
  505. float F = glm::round(1.5f);
  506. Error += F == 2.0f ? 0 : 1;
  507. float G = glm::round(1.9f);
  508. Error += G == 2.0f ? 0 : 1;
  509. }
  510. {
  511. float A = glm::round(-0.0f);
  512. Error += A == 0.0f ? 0 : 1;
  513. float B = glm::round(-0.5f);
  514. Error += B == -1.0f ? 0 : 1;
  515. float C = glm::round(-1.0f);
  516. Error += C == -1.0f ? 0 : 1;
  517. float D = glm::round(-0.1f);
  518. Error += D == 0.0f ? 0 : 1;
  519. float E = glm::round(-0.9f);
  520. Error += E == -1.0f ? 0 : 1;
  521. float F = glm::round(-1.5f);
  522. Error += F == -2.0f ? 0 : 1;
  523. float G = glm::round(-1.9f);
  524. Error += G == -2.0f ? 0 : 1;
  525. }
  526. return Error;
  527. }
  528. }//namespace round_
  529. namespace roundEven
  530. {
  531. int test()
  532. {
  533. int Error = 0;
  534. {
  535. float A1 = glm::roundEven(-1.5f);
  536. Error += glm::epsilonEqual(A1, -2.0f, 0.0001f) ? 0 : 1;
  537. float A2 = glm::roundEven(1.5f);
  538. Error += glm::epsilonEqual(A2, 2.0f, 0.0001f) ? 0 : 1;
  539. float A5 = glm::roundEven(-2.5f);
  540. Error += glm::epsilonEqual(A5, -2.0f, 0.0001f) ? 0 : 1;
  541. float A6 = glm::roundEven(2.5f);
  542. Error += glm::epsilonEqual(A6, 2.0f, 0.0001f) ? 0 : 1;
  543. float A3 = glm::roundEven(-3.5f);
  544. Error += glm::epsilonEqual(A3, -4.0f, 0.0001f) ? 0 : 1;
  545. float A4 = glm::roundEven(3.5f);
  546. Error += glm::epsilonEqual(A4, 4.0f, 0.0001f) ? 0 : 1;
  547. float C7 = glm::roundEven(-4.5f);
  548. Error += glm::epsilonEqual(C7, -4.0f, 0.0001f) ? 0 : 1;
  549. float C8 = glm::roundEven(4.5f);
  550. Error += glm::epsilonEqual(C8, 4.0f, 0.0001f) ? 0 : 1;
  551. float C1 = glm::roundEven(-5.5f);
  552. Error += glm::epsilonEqual(C1, -6.0f, 0.0001f) ? 0 : 1;
  553. float C2 = glm::roundEven(5.5f);
  554. Error += glm::epsilonEqual(C2, 6.0f, 0.0001f) ? 0 : 1;
  555. float C3 = glm::roundEven(-6.5f);
  556. Error += glm::epsilonEqual(C3, -6.0f, 0.0001f) ? 0 : 1;
  557. float C4 = glm::roundEven(6.5f);
  558. Error += glm::epsilonEqual(C4, 6.0f, 0.0001f) ? 0 : 1;
  559. float C5 = glm::roundEven(-7.5f);
  560. Error += glm::epsilonEqual(C5, -8.0f, 0.0001f) ? 0 : 1;
  561. float C6 = glm::roundEven(7.5f);
  562. Error += glm::epsilonEqual(C6, 8.0f, 0.0001f) ? 0 : 1;
  563. Error += 0;
  564. }
  565. {
  566. float A7 = glm::roundEven(-2.4f);
  567. Error += glm::epsilonEqual(A7, -2.0f, 0.0001f) ? 0 : 1;
  568. float A8 = glm::roundEven(2.4f);
  569. Error += glm::epsilonEqual(A8, 2.0f, 0.0001f) ? 0 : 1;
  570. float B1 = glm::roundEven(-2.6f);
  571. Error += glm::epsilonEqual(B1, -3.0f, 0.0001f) ? 0 : 1;
  572. float B2 = glm::roundEven(2.6f);
  573. Error += glm::epsilonEqual(B2, 3.0f, 0.0001f) ? 0 : 1;
  574. float B3 = glm::roundEven(-2.0f);
  575. Error += glm::epsilonEqual(B3, -2.0f, 0.0001f) ? 0 : 1;
  576. float B4 = glm::roundEven(2.0f);
  577. Error += glm::epsilonEqual(B4, 2.0f, 0.0001f) ? 0 : 1;
  578. Error += 0;
  579. }
  580. {
  581. float A = glm::roundEven(0.0f);
  582. Error += A == 0.0f ? 0 : 1;
  583. float B = glm::roundEven(0.5f);
  584. Error += B == 0.0f ? 0 : 1;
  585. float C = glm::roundEven(1.0f);
  586. Error += C == 1.0f ? 0 : 1;
  587. float D = glm::roundEven(0.1f);
  588. Error += D == 0.0f ? 0 : 1;
  589. float E = glm::roundEven(0.9f);
  590. Error += E == 1.0f ? 0 : 1;
  591. float F = glm::roundEven(1.5f);
  592. Error += F == 2.0f ? 0 : 1;
  593. float G = glm::roundEven(1.9f);
  594. Error += G == 2.0f ? 0 : 1;
  595. }
  596. {
  597. float A = glm::roundEven(-0.0f);
  598. Error += A == 0.0f ? 0 : 1;
  599. float B = glm::roundEven(-0.5f);
  600. Error += B == -0.0f ? 0 : 1;
  601. float C = glm::roundEven(-1.0f);
  602. Error += C == -1.0f ? 0 : 1;
  603. float D = glm::roundEven(-0.1f);
  604. Error += D == 0.0f ? 0 : 1;
  605. float E = glm::roundEven(-0.9f);
  606. Error += E == -1.0f ? 0 : 1;
  607. float F = glm::roundEven(-1.5f);
  608. Error += F == -2.0f ? 0 : 1;
  609. float G = glm::roundEven(-1.9f);
  610. Error += G == -2.0f ? 0 : 1;
  611. }
  612. {
  613. float A = glm::roundEven(1.5f);
  614. Error += A == 2.0f ? 0 : 1;
  615. float B = glm::roundEven(2.5f);
  616. Error += B == 2.0f ? 0 : 1;
  617. float C = glm::roundEven(3.5f);
  618. Error += C == 4.0f ? 0 : 1;
  619. float D = glm::roundEven(4.5f);
  620. Error += D == 4.0f ? 0 : 1;
  621. float E = glm::roundEven(5.5f);
  622. Error += E == 6.0f ? 0 : 1;
  623. float F = glm::roundEven(6.5f);
  624. Error += F == 6.0f ? 0 : 1;
  625. float G = glm::roundEven(7.5f);
  626. Error += G == 8.0f ? 0 : 1;
  627. }
  628. {
  629. float A = glm::roundEven(-1.5f);
  630. Error += A == -2.0f ? 0 : 1;
  631. float B = glm::roundEven(-2.5f);
  632. Error += B == -2.0f ? 0 : 1;
  633. float C = glm::roundEven(-3.5f);
  634. Error += C == -4.0f ? 0 : 1;
  635. float D = glm::roundEven(-4.5f);
  636. Error += D == -4.0f ? 0 : 1;
  637. float E = glm::roundEven(-5.5f);
  638. Error += E == -6.0f ? 0 : 1;
  639. float F = glm::roundEven(-6.5f);
  640. Error += F == -6.0f ? 0 : 1;
  641. float G = glm::roundEven(-7.5f);
  642. Error += G == -8.0f ? 0 : 1;
  643. }
  644. return Error;
  645. }
  646. }//namespace roundEven
  647. namespace isnan_
  648. {
  649. int test()
  650. {
  651. int Error = 0;
  652. float Zero_f = 0.0;
  653. double Zero_d = 0.0;
  654. {
  655. Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
  656. Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
  657. Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
  658. Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
  659. }
  660. {
  661. Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
  662. Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
  663. Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
  664. Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
  665. }
  666. return Error;
  667. }
  668. }//namespace isnan_
  669. namespace isinf_
  670. {
  671. int test()
  672. {
  673. int Error = 0;
  674. float Zero_f = 0.0;
  675. double Zero_d = 0.0;
  676. {
  677. Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
  678. Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
  679. Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
  680. Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
  681. Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
  682. Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
  683. Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
  684. Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
  685. }
  686. {
  687. Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
  688. Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
  689. Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
  690. Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
  691. Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
  692. Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
  693. Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
  694. Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
  695. }
  696. return Error;
  697. }
  698. }//namespace isinf_
  699. namespace sign
  700. {
  701. template <typename genFIType>
  702. GLM_FUNC_QUALIFIER genFIType sign_if(genFIType x)
  703. {
  704. GLM_STATIC_ASSERT(
  705. std::numeric_limits<genFIType>::is_iec559 ||
  706. (std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), "'sign' only accept signed inputs");
  707. genFIType result;
  708. if(x > genFIType(0))
  709. result = genFIType(1);
  710. else if(x < genFIType(0))
  711. result = genFIType(-1);
  712. else
  713. result = genFIType(0);
  714. return result;
  715. }
  716. template <typename genFIType>
  717. GLM_FUNC_QUALIFIER genFIType sign_alu1(genFIType x)
  718. {
  719. GLM_STATIC_ASSERT(
  720. std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
  721. "'sign' only accept integer inputs");
  722. return (x >> 31) | ((unsigned)-x >> 31);
  723. }
  724. template <typename genFIType>
  725. GLM_FUNC_QUALIFIER genFIType sign_alu2(genFIType x)
  726. {
  727. GLM_STATIC_ASSERT(
  728. std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
  729. "'sign' only accept integer inputs");
  730. return -((unsigned)x >> 31) | (-(unsigned)x >> 31);
  731. }
  732. template <typename genFIType>
  733. GLM_FUNC_QUALIFIER genFIType sign_sub(genFIType x)
  734. {
  735. GLM_STATIC_ASSERT(
  736. std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
  737. "'sign' only accept integer inputs");
  738. return ((unsigned)-x >> 31) - ((unsigned)x >> 31);
  739. }
  740. template <typename genFIType>
  741. GLM_FUNC_QUALIFIER genFIType sign_cmp(genFIType x)
  742. {
  743. GLM_STATIC_ASSERT(
  744. std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
  745. "'sign' only accept integer inputs");
  746. return (x > 0) - (x < 0);
  747. }
  748. template <typename genType>
  749. struct type
  750. {
  751. genType Value;
  752. genType Return;
  753. };
  754. int test_int32()
  755. {
  756. type<glm::int32> const Data[] =
  757. {
  758. { std::numeric_limits<glm::int32>::max(), 1},
  759. { std::numeric_limits<glm::int32>::min(), -1},
  760. { 0, 0},
  761. { 1, 1},
  762. { 2, 1},
  763. { 3, 1},
  764. {-1,-1},
  765. {-2,-1},
  766. {-3,-1}
  767. };
  768. int Error = 0;
  769. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
  770. {
  771. glm::int32 Result = glm::sign(Data[i].Value);
  772. Error += Data[i].Return == Result ? 0 : 1;
  773. }
  774. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
  775. {
  776. glm::int32 Result = sign_cmp(Data[i].Value);
  777. Error += Data[i].Return == Result ? 0 : 1;
  778. }
  779. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
  780. {
  781. glm::int32 Result = sign_if(Data[i].Value);
  782. Error += Data[i].Return == Result ? 0 : 1;
  783. }
  784. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
  785. {
  786. glm::int32 Result = sign_alu1(Data[i].Value);
  787. Error += Data[i].Return == Result ? 0 : 1;
  788. }
  789. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
  790. {
  791. glm::int32 Result = sign_alu2(Data[i].Value);
  792. Error += Data[i].Return == Result ? 0 : 1;
  793. }
  794. return Error;
  795. }
  796. int test_i32vec4()
  797. {
  798. type<glm::i32vec4> const Data[] =
  799. {
  800. {glm::i32vec4( 1), glm::i32vec4( 1)},
  801. {glm::i32vec4( 0), glm::i32vec4( 0)},
  802. {glm::i32vec4( 2), glm::i32vec4( 1)},
  803. {glm::i32vec4( 3), glm::i32vec4( 1)},
  804. {glm::i32vec4(-1), glm::i32vec4(-1)},
  805. {glm::i32vec4(-2), glm::i32vec4(-1)},
  806. {glm::i32vec4(-3), glm::i32vec4(-1)}
  807. };
  808. int Error = 0;
  809. for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::i32vec4>); ++i)
  810. {
  811. glm::i32vec4 Result = glm::sign(Data[i].Value);
  812. Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
  813. }
  814. return Error;
  815. }
  816. int test()
  817. {
  818. int Error = 0;
  819. Error += test_int32();
  820. Error += test_i32vec4();
  821. return Error;
  822. }
  823. int perf_rand()
  824. {
  825. int Error = 0;
  826. std::size_t const Count = 100000000;
  827. std::vector<glm::int32> Input, Output;
  828. Input.resize(Count);
  829. Output.resize(Count);
  830. for(std::size_t i = 0; i < Count; ++i)
  831. Input[i] = static_cast<glm::int32>(glm::linearRand(-65536.f, 65536.f));
  832. std::clock_t Timestamp0 = std::clock();
  833. for(std::size_t i = 0; i < Count; ++i)
  834. Output[i] = sign_cmp(Input[i]);
  835. std::clock_t Timestamp1 = std::clock();
  836. for(std::size_t i = 0; i < Count; ++i)
  837. Output[i] = sign_if(Input[i]);
  838. std::clock_t Timestamp2 = std::clock();
  839. for(std::size_t i = 0; i < Count; ++i)
  840. Output[i] = sign_alu1(Input[i]);
  841. std::clock_t Timestamp3 = std::clock();
  842. for(std::size_t i = 0; i < Count; ++i)
  843. Output[i] = sign_alu2(Input[i]);
  844. std::clock_t Timestamp4 = std::clock();
  845. for(std::size_t i = 0; i < Count; ++i)
  846. Output[i] = sign_sub(Input[i]);
  847. std::clock_t Timestamp5 = std::clock();
  848. for(std::size_t i = 0; i < Count; ++i)
  849. Output[i] = glm::sign(Input[i]);
  850. std::clock_t Timestamp6 = std::clock();
  851. std::printf("sign_cmp(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  852. std::printf("sign_if(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  853. std::printf("sign_alu1(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  854. std::printf("sign_alu2(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  855. std::printf("sign_sub(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  856. std::printf("glm::sign(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp6 - Timestamp5));
  857. return Error;
  858. }
  859. int perf_linear()
  860. {
  861. int Error = 0;
  862. std::size_t const Count = 10000000;
  863. std::vector<glm::int32> Input, Output;
  864. Input.resize(Count);
  865. Output.resize(Count);
  866. for(std::size_t i = 0; i < Count; ++i)
  867. Input[i] = static_cast<glm::int32>(i);
  868. std::clock_t Timestamp0 = std::clock();
  869. for(std::size_t i = 0; i < Count; ++i)
  870. Output[i] = sign_cmp(Input[i]);
  871. std::clock_t Timestamp1 = std::clock();
  872. for(std::size_t i = 0; i < Count; ++i)
  873. Output[i] = sign_if(Input[i]);
  874. std::clock_t Timestamp2 = std::clock();
  875. for(std::size_t i = 0; i < Count; ++i)
  876. Output[i] = sign_alu1(Input[i]);
  877. std::clock_t Timestamp3 = std::clock();
  878. for(std::size_t i = 0; i < Count; ++i)
  879. Output[i] = sign_alu2(Input[i]);
  880. std::clock_t Timestamp4 = std::clock();
  881. for(std::size_t i = 0; i < Count; ++i)
  882. Output[i] = sign_sub(Input[i]);
  883. std::clock_t Timestamp5 = std::clock();
  884. std::printf("sign_cmp(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  885. std::printf("sign_if(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  886. std::printf("sign_alu1(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  887. std::printf("sign_alu2(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  888. std::printf("sign_sub(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  889. return Error;
  890. }
  891. int perf_linear_cal()
  892. {
  893. int Error = 0;
  894. glm::uint32 const Count = 10000000;
  895. std::clock_t Timestamp0 = std::clock();
  896. glm::int32 Sum = 0;
  897. for(glm::int32 i = 1; i < Count; ++i)
  898. Sum += sign_cmp(i);
  899. std::clock_t Timestamp1 = std::clock();
  900. for(glm::int32 i = 1; i < Count; ++i)
  901. Sum += sign_if(i);
  902. std::clock_t Timestamp2 = std::clock();
  903. for(glm::int32 i = 1; i < Count; ++i)
  904. Sum += sign_alu1(i);
  905. std::clock_t Timestamp3 = std::clock();
  906. for(glm::int32 i = 1; i < Count; ++i)
  907. Sum += sign_alu2(i);
  908. std::clock_t Timestamp4 = std::clock();
  909. for(glm::int32 i = 1; i < Count; ++i)
  910. Sum += sign_sub(i);
  911. std::clock_t Timestamp5 = std::clock();
  912. std::printf("Sum %d\n", static_cast<unsigned int>(Sum));
  913. std::printf("sign_cmp(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  914. std::printf("sign_if(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  915. std::printf("sign_alu1(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  916. std::printf("sign_alu2(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  917. std::printf("sign_sub(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  918. return Error;
  919. }
  920. int perf()
  921. {
  922. int Error(0);
  923. Error += perf_linear_cal();
  924. Error += perf_linear();
  925. Error += perf_rand();
  926. return Error;
  927. }
  928. }//namespace sign
  929. int main()
  930. {
  931. int Error(0);
  932. Error += sign::test();
  933. Error += floor_::test();
  934. Error += mod_::test();
  935. Error += modf_::test();
  936. Error += floatBitsToInt::test();
  937. Error += floatBitsToUint::test();
  938. Error += step_::test();
  939. Error += max_::test();
  940. Error += min_::test();
  941. Error += mix_::test();
  942. Error += round_::test();
  943. Error += roundEven::test();
  944. Error += isnan_::test();
  945. Error += isinf_::test();
  946. # ifdef NDEBUG
  947. Error += sign::perf();
  948. # endif
  949. return Error;
  950. }