core_func_common.cpp 34 KB

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