| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259 |
- #define GLM_FORCE_EXPLICIT_CTOR
- #include <glm/common.hpp>
- #include <glm/gtc/constants.hpp>
- #include <glm/gtc/epsilon.hpp>
- #include <glm/gtc/vec1.hpp>
- #include <glm/gtc/random.hpp>
- #include <vector>
- #include <cstdio>
- #include <cmath>
- #include <ctime>
- namespace floor_
- {
- int test()
- {
- int Error(0);
- {
- float A = 1.1f;
- float B = glm::floor(A);
- Error += glm::epsilonEqual(B, 1.f, 0.0001f) ? 0 : 1;
- }
- {
- double A = 1.1;
- double B = glm::floor(A);
- Error += glm::epsilonEqual(B, 1.0, 0.0001) ? 0 : 1;
- }
- {
- glm::vec1 A(1.1f);
- glm::vec1 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.0), 0.0001f)) ? 0 : 1;
- }
- {
- glm::dvec1 A(1.1);
- glm::dvec1 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::dvec1(1.0), 0.0001)) ? 0 : 1;
- }
- {
- glm::vec2 A(1.1f);
- glm::vec2 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::vec2(1.0), 0.0001f)) ? 0 : 1;
- }
- {
- glm::dvec2 A(1.1);
- glm::dvec2 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::dvec2(1.0), 0.0001)) ? 0 : 1;
- }
- {
- glm::vec3 A(1.1f);
- glm::vec3 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::vec3(1.0), 0.0001f)) ? 0 : 1;
- }
- {
- glm::dvec3 A(1.1);
- glm::dvec3 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::dvec3(1.0), 0.0001)) ? 0 : 1;
- }
- {
- glm::vec4 A(1.1f);
- glm::vec4 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::vec4(1.0), 0.0001f)) ? 0 : 1;
- }
- {
- glm::dvec4 A(1.1);
- glm::dvec4 B = glm::floor(A);
- Error += glm::all(glm::epsilonEqual(B, glm::dvec4(1.0), 0.0001)) ? 0 : 1;
- }
- return Error;
- }
- }//namespace floor
- namespace modf_
- {
- int test()
- {
- int Error(0);
- {
- float X(1.5f);
- float I(0.0f);
- float A = glm::modf(X, I);
- Error += I == 1.0f ? 0 : 1;
- Error += A == 0.5f ? 0 : 1;
- }
- {
- glm::vec4 X(1.1f, 1.2f, 1.5f, 1.7f);
- glm::vec4 I(0.0f);
- glm::vec4 A = glm::modf(X, I);
- Error += I == glm::vec4(1.0f) ? 0 : 1;
- Error += glm::all(glm::epsilonEqual(A, glm::vec4(0.1f, 0.2f, 0.5f, 0.7f), 0.00001f)) ? 0 : 1;
- }
- {
- glm::dvec4 X(1.1, 1.2, 1.5, 1.7);
- glm::dvec4 I(0.0);
- glm::dvec4 A = glm::modf(X, I);
- Error += I == glm::dvec4(1.0) ? 0 : 1;
- Error += glm::all(glm::epsilonEqual(A, glm::dvec4(0.1, 0.2, 0.5, 0.7), 0.000000001)) ? 0 : 1;
- }
- {
- double X(1.5);
- double I(0.0);
- double A = glm::modf(X, I);
- Error += I == 1.0 ? 0 : 1;
- Error += A == 0.5 ? 0 : 1;
- }
- return Error;
- }
- }//namespace modf
- namespace mod_
- {
- int test()
- {
- int Error(0);
- {
- float A(1.5f);
- float B(1.0f);
- float C = glm::mod(A, B);
- Error += glm::abs(C - 0.5f) < 0.00001f ? 0 : 1;
- }
- {
- float A(-0.2f);
- float B(1.0f);
- float C = glm::mod(A, B);
- Error += glm::abs(C - 0.8f) < 0.00001f ? 0 : 1;
- }
- {
- float A(3.0);
- float B(2.0f);
- float C = glm::mod(A, B);
- Error += glm::abs(C - 1.0f) < 0.00001f ? 0 : 1;
- }
- {
- glm::vec4 A(3.0);
- float B(2.0f);
- glm::vec4 C = glm::mod(A, B);
- Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
- }
- {
- glm::vec4 A(3.0);
- glm::vec4 B(2.0f);
- glm::vec4 C = glm::mod(A, B);
- Error += glm::all(glm::epsilonEqual(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
- }
- return Error;
- }
- }//namespace mod_
- namespace floatBitsToInt
- {
- int test()
- {
- int Error = 0;
-
- {
- float A = 1.0f;
- int B = glm::floatBitsToInt(A);
- float C = glm::intBitsToFloat(B);
- Error += glm::epsilonEqual(A, C, 0.0001f) ? 0 : 1;
- }
- {
- glm::vec2 A(1.0f, 2.0f);
- glm::ivec2 B = glm::floatBitsToInt(A);
- glm::vec2 C = glm::intBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
- {
- glm::vec3 A(1.0f, 2.0f, 3.0f);
- glm::ivec3 B = glm::floatBitsToInt(A);
- glm::vec3 C = glm::intBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
-
- {
- glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
- glm::ivec4 B = glm::floatBitsToInt(A);
- glm::vec4 C = glm::intBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
-
- return Error;
- }
- }//namespace floatBitsToInt
- namespace floatBitsToUint
- {
- int test()
- {
- int Error = 0;
-
- {
- float A = 1.0f;
- glm::uint B = glm::floatBitsToUint(A);
- float C = glm::intBitsToFloat(B);
- Error += glm::epsilonEqual(A, C, 0.0001f) ? 0 : 1;
- }
-
- {
- glm::vec2 A(1.0f, 2.0f);
- glm::uvec2 B = glm::floatBitsToUint(A);
- glm::vec2 C = glm::uintBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
-
- {
- glm::vec3 A(1.0f, 2.0f, 3.0f);
- glm::uvec3 B = glm::floatBitsToUint(A);
- glm::vec3 C = glm::uintBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
-
- {
- glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
- glm::uvec4 B = glm::floatBitsToUint(A);
- glm::vec4 C = glm::uintBitsToFloat(B);
- Error += glm::all(glm::epsilonEqual(A, C, 0.0001f)) ? 0 : 1;
- }
-
- return Error;
- }
- }//namespace floatBitsToUint
- namespace min_
- {
- int test()
- {
- int Error = 0;
- glm::vec1 A0 = glm::min(glm::vec1(1), glm::vec1(1));
- glm::vec2 B0 = glm::min(glm::vec2(1), glm::vec2(1));
- glm::vec2 B1 = glm::min(glm::vec2(1), 1.0f);
- bool B2 = glm::all(glm::equal(B0, B1));
- Error += B2 ? 0 : 1;
- glm::vec3 C0 = glm::min(glm::vec3(1), glm::vec3(1));
- glm::vec3 C1 = glm::min(glm::vec3(1), 1.0f);
- bool C2 = glm::all(glm::equal(C0, C1));
- Error += C2 ? 0 : 1;
- glm::vec4 D0 = glm::min(glm::vec4(1), glm::vec4(1));
- glm::vec4 D1 = glm::min(glm::vec4(1), 1.0f);
- bool D2 = glm::all(glm::equal(D0, D1));
- Error += D2 ? 0 : 1;
- return Error;
- }
- }//namespace min_
- namespace max_
- {
- int test()
- {
- int Error = 0;
- glm::vec1 A0 = glm::max(glm::vec1(1), glm::vec1(1));
- glm::vec2 B0 = glm::max(glm::vec2(1), glm::vec2(1));
- glm::vec2 B1 = glm::max(glm::vec2(1), 1.0f);
- bool B2 = glm::all(glm::equal(B0, B1));
- Error += B2 ? 0 : 1;
- glm::vec3 C0 = glm::max(glm::vec3(1), glm::vec3(1));
- glm::vec3 C1 = glm::max(glm::vec3(1), 1.0f);
- bool C2 = glm::all(glm::equal(C0, C1));
- Error += C2 ? 0 : 1;
- glm::vec4 D0 = glm::max(glm::vec4(1), glm::vec4(1));
- glm::vec4 D1 = glm::max(glm::vec4(1), 1.0f);
- bool D2 = glm::all(glm::equal(D0, D1));
- Error += D2 ? 0 : 1;
- return Error;
- }
- }//namespace max_
- namespace clamp_
- {
- int test()
- {
- int Error = 0;
- return Error;
- }
- }//namespace clamp_
- namespace mix_
- {
- template<typename T, typename B>
- struct entry
- {
- T x;
- T y;
- B a;
- T Result;
- };
- entry<float, bool> const TestBool[] =
- {
- {0.0f, 1.0f, false, 0.0f},
- {0.0f, 1.0f, true, 1.0f},
- {-1.0f, 1.0f, false, -1.0f},
- {-1.0f, 1.0f, true, 1.0f}
- };
- entry<float, float> const TestFloat[] =
- {
- {0.0f, 1.0f, 0.0f, 0.0f},
- {0.0f, 1.0f, 1.0f, 1.0f},
- {-1.0f, 1.0f, 0.0f, -1.0f},
- {-1.0f, 1.0f, 1.0f, 1.0f}
- };
- entry<glm::vec2, bool> const TestVec2Bool[] =
- {
- {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)},
- {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)},
- {glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)},
- {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}
- };
- entry<glm::vec2, glm::bvec2> const TestBVec2[] =
- {
- {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)},
- {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
- {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)},
- {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)},
- {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)}
- };
- entry<glm::vec3, bool> const TestVec3Bool[] =
- {
- {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)},
- {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)},
- {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)},
- {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}
- };
- entry<glm::vec3, glm::bvec3> const TestBVec3[] =
- {
- {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)},
- {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
- {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)},
- {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)},
- {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)}
- };
- entry<glm::vec4, bool> const TestVec4Bool[] =
- {
- {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)},
- {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)},
- {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)},
- {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}
- };
- entry<glm::vec4, glm::bvec4> const TestBVec4[] =
- {
- {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)},
- {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
- {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)},
- {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)},
- {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)}
- };
- int test()
- {
- int Error = 0;
- // Float with bool
- {
- for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(entry<float, bool>); ++i)
- {
- float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a);
- Error += glm::epsilonEqual(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // Float with float
- {
- for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(entry<float, float>); ++i)
- {
- float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a);
- Error += glm::epsilonEqual(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec2 with bool
- {
- for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(entry<glm::vec2, bool>); ++i)
- {
- glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a);
- Error += glm::epsilonEqual(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec2 with bvec2
- {
- for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(entry<glm::vec2, glm::bvec2>); ++i)
- {
- glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a);
- Error += glm::epsilonEqual(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec3 with bool
- {
- for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(entry<glm::vec3, bool>); ++i)
- {
- glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a);
- Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec3 with bvec3
- {
- for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(entry<glm::vec3, glm::bvec3>); ++i)
- {
- glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a);
- Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec4 with bool
- {
- for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(entry<glm::vec4, bool>); ++i)
- {
- glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a);
- Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- // vec4 with bvec4
- {
- for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(entry<glm::vec4, glm::bvec4>); ++i)
- {
- glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a);
- Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1;
- Error += glm::epsilonEqual(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1;
- }
- }
- return Error;
- }
- }//namespace mix_
- namespace step_
- {
- template<typename EDGE, typename VEC>
- struct entry
- {
- EDGE edge;
- VEC x;
- VEC result;
- };
- entry<float, glm::vec4> TestVec4Scalar [] =
- {
- { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
- { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
- { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
- };
- entry<glm::vec4, glm::vec4> TestVec4Vector [] =
- {
- { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
- { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
- { glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
- { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
- };
- int test()
- {
- int Error = 0;
- // vec4 and float
- {
- for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(entry<float, glm::vec4>); ++i)
- {
- glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
- Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
- }
- }
- // vec4 and vec4
- {
- for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(entry<glm::vec4, glm::vec4>); ++i)
- {
- glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
- Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
- }
- }
- return Error;
- }
- }//namespace step_
- namespace round_
- {
- int test()
- {
- int Error = 0;
- {
- float A = glm::round(0.0f);
- Error += glm::epsilonEqual(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::round(0.5f);
- Error += glm::epsilonEqual(B, 1.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::round(1.0f);
- Error += glm::epsilonEqual(C, 1.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::round(0.1f);
- Error += glm::epsilonEqual(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::round(0.9f);
- Error += glm::epsilonEqual(E, 1.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::round(1.5f);
- Error += glm::epsilonEqual(F, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::round(1.9f);
- Error += glm::epsilonEqual(G, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- }
-
- {
- float A = glm::round(-0.0f);
- Error += glm::epsilonEqual(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::round(-0.5f);
- Error += glm::epsilonEqual(B, -1.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::round(-1.0f);
- Error += glm::epsilonEqual(C, -1.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::round(-0.1f);
- Error += glm::epsilonEqual(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::round(-0.9f);
- Error += glm::epsilonEqual(E, -1.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::round(-1.5f);
- Error += glm::epsilonEqual(F, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::round(-1.9f);
- Error += glm::epsilonEqual(G, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- }
-
- return Error;
- }
- }//namespace round_
- namespace roundEven
- {
- int test()
- {
- int Error = 0;
- {
- float A1 = glm::roundEven(-1.5f);
- Error += glm::epsilonEqual(A1, -2.0f, 0.0001f) ? 0 : 1;
- float A2 = glm::roundEven(1.5f);
- Error += glm::epsilonEqual(A2, 2.0f, 0.0001f) ? 0 : 1;
- float A5 = glm::roundEven(-2.5f);
- Error += glm::epsilonEqual(A5, -2.0f, 0.0001f) ? 0 : 1;
- float A6 = glm::roundEven(2.5f);
- Error += glm::epsilonEqual(A6, 2.0f, 0.0001f) ? 0 : 1;
- float A3 = glm::roundEven(-3.5f);
- Error += glm::epsilonEqual(A3, -4.0f, 0.0001f) ? 0 : 1;
- float A4 = glm::roundEven(3.5f);
- Error += glm::epsilonEqual(A4, 4.0f, 0.0001f) ? 0 : 1;
- float C7 = glm::roundEven(-4.5f);
- Error += glm::epsilonEqual(C7, -4.0f, 0.0001f) ? 0 : 1;
- float C8 = glm::roundEven(4.5f);
- Error += glm::epsilonEqual(C8, 4.0f, 0.0001f) ? 0 : 1;
- float C1 = glm::roundEven(-5.5f);
- Error += glm::epsilonEqual(C1, -6.0f, 0.0001f) ? 0 : 1;
- float C2 = glm::roundEven(5.5f);
- Error += glm::epsilonEqual(C2, 6.0f, 0.0001f) ? 0 : 1;
- float C3 = glm::roundEven(-6.5f);
- Error += glm::epsilonEqual(C3, -6.0f, 0.0001f) ? 0 : 1;
- float C4 = glm::roundEven(6.5f);
- Error += glm::epsilonEqual(C4, 6.0f, 0.0001f) ? 0 : 1;
- float C5 = glm::roundEven(-7.5f);
- Error += glm::epsilonEqual(C5, -8.0f, 0.0001f) ? 0 : 1;
- float C6 = glm::roundEven(7.5f);
- Error += glm::epsilonEqual(C6, 8.0f, 0.0001f) ? 0 : 1;
- Error += 0;
- }
- {
- float A7 = glm::roundEven(-2.4f);
- Error += glm::epsilonEqual(A7, -2.0f, 0.0001f) ? 0 : 1;
- float A8 = glm::roundEven(2.4f);
- Error += glm::epsilonEqual(A8, 2.0f, 0.0001f) ? 0 : 1;
- float B1 = glm::roundEven(-2.6f);
- Error += glm::epsilonEqual(B1, -3.0f, 0.0001f) ? 0 : 1;
- float B2 = glm::roundEven(2.6f);
- Error += glm::epsilonEqual(B2, 3.0f, 0.0001f) ? 0 : 1;
- float B3 = glm::roundEven(-2.0f);
- Error += glm::epsilonEqual(B3, -2.0f, 0.0001f) ? 0 : 1;
- float B4 = glm::roundEven(2.0f);
- Error += glm::epsilonEqual(B4, 2.0f, 0.0001f) ? 0 : 1;
- Error += 0;
- }
- {
- float A = glm::roundEven(0.0f);
- Error += glm::epsilonEqual(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::roundEven(0.5f);
- Error += glm::epsilonEqual(B, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::roundEven(1.0f);
- Error += glm::epsilonEqual(C, 1.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::roundEven(0.1f);
- Error += glm::epsilonEqual(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::roundEven(0.9f);
- Error += glm::epsilonEqual(E, 1.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::roundEven(1.5f);
- Error += glm::epsilonEqual(F, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::roundEven(1.9f);
- Error += glm::epsilonEqual(G, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- }
- {
- float A = glm::roundEven(-0.0f);
- Error += glm::epsilonEqual(A, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::roundEven(-0.5f);
- Error += glm::epsilonEqual(B, -0.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::roundEven(-1.0f);
- Error += glm::epsilonEqual(C, -1.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::roundEven(-0.1f);
- Error += glm::epsilonEqual(D, 0.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::roundEven(-0.9f);
- Error += glm::epsilonEqual(E, -1.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::roundEven(-1.5f);
- Error += glm::epsilonEqual(F, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::roundEven(-1.9f);
- Error += glm::epsilonEqual(G, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- }
- {
- float A = glm::roundEven(1.5f);
- Error += glm::epsilonEqual(A, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::roundEven(2.5f);
- Error += glm::epsilonEqual(B, 2.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::roundEven(3.5f);
- Error += glm::epsilonEqual(C, 4.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::roundEven(4.5f);
- Error += glm::epsilonEqual(D, 4.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::roundEven(5.5f);
- Error += glm::epsilonEqual(E, 6.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::roundEven(6.5f);
- Error += glm::epsilonEqual(F, 6.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::roundEven(7.5f);
- Error += glm::epsilonEqual(G, 8.0f, glm::epsilon<float>()) ? 0 : 1;
- }
-
- {
- float A = glm::roundEven(-1.5f);
- Error += glm::epsilonEqual(A, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- float B = glm::roundEven(-2.5f);
- Error += glm::epsilonEqual(B, -2.0f, glm::epsilon<float>()) ? 0 : 1;
- float C = glm::roundEven(-3.5f);
- Error += glm::epsilonEqual(C, -4.0f, glm::epsilon<float>()) ? 0 : 1;
- float D = glm::roundEven(-4.5f);
- Error += glm::epsilonEqual(D, -4.0f, glm::epsilon<float>()) ? 0 : 1;
- float E = glm::roundEven(-5.5f);
- Error += glm::epsilonEqual(E, -6.0f, glm::epsilon<float>()) ? 0 : 1;
- float F = glm::roundEven(-6.5f);
- Error += glm::epsilonEqual(F, -6.0f, glm::epsilon<float>()) ? 0 : 1;
- float G = glm::roundEven(-7.5f);
- Error += glm::epsilonEqual(G, -8.0f, glm::epsilon<float>()) ? 0 : 1;
- }
- return Error;
- }
- }//namespace roundEven
- namespace isnan_
- {
- int test()
- {
- int Error = 0;
- float Zero_f = 0.0;
- double Zero_d = 0.0;
- {
- Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1;
- }
- {
- Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1;
- }
- return Error;
- }
- }//namespace isnan_
- namespace isinf_
- {
- int test()
- {
- int Error = 0;
- float Zero_f = 0.0;
- double Zero_d = 0.0;
- {
- Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1;
- Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1;
- }
- {
- Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1;
- Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1;
- Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1;
- }
- return Error;
- }
- }//namespace isinf_
- namespace sign
- {
- template<typename genFIType>
- GLM_FUNC_QUALIFIER genFIType sign_if(genFIType x)
- {
- GLM_STATIC_ASSERT(
- std::numeric_limits<genFIType>::is_iec559 ||
- (std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), "'sign' only accept signed inputs");
- genFIType result;
- if(x > genFIType(0))
- result = genFIType(1);
- else if(x < genFIType(0))
- result = genFIType(-1);
- else
- result = genFIType(0);
- return result;
- }
- template<typename genFIType>
- GLM_FUNC_QUALIFIER genFIType sign_alu1(genFIType x)
- {
- GLM_STATIC_ASSERT(
- std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
- "'sign' only accept integer inputs");
- return (x >> 31) | (static_cast<unsigned>(-x) >> 31);
- }
- GLM_FUNC_QUALIFIER int sign_alu2(int x)
- {
- GLM_STATIC_ASSERT(std::numeric_limits<int>::is_signed && std::numeric_limits<int>::is_integer, "'sign' only accept integer inputs");
- # if GLM_COMPILER & GLM_COMPILER_VC
- # pragma warning(push)
- # pragma warning(disable : 4146) //cast truncates constant value
- # endif
- return -(static_cast<unsigned>(x) >> 31) | (-static_cast<unsigned>(x) >> 31);
- # if GLM_COMPILER & GLM_COMPILER_VC
- # pragma warning(pop)
- # endif
- }
- template<typename genFIType>
- GLM_FUNC_QUALIFIER genFIType sign_sub(genFIType x)
- {
- GLM_STATIC_ASSERT(
- std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
- "'sign' only accept integer inputs");
- return (static_cast<unsigned>(-x) >> 31) - (static_cast<unsigned>(x) >> 31);
- }
- template<typename genFIType>
- GLM_FUNC_QUALIFIER genFIType sign_cmp(genFIType x)
- {
- GLM_STATIC_ASSERT(
- std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer,
- "'sign' only accept integer inputs");
- return (x > 0) - (x < 0);
- }
- template<typename genType>
- struct type
- {
- genType Value;
- genType Return;
- };
- int test_int32()
- {
- type<glm::int32> const Data[] =
- {
- { std::numeric_limits<glm::int32>::max(), 1},
- { std::numeric_limits<glm::int32>::min(), -1},
- { 0, 0},
- { 1, 1},
- { 2, 1},
- { 3, 1},
- {-1,-1},
- {-2,-1},
- {-3,-1}
- };
- int Error = 0;
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
- {
- glm::int32 Result = glm::sign(Data[i].Value);
- Error += Data[i].Return == Result ? 0 : 1;
- }
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
- {
- glm::int32 Result = sign_cmp(Data[i].Value);
- Error += Data[i].Return == Result ? 0 : 1;
- }
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
- {
- glm::int32 Result = sign_if(Data[i].Value);
- Error += Data[i].Return == Result ? 0 : 1;
- }
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
- {
- glm::int32 Result = sign_alu1(Data[i].Value);
- Error += Data[i].Return == Result ? 0 : 1;
- }
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i)
- {
- glm::int32 Result = sign_alu2(Data[i].Value);
- Error += Data[i].Return == Result ? 0 : 1;
- }
- return Error;
- }
- int test_i32vec4()
- {
- type<glm::i32vec4> const Data[] =
- {
- {glm::i32vec4( 1), glm::i32vec4( 1)},
- {glm::i32vec4( 0), glm::i32vec4( 0)},
- {glm::i32vec4( 2), glm::i32vec4( 1)},
- {glm::i32vec4( 3), glm::i32vec4( 1)},
- {glm::i32vec4(-1), glm::i32vec4(-1)},
- {glm::i32vec4(-2), glm::i32vec4(-1)},
- {glm::i32vec4(-3), glm::i32vec4(-1)}
- };
- int Error = 0;
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::i32vec4>); ++i)
- {
- glm::i32vec4 Result = glm::sign(Data[i].Value);
- Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
- }
- return Error;
- }
- int test_f32vec4()
- {
- type<glm::vec4> const Data[] =
- {
- {glm::vec4( 1), glm::vec4( 1)},
- {glm::vec4( 0), glm::vec4( 0)},
- {glm::vec4( 2), glm::vec4( 1)},
- {glm::vec4( 3), glm::vec4( 1)},
- {glm::vec4(-1), glm::vec4(-1)},
- {glm::vec4(-2), glm::vec4(-1)},
- {glm::vec4(-3), glm::vec4(-1)}
- };
- int Error = 0;
- for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::vec4>); ++i)
- {
- glm::vec4 Result = glm::sign(Data[i].Value);
- Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
- }
- return Error;
- }
- int test()
- {
- int Error = 0;
- Error += test_int32();
- Error += test_i32vec4();
- Error += test_f32vec4();
- return Error;
- }
- int perf_rand(std::size_t Samples)
- {
- int Error = 0;
- std::size_t const Count = Samples;
- std::vector<glm::int32> Input, Output;
- Input.resize(Count);
- Output.resize(Count);
- for(std::size_t i = 0; i < Count; ++i)
- Input[i] = static_cast<glm::int32>(glm::linearRand(-65536.f, 65536.f));
- std::clock_t Timestamp0 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_cmp(Input[i]);
- std::clock_t Timestamp1 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_if(Input[i]);
- std::clock_t Timestamp2 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_alu1(Input[i]);
- std::clock_t Timestamp3 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_alu2(Input[i]);
- std::clock_t Timestamp4 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_sub(Input[i]);
- std::clock_t Timestamp5 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = glm::sign(Input[i]);
- std::clock_t Timestamp6 = std::clock();
- std::printf("sign_cmp(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
- std::printf("sign_if(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
- std::printf("sign_alu1(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
- std::printf("sign_alu2(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
- std::printf("sign_sub(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
- std::printf("glm::sign(rand) Time %d clocks\n", static_cast<unsigned int>(Timestamp6 - Timestamp5));
- return Error;
- }
- int perf_linear(std::size_t Samples)
- {
- int Error = 0;
- std::size_t const Count = Samples;
- std::vector<glm::int32> Input, Output;
- Input.resize(Count);
- Output.resize(Count);
- for(std::size_t i = 0; i < Count; ++i)
- Input[i] = static_cast<glm::int32>(i);
- std::clock_t Timestamp0 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_cmp(Input[i]);
- std::clock_t Timestamp1 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_if(Input[i]);
- std::clock_t Timestamp2 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_alu1(Input[i]);
- std::clock_t Timestamp3 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_alu2(Input[i]);
- std::clock_t Timestamp4 = std::clock();
- for(std::size_t i = 0; i < Count; ++i)
- Output[i] = sign_sub(Input[i]);
- std::clock_t Timestamp5 = std::clock();
- std::printf("sign_cmp(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
- std::printf("sign_if(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
- std::printf("sign_alu1(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
- std::printf("sign_alu2(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
- std::printf("sign_sub(linear) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
- return Error;
- }
- int perf_linear_cal(std::size_t Samples)
- {
- int Error = 0;
- glm::int32 const Count = static_cast<glm::int32>(Samples);
- std::clock_t Timestamp0 = std::clock();
- glm::int32 Sum = 0;
- for(glm::int32 i = 1; i < Count; ++i)
- Sum += sign_cmp(i);
- std::clock_t Timestamp1 = std::clock();
- for(glm::int32 i = 1; i < Count; ++i)
- Sum += sign_if(i);
- std::clock_t Timestamp2 = std::clock();
- for(glm::int32 i = 1; i < Count; ++i)
- Sum += sign_alu1(i);
- std::clock_t Timestamp3 = std::clock();
- for(glm::int32 i = 1; i < Count; ++i)
- Sum += sign_alu2(i);
- std::clock_t Timestamp4 = std::clock();
- for(glm::int32 i = 1; i < Count; ++i)
- Sum += sign_sub(i);
- std::clock_t Timestamp5 = std::clock();
- std::printf("Sum %d\n", static_cast<unsigned int>(Sum));
- std::printf("sign_cmp(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp1 - Timestamp0));
- std::printf("sign_if(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp2 - Timestamp1));
- std::printf("sign_alu1(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp3 - Timestamp2));
- std::printf("sign_alu2(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp4 - Timestamp3));
- std::printf("sign_sub(linear_cal) Time %d clocks\n", static_cast<unsigned int>(Timestamp5 - Timestamp4));
- return Error;
- }
- int perf(std::size_t Samples)
- {
- int Error(0);
- Error += perf_linear_cal(Samples);
- Error += perf_linear(Samples);
- Error += perf_rand(Samples);
- return Error;
- }
- }//namespace sign
- namespace frexp_
- {
- int test()
- {
- int Error(0);
- {
- glm::vec1 x(1024);
- glm::ivec1 exp;
- glm::vec1 A = glm::frexp(x, exp);
- Error += glm::all(glm::epsilonEqual(A, glm::vec1(0.5), 0.00001f)) ? 0 : 1;
- Error += glm::all(glm::equal(exp, glm::ivec1(11))) ? 0 : 1;
- }
- {
- glm::vec2 x(1024, 0.24);
- glm::ivec2 exp;
- glm::vec2 A = glm::frexp(x, exp);
- Error += glm::all(glm::epsilonEqual(A, glm::vec2(0.5, 0.96), 0.00001f)) ? 0 : 1;
- Error += glm::all(glm::equal(exp, glm::ivec2(11, -2))) ? 0 : 1;
- }
- {
- glm::vec3 x(1024, 0.24, 0);
- glm::ivec3 exp;
- glm::vec3 A = glm::frexp(x, exp);
- Error += glm::all(glm::epsilonEqual(A, glm::vec3(0.5, 0.96, 0.0), 0.00001f)) ? 0 : 1;
- Error += glm::all(glm::equal(exp, glm::ivec3(11, -2, 0))) ? 0 : 1;
- }
- {
- glm::vec4 x(1024, 0.24, 0, -1.33);
- glm::ivec4 exp;
- glm::vec4 A = glm::frexp(x, exp);
- Error += glm::all(glm::epsilonEqual(A, glm::vec4(0.5, 0.96, 0.0, -0.665), 0.00001f)) ? 0 : 1;
- Error += glm::all(glm::equal(exp, glm::ivec4(11, -2, 0, 1))) ? 0 : 1;
- }
- return Error;
- }
- }//namespace frexp_
- namespace ldexp_
- {
- int test()
- {
- int Error(0);
- {
- glm::vec1 A = glm::vec1(0.5);
- glm::ivec1 exp = glm::ivec1(11);
- glm::vec1 x = glm::ldexp(A, exp);
- Error += glm::all(glm::epsilonEqual(x, glm::vec1(1024),0.00001f)) ? 0 : 1;
- }
- {
- glm::vec2 A = glm::vec2(0.5, 0.96);
- glm::ivec2 exp = glm::ivec2(11, -2);
- glm::vec2 x = glm::ldexp(A, exp);
- Error += glm::all(glm::epsilonEqual(x, glm::vec2(1024, .24),0.00001f)) ? 0 : 1;
- }
- {
- glm::vec3 A = glm::vec3(0.5, 0.96, 0.0);
- glm::ivec3 exp = glm::ivec3(11, -2, 0);
- glm::vec3 x = glm::ldexp(A, exp);
- Error += glm::all(glm::epsilonEqual(x, glm::vec3(1024, .24, 0),0.00001f)) ? 0 : 1;
- }
- {
- glm::vec4 A = glm::vec4(0.5, 0.96, 0.0, -0.665);
- glm::ivec4 exp = glm::ivec4(11, -2, 0, 1);
- glm::vec4 x = glm::ldexp(A, exp);
- Error += glm::all(glm::epsilonEqual(x, glm::vec4(1024, .24, 0, -1.33),0.00001f)) ? 0 : 1;
- }
- return Error;
- }
- }//namespace ldexp_
- int main()
- {
- int Error = 0;
- glm::ivec4 const a(1);
- glm::ivec4 const b = ~a;
- glm::int32 const c(1);
- glm::int32 const d = ~c;
- # if GLM_ARCH & GLM_ARCH_AVX_BIT && GLM_HAS_UNRESTRICTED_UNIONS
- glm_vec4 const A = _mm_set_ps(4, 3, 2, 1);
- glm_vec4 const B = glm_vec4_swizzle_xyzw(A);
- glm_vec4 const C = _mm_permute_ps(A, _MM_SHUFFLE(3, 2, 1, 0));
- glm_vec4 const D = _mm_permute_ps(A, _MM_SHUFFLE(0, 1, 2, 3));
- glm_vec4 const E = _mm_shuffle_ps(A, A, _MM_SHUFFLE(0, 1, 2, 3));
- # endif
- Error += sign::test();
- Error += floor_::test();
- Error += mod_::test();
- Error += modf_::test();
- Error += floatBitsToInt::test();
- Error += floatBitsToUint::test();
- Error += mix_::test();
- Error += step_::test();
- Error += max_::test();
- Error += min_::test();
- Error += round_::test();
- Error += roundEven::test();
- Error += isnan_::test();
- Error += isinf_::test();
- Error += frexp_::test();
- Error += ldexp_::test();
- # ifdef NDEBUG
- std::size_t Samples = 1000;
- Error += sign::perf(Samples);
- # endif
- return Error;
- }
|