core_func_common.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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()
  799. {
  800. int Error = 0;
  801. Error += test_int32();
  802. Error += test_i32vec4();
  803. return Error;
  804. }
  805. int perf_rand(std::size_t Samples)
  806. {
  807. int Error = 0;
  808. std::size_t const Count = Samples;
  809. std::vector<glm::int32> Input, Output;
  810. Input.resize(Count);
  811. Output.resize(Count);
  812. for(std::size_t i = 0; i < Count; ++i)
  813. Input[i] = static_cast<glm::int32>(glm::linearRand(-65536.f, 65536.f));
  814. std::clock_t Timestamp0 = std::clock();
  815. for(std::size_t i = 0; i < Count; ++i)
  816. Output[i] = sign_cmp(Input[i]);
  817. std::clock_t Timestamp1 = std::clock();
  818. for(std::size_t i = 0; i < Count; ++i)
  819. Output[i] = sign_if(Input[i]);
  820. std::clock_t Timestamp2 = std::clock();
  821. for(std::size_t i = 0; i < Count; ++i)
  822. Output[i] = sign_alu1(Input[i]);
  823. std::clock_t Timestamp3 = std::clock();
  824. for(std::size_t i = 0; i < Count; ++i)
  825. Output[i] = sign_alu2(Input[i]);
  826. std::clock_t Timestamp4 = std::clock();
  827. for(std::size_t i = 0; i < Count; ++i)
  828. Output[i] = sign_sub(Input[i]);
  829. std::clock_t Timestamp5 = std::clock();
  830. for(std::size_t i = 0; i < Count; ++i)
  831. Output[i] = glm::sign(Input[i]);
  832. std::clock_t Timestamp6 = std::clock();
  833. std::printf("sign_cmp(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  834. std::printf("sign_if(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  835. std::printf("sign_alu1(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  836. std::printf("sign_alu2(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  837. std::printf("sign_sub(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  838. std::printf("glm::sign(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp6 - Timestamp5));
  839. return Error;
  840. }
  841. int perf_linear(std::size_t Samples)
  842. {
  843. int Error = 0;
  844. std::size_t const Count = Samples;
  845. std::vector<glm::int32> Input, Output;
  846. Input.resize(Count);
  847. Output.resize(Count);
  848. for(std::size_t i = 0; i < Count; ++i)
  849. Input[i] = static_cast<glm::int32>(i);
  850. std::clock_t Timestamp0 = std::clock();
  851. for(std::size_t i = 0; i < Count; ++i)
  852. Output[i] = sign_cmp(Input[i]);
  853. std::clock_t Timestamp1 = std::clock();
  854. for(std::size_t i = 0; i < Count; ++i)
  855. Output[i] = sign_if(Input[i]);
  856. std::clock_t Timestamp2 = std::clock();
  857. for(std::size_t i = 0; i < Count; ++i)
  858. Output[i] = sign_alu1(Input[i]);
  859. std::clock_t Timestamp3 = std::clock();
  860. for(std::size_t i = 0; i < Count; ++i)
  861. Output[i] = sign_alu2(Input[i]);
  862. std::clock_t Timestamp4 = std::clock();
  863. for(std::size_t i = 0; i < Count; ++i)
  864. Output[i] = sign_sub(Input[i]);
  865. std::clock_t Timestamp5 = std::clock();
  866. std::printf("sign_cmp(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  867. std::printf("sign_if(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  868. std::printf("sign_alu1(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  869. std::printf("sign_alu2(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  870. std::printf("sign_sub(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  871. return Error;
  872. }
  873. int perf_linear_cal(std::size_t Samples)
  874. {
  875. int Error = 0;
  876. glm::int32 const Count = static_cast<glm::int32>(Samples);
  877. std::clock_t Timestamp0 = std::clock();
  878. glm::int32 Sum = 0;
  879. for(glm::int32 i = 1; i < Count; ++i)
  880. Sum += sign_cmp(i);
  881. std::clock_t Timestamp1 = std::clock();
  882. for(glm::int32 i = 1; i < Count; ++i)
  883. Sum += sign_if(i);
  884. std::clock_t Timestamp2 = std::clock();
  885. for(glm::int32 i = 1; i < Count; ++i)
  886. Sum += sign_alu1(i);
  887. std::clock_t Timestamp3 = std::clock();
  888. for(glm::int32 i = 1; i < Count; ++i)
  889. Sum += sign_alu2(i);
  890. std::clock_t Timestamp4 = std::clock();
  891. for(glm::int32 i = 1; i < Count; ++i)
  892. Sum += sign_sub(i);
  893. std::clock_t Timestamp5 = std::clock();
  894. std::printf("Sum %d\n", static_cast<unsigned int>(Sum));
  895. std::printf("sign_cmp(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
  896. std::printf("sign_if(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
  897. std::printf("sign_alu1(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
  898. std::printf("sign_alu2(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
  899. std::printf("sign_sub(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
  900. return Error;
  901. }
  902. int perf(std::size_t Samples)
  903. {
  904. int Error(0);
  905. Error += perf_linear_cal(Samples);
  906. Error += perf_linear(Samples);
  907. Error += perf_rand(Samples);
  908. return Error;
  909. }
  910. }//namespace sign
  911. namespace frexp_
  912. {
  913. int test()
  914. {
  915. int Error(0);
  916. {
  917. glm::vec1 x(1024);
  918. glm::ivec1 exp;
  919. glm::vec1 A = glm::frexp(x, exp);
  920. Error += glm::all(glm::epsilonEqual(A, glm::vec1(0.5), 0.00001f)) ? 0 : 1;
  921. Error += glm::all(glm::equal(exp, glm::ivec1(11))) ? 0 : 1;
  922. }
  923. {
  924. glm::vec2 x(1024, 0.24);
  925. glm::ivec2 exp;
  926. glm::vec2 A = glm::frexp(x, exp);
  927. Error += glm::all(glm::epsilonEqual(A, glm::vec2(0.5, 0.96), 0.00001f)) ? 0 : 1;
  928. Error += glm::all(glm::equal(exp, glm::ivec2(11, -2))) ? 0 : 1;
  929. }
  930. {
  931. glm::vec3 x(1024, 0.24, 0);
  932. glm::ivec3 exp;
  933. glm::vec3 A = glm::frexp(x, exp);
  934. Error += glm::all(glm::epsilonEqual(A, glm::vec3(0.5, 0.96, 0.0), 0.00001f)) ? 0 : 1;
  935. Error += glm::all(glm::equal(exp, glm::ivec3(11, -2, 0))) ? 0 : 1;
  936. }
  937. {
  938. glm::vec4 x(1024, 0.24, 0, -1.33);
  939. glm::ivec4 exp;
  940. glm::vec4 A = glm::frexp(x, exp);
  941. Error += glm::all(glm::epsilonEqual(A, glm::vec4(0.5, 0.96, 0.0, -0.665), 0.00001f)) ? 0 : 1;
  942. Error += glm::all(glm::equal(exp, glm::ivec4(11, -2, 0, 1))) ? 0 : 1;
  943. }
  944. return Error;
  945. }
  946. }//namespace frexp_
  947. namespace ldexp_
  948. {
  949. int test()
  950. {
  951. int Error(0);
  952. {
  953. glm::vec1 A = glm::vec1(0.5);
  954. glm::ivec1 exp = glm::ivec1(11);
  955. glm::vec1 x = glm::ldexp(A, exp);
  956. Error += glm::all(glm::epsilonEqual(x, glm::vec1(1024),0.00001f)) ? 0 : 1;
  957. }
  958. {
  959. glm::vec2 A = glm::vec2(0.5, 0.96);
  960. glm::ivec2 exp = glm::ivec2(11, -2);
  961. glm::vec2 x = glm::ldexp(A, exp);
  962. Error += glm::all(glm::epsilonEqual(x, glm::vec2(1024, .24),0.00001f)) ? 0 : 1;
  963. }
  964. {
  965. glm::vec3 A = glm::vec3(0.5, 0.96, 0.0);
  966. glm::ivec3 exp = glm::ivec3(11, -2, 0);
  967. glm::vec3 x = glm::ldexp(A, exp);
  968. Error += glm::all(glm::epsilonEqual(x, glm::vec3(1024, .24, 0),0.00001f)) ? 0 : 1;
  969. }
  970. {
  971. glm::vec4 A = glm::vec4(0.5, 0.96, 0.0, -0.665);
  972. glm::ivec4 exp = glm::ivec4(11, -2, 0, 1);
  973. glm::vec4 x = glm::ldexp(A, exp);
  974. Error += glm::all(glm::epsilonEqual(x, glm::vec4(1024, .24, 0, -1.33),0.00001f)) ? 0 : 1;
  975. }
  976. return Error;
  977. }
  978. }//namespace ldexp_
  979. int main()
  980. {
  981. int Error = 0;
  982. glm::ivec4 const a(1);
  983. glm::ivec4 const b = ~a;
  984. glm::int32 const c(1);
  985. glm::int32 const d = ~c;
  986. # if GLM_ARCH & GLM_ARCH_AVX_BIT
  987. glm_vec4 const A = _mm_set_ps(4, 3, 2, 1);
  988. glm_vec4 const B = glm_vec4_swizzle_xyzw(A);
  989. glm_vec4 const C = _mm_permute_ps(A, _MM_SHUFFLE(3, 2, 1, 0));
  990. glm_vec4 const D = _mm_permute_ps(A, _MM_SHUFFLE(0, 1, 2, 3));
  991. glm_vec4 const E = _mm_shuffle_ps(A, A, _MM_SHUFFLE(0, 1, 2, 3));
  992. # endif
  993. Error += sign::test();
  994. Error += floor_::test();
  995. Error += mod_::test();
  996. Error += modf_::test();
  997. Error += floatBitsToInt::test();
  998. Error += floatBitsToUint::test();
  999. Error += mix_::test();
  1000. Error += step_::test();
  1001. Error += max_::test();
  1002. Error += min_::test();
  1003. Error += round_::test();
  1004. Error += roundEven::test();
  1005. Error += isnan_::test();
  1006. Error += isinf_::test();
  1007. Error += frexp_::test();
  1008. Error += ldexp_::test();
  1009. # ifdef NDEBUG
  1010. std::size_t Samples = 1000;
  1011. Error += sign::perf(Samples);
  1012. # endif
  1013. return Error;
  1014. }