core_func_common.cpp 33 KB

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