math.cs 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Runtime.CompilerServices;
  4. namespace Unity.Mathematics
  5. {
  6. public static partial class math
  7. {
  8. /// <summary>Extrinsic rotation order. Specifies in which order rotations around the principal axes (x, y and z) are to be applied.</summary>
  9. public enum RotationOrder : byte
  10. {
  11. /// <summary>Extrinsic rotation around the x axis, then around the y axis and finally around the z axis.</summary>
  12. XYZ,
  13. /// <summary>Extrinsic rotation around the x axis, then around the z axis and finally around the y axis.</summary>
  14. XZY,
  15. /// <summary>Extrinsic rotation around the y axis, then around the x axis and finally around the z axis.</summary>
  16. YXZ,
  17. /// <summary>Extrinsic rotation around the y axis, then around the z axis and finally around the x axis.</summary>
  18. YZX,
  19. /// <summary>Extrinsic rotation around the z axis, then around the x axis and finally around the y axis.</summary>
  20. ZXY,
  21. /// <summary>Extrinsic rotation around the z axis, then around the y axis and finally around the x axis.</summary>
  22. ZYX,
  23. /// <summary>Unity default rotation order. Extrinsic Rotation around the z axis, then around the x axis and finally around the y axis.</summary>
  24. Default = ZXY
  25. };
  26. /// <summary>Specifies a shuffle component.</summary>
  27. public enum ShuffleComponent : byte
  28. {
  29. /// <summary>Specified the x component of the left vector.</summary>
  30. LeftX,
  31. /// <summary>Specified the y component of the left vector.</summary>
  32. LeftY,
  33. /// <summary>Specified the z component of the left vector.</summary>
  34. LeftZ,
  35. /// <summary>Specified the w component of the left vector.</summary>
  36. LeftW,
  37. /// <summary>Specified the x component of the right vector.</summary>
  38. RightX,
  39. /// <summary>Specified the y component of the right vector.</summary>
  40. RightY,
  41. /// <summary>Specified the z component of the right vector.</summary>
  42. RightZ,
  43. /// <summary>Specified the w component of the right vector.</summary>
  44. RightW
  45. };
  46. /// <summary>The mathematical constant e also known as Euler's number. Approximately 2.72. This is a f64/double precision constant.</summary>
  47. public const double E_DBL = 2.71828182845904523536;
  48. /// <summary>The base 2 logarithm of e. Approximately 1.44. This is a f64/double precision constant.</summary>
  49. public const double LOG2E_DBL = 1.44269504088896340736;
  50. /// <summary>The base 10 logarithm of e. Approximately 0.43. This is a f64/double precision constant.</summary>
  51. public const double LOG10E_DBL = 0.434294481903251827651;
  52. /// <summary>The natural logarithm of 2. Approximately 0.69. This is a f64/double precision constant.</summary>
  53. public const double LN2_DBL = 0.693147180559945309417;
  54. /// <summary>The natural logarithm of 10. Approximately 2.30. This is a f64/double precision constant.</summary>
  55. public const double LN10_DBL = 2.30258509299404568402;
  56. /// <summary>The mathematical constant pi. Approximately 3.14. This is a f64/double precision constant.</summary>
  57. public const double PI_DBL = 3.14159265358979323846;
  58. /// <summary>The square root 2. Approximately 1.41. This is a f64/double precision constant.</summary>
  59. public const double SQRT2_DBL = 1.41421356237309504880;
  60. /// <summary>The smallest positive normal number representable in a float.</summary>
  61. public const float FLT_MIN_NORMAL = 1.175494351e-38F;
  62. /// <summary>The smallest positive normal number representable in a double. This is a f64/double precision constant.</summary>
  63. public const double DBL_MIN_NORMAL = 2.2250738585072014e-308;
  64. /// <summary>The mathematical constant e also known as Euler's number. Approximately 2.72.</summary>
  65. public const float E = (float)E_DBL;
  66. /// <summary>The base 2 logarithm of e. Approximately 1.44.</summary>
  67. public const float LOG2E = (float)LOG2E_DBL;
  68. /// <summary>The base 10 logarithm of e. Approximately 0.43.</summary>
  69. public const float LOG10E = (float)LOG10E_DBL;
  70. /// <summary>The natural logarithm of 2. Approximately 0.69.</summary>
  71. public const float LN2 = (float)LN2_DBL;
  72. /// <summary>The natural logarithm of 10. Approximately 2.30.</summary>
  73. public const float LN10 = (float)LN10_DBL;
  74. /// <summary>The mathematical constant pi. Approximately 3.14.</summary>
  75. public const float PI = (float)PI_DBL;
  76. /// <summary>The square root 2. Approximately 1.41.</summary>
  77. public const float SQRT2 = (float)SQRT2_DBL;
  78. /// <summary>Returns the bit pattern of a uint as an int.</summary>
  79. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  80. public static int asint(uint x) { return (int)x; }
  81. /// <summary>Returns the bit pattern of a uint2 as an int2.</summary>
  82. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  83. public static int2 asint(uint2 x) { return int2((int)x.x, (int)x.y); }
  84. /// <summary>Returns the bit pattern of a uint3 as an int3.</summary>
  85. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  86. public static int3 asint(uint3 x) { return int3((int)x.x, (int)x.y, (int)x.z); }
  87. /// <summary>Returns the bit pattern of a uint4 as an int4.</summary>
  88. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  89. public static int4 asint(uint4 x) { return int4((int)x.x, (int)x.y, (int)x.z, (int)x.w); }
  90. /// <summary>Returns the bit pattern of a float as an int.</summary>
  91. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  92. public static int asint(float x) {
  93. IntFloatUnion u;
  94. u.intValue = 0;
  95. u.floatValue = x;
  96. return u.intValue;
  97. }
  98. /// <summary>Returns the bit pattern of a float2 as an int2.</summary>
  99. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  100. public static int2 asint(float2 x) { return int2(asint(x.x), asint(x.y)); }
  101. /// <summary>Returns the bit pattern of a float3 as an int3.</summary>
  102. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  103. public static int3 asint(float3 x) { return int3(asint(x.x), asint(x.y), asint(x.z)); }
  104. /// <summary>Returns the bit pattern of a float4 as an int4.</summary>
  105. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  106. public static int4 asint(float4 x) { return int4(asint(x.x), asint(x.y), asint(x.z), asint(x.w)); }
  107. /// <summary>Returns the bit pattern of an int as a uint.</summary>
  108. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  109. public static uint asuint(int x) { return (uint)x; }
  110. /// <summary>Returns the bit pattern of an int2 as a uint2.</summary>
  111. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  112. public static uint2 asuint(int2 x) { return uint2((uint)x.x, (uint)x.y); }
  113. /// <summary>Returns the bit pattern of an int3 as a uint3.</summary>
  114. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  115. public static uint3 asuint(int3 x) { return uint3((uint)x.x, (uint)x.y, (uint)x.z); }
  116. /// <summary>Returns the bit pattern of an int4 as a uint4.</summary>
  117. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  118. public static uint4 asuint(int4 x) { return uint4((uint)x.x, (uint)x.y, (uint)x.z, (uint)x.w); }
  119. /// <summary>Returns the bit pattern of a float as a uint.</summary>
  120. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  121. public static uint asuint(float x) { return (uint)asint(x); }
  122. /// <summary>Returns the bit pattern of a float2 as a uint2.</summary>
  123. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  124. public static uint2 asuint(float2 x) { return uint2(asuint(x.x), asuint(x.y)); }
  125. /// <summary>Returns the bit pattern of a float3 as a uint3.</summary>
  126. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  127. public static uint3 asuint(float3 x) { return uint3(asuint(x.x), asuint(x.y), asuint(x.z)); }
  128. /// <summary>Returns the bit pattern of a float4 as a uint4.</summary>
  129. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  130. public static uint4 asuint(float4 x) { return uint4(asuint(x.x), asuint(x.y), asuint(x.z), asuint(x.w)); }
  131. /// <summary>Returns the bit pattern of a ulong as a long.</summary>
  132. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  133. public static long aslong(ulong x) { return (long)x; }
  134. /// <summary>Returns the bit pattern of a double as a long.</summary>
  135. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  136. public static long aslong(double x)
  137. {
  138. LongDoubleUnion u;
  139. u.longValue = 0;
  140. u.doubleValue = x;
  141. return u.longValue;
  142. }
  143. /// <summary>Returns the bit pattern of a long as a ulong.</summary>
  144. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  145. public static ulong asulong(long x) { return (ulong)x; }
  146. /// <summary>Returns the bit pattern of a double as a ulong.</summary>
  147. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  148. public static ulong asulong(double x) { return (ulong) aslong(x); }
  149. /// <summary>Returns the bit pattern of an int as a float.</summary>
  150. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  151. public static float asfloat(int x)
  152. {
  153. IntFloatUnion u;
  154. u.floatValue = 0;
  155. u.intValue = x;
  156. return u.floatValue;
  157. }
  158. /// <summary>Returns the bit pattern of an int2 as a float2.</summary>
  159. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  160. public static float2 asfloat(int2 x) { return float2(asfloat(x.x), asfloat(x.y)); }
  161. /// <summary>Returns the bit pattern of an int3 as a float3.</summary>
  162. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  163. public static float3 asfloat(int3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); }
  164. /// <summary>Returns the bit pattern of an int4 as a float4.</summary>
  165. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  166. public static float4 asfloat(int4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); }
  167. /// <summary>Returns the bit pattern of a uint as a float.</summary>
  168. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  169. public static float asfloat(uint x) { return asfloat((int)x); }
  170. /// <summary>Returns the bit pattern of a uint2 as a float2.</summary>
  171. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  172. public static float2 asfloat(uint2 x) { return float2(asfloat(x.x), asfloat(x.y)); }
  173. /// <summary>Returns the bit pattern of a uint3 as a float3.</summary>
  174. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  175. public static float3 asfloat(uint3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); }
  176. /// <summary>Returns the bit pattern of a uint4 as a float4.</summary>
  177. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  178. public static float4 asfloat(uint4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); }
  179. /// <summary>
  180. /// Returns a bitmask representation of a bool4. Storing one 1 bit per component
  181. /// in LSB order, from lower to higher bits (so 4 bits in total).
  182. /// The component x is stored at bit 0,
  183. /// The component y is stored at bit 1,
  184. /// The component z is stored at bit 2,
  185. /// The component w is stored at bit 3
  186. /// The bool4(x = true, y = true, z = false, w = true) would produce the value 1011 = 0xB
  187. /// </summary>
  188. /// <param name="value">The input bool4 to calculate the bitmask for</param>
  189. /// <returns>A bitmask representation of the bool4, in LSB order</returns>
  190. public static int bitmask(bool4 value)
  191. {
  192. int mask = 0;
  193. if (value.x) mask |= 0x01;
  194. if (value.y) mask |= 0x02;
  195. if (value.z) mask |= 0x04;
  196. if (value.w) mask |= 0x08;
  197. return mask;
  198. }
  199. /// <summary>Returns the bit pattern of a long as a double.</summary>
  200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  201. public static double asdouble(long x)
  202. {
  203. LongDoubleUnion u;
  204. u.doubleValue = 0;
  205. u.longValue = x;
  206. return u.doubleValue;
  207. }
  208. /// <summary>Returns the bit pattern of a ulong as a double.</summary>
  209. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  210. public static double asdouble(ulong x) { return asdouble((long)x); }
  211. /// <summary>Returns true if the input float is a finite floating point value, false otherwise.</summary>
  212. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  213. public static bool isfinite(float x) { return abs(x) < float.PositiveInfinity; }
  214. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a finite floating point value.</summary>
  215. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  216. public static bool2 isfinite(float2 x) { return abs(x) < float.PositiveInfinity; }
  217. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a finite floating point value.</summary>
  218. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  219. public static bool3 isfinite(float3 x) { return abs(x) < float.PositiveInfinity; }
  220. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a finite floating point value.</summary>
  221. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  222. public static bool4 isfinite(float4 x) { return abs(x) < float.PositiveInfinity; }
  223. /// <summary>Returns true if the input double is a finite floating point value, false otherwise.</summary>
  224. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  225. public static bool isfinite(double x) { return abs(x) < double.PositiveInfinity; }
  226. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a finite floating point value.</summary>
  227. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  228. public static bool2 isfinite(double2 x) { return abs(x) < double.PositiveInfinity; }
  229. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a finite floating point value.</summary>
  230. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  231. public static bool3 isfinite(double3 x) { return abs(x) < double.PositiveInfinity; }
  232. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a finite floating point value.</summary>
  233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  234. public static bool4 isfinite(double4 x) { return abs(x) < double.PositiveInfinity; }
  235. /// <summary>Returns true if the input float is an infinite floating point value, false otherwise.</summary>
  236. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  237. public static bool isinf(float x) { return abs(x) == float.PositiveInfinity; }
  238. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is an infinite floating point value.</summary>
  239. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  240. public static bool2 isinf(float2 x) { return abs(x) == float.PositiveInfinity; }
  241. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is an infinite floating point value.</summary>
  242. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  243. public static bool3 isinf(float3 x) { return abs(x) == float.PositiveInfinity; }
  244. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is an infinite floating point value.</summary>
  245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  246. public static bool4 isinf(float4 x) { return abs(x) == float.PositiveInfinity; }
  247. /// <summary>Returns true if the input double is an infinite floating point value, false otherwise.</summary>
  248. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  249. public static bool isinf(double x) { return abs(x) == double.PositiveInfinity; }
  250. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is an infinite floating point value.</summary>
  251. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  252. public static bool2 isinf(double2 x) { return abs(x) == double.PositiveInfinity; }
  253. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is an infinite floating point value.</summary>
  254. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  255. public static bool3 isinf(double3 x) { return abs(x) == double.PositiveInfinity; }
  256. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is an infinite floating point value.</summary>
  257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  258. public static bool4 isinf(double4 x) { return abs(x) == double.PositiveInfinity; }
  259. /// <summary>Returns true if the input float is a NaN (not a number) floating point value, false otherwise.</summary>
  260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  261. public static bool isnan(float x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  262. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a NaN (not a number) floating point value.</summary>
  263. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  264. public static bool2 isnan(float2 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  265. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a NaN (not a number) floating point value.</summary>
  266. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  267. public static bool3 isnan(float3 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  268. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a NaN (not a number) floating point value.</summary>
  269. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  270. public static bool4 isnan(float4 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  271. /// <summary>Returns true if the input double is a NaN (not a number) floating point value, false otherwise.</summary>
  272. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  273. public static bool isnan(double x) { return (asulong(x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000; }
  274. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a NaN (not a number) floating point value.</summary>
  275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  276. public static bool2 isnan(double2 x) {
  277. return bool2((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  278. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  279. }
  280. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a NaN (not a number) floating point value.</summary>
  281. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  282. public static bool3 isnan(double3 x)
  283. {
  284. return bool3((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  285. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  286. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  287. }
  288. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a NaN (not a number) floating point value.</summary>
  289. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  290. public static bool4 isnan(double4 x)
  291. {
  292. return bool4((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  293. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  294. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  295. (asulong(x.w) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  296. }
  297. /// <summary>Returns the minimum of two int values.</summary>
  298. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  299. public static int min(int x, int y) { return x < y ? x : y; }
  300. /// <summary>Returns the componentwise minimum of two int2 vectors.</summary>
  301. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  302. public static int2 min(int2 x, int2 y) { return new int2(min(x.x, y.x), min(x.y, y.y)); }
  303. /// <summary>Returns the componentwise minimum of two int3 vectors.</summary>
  304. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  305. public static int3 min(int3 x, int3 y) { return new int3(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)); }
  306. /// <summary>Returns the componentwise minimum of two int4 vectors.</summary>
  307. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  308. public static int4 min(int4 x, int4 y) { return new int4(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)); }
  309. /// <summary>Returns the minimum of two uint values.</summary>
  310. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  311. public static uint min(uint x, uint y) { return x < y ? x : y; }
  312. /// <summary>Returns the componentwise minimum of two uint2 vectors.</summary>
  313. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  314. public static uint2 min(uint2 x, uint2 y) { return new uint2(min(x.x, y.x), min(x.y, y.y)); }
  315. /// <summary>Returns the componentwise minimum of two uint3 vectors.</summary>
  316. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  317. public static uint3 min(uint3 x, uint3 y) { return new uint3(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)); }
  318. /// <summary>Returns the componentwise minimum of two uint4 vectors.</summary>
  319. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  320. public static uint4 min(uint4 x, uint4 y) { return new uint4(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)); }
  321. /// <summary>Returns the minimum of two long values.</summary>
  322. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  323. public static long min(long x, long y) { return x < y ? x : y; }
  324. /// <summary>Returns the minimum of two ulong values.</summary>
  325. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  326. public static ulong min(ulong x, ulong y) { return x < y ? x : y; }
  327. /// <summary>Returns the minimum of two float values.</summary>
  328. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  329. public static float min(float x, float y) { return float.IsNaN(y) || x < y ? x : y; }
  330. /// <summary>Returns the componentwise minimum of two float2 vectors.</summary>
  331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  332. public static float2 min(float2 x, float2 y) { return new float2(min(x.x, y.x), min(x.y, y.y)); }
  333. /// <summary>Returns the componentwise minimum of two float3 vectors.</summary>
  334. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  335. public static float3 min(float3 x, float3 y) { return new float3(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)); }
  336. /// <summary>Returns the componentwise minimum of two float4 vectors.</summary>
  337. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  338. public static float4 min(float4 x, float4 y) { return new float4(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)); }
  339. /// <summary>Returns the minimum of two double values.</summary>
  340. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  341. public static double min(double x, double y) { return double.IsNaN(y) || x < y ? x : y; }
  342. /// <summary>Returns the componentwise minimum of two double2 vectors.</summary>
  343. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  344. public static double2 min(double2 x, double2 y) { return new double2(min(x.x, y.x), min(x.y, y.y)); }
  345. /// <summary>Returns the componentwise minimum of two double3 vectors.</summary>
  346. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  347. public static double3 min(double3 x, double3 y) { return new double3(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z)); }
  348. /// <summary>Returns the componentwise minimum of two double4 vectors.</summary>
  349. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  350. public static double4 min(double4 x, double4 y) { return new double4(min(x.x, y.x), min(x.y, y.y), min(x.z, y.z), min(x.w, y.w)); }
  351. /// <summary>Returns the maximum of two int values.</summary>
  352. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  353. public static int max(int x, int y) { return x > y ? x : y; }
  354. /// <summary>Returns the componentwise maximum of two int2 vectors.</summary>
  355. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  356. public static int2 max(int2 x, int2 y) { return new int2(max(x.x, y.x), max(x.y, y.y)); }
  357. /// <summary>Returns the componentwise maximum of two int3 vectors.</summary>
  358. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  359. public static int3 max(int3 x, int3 y) { return new int3(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)); }
  360. /// <summary>Returns the componentwise maximum of two int4 vectors.</summary>
  361. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  362. public static int4 max(int4 x, int4 y) { return new int4(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)); }
  363. /// <summary>Returns the maximum of two uint values.</summary>
  364. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  365. public static uint max(uint x, uint y) { return x > y ? x : y; }
  366. /// <summary>Returns the componentwise maximum of two uint2 vectors.</summary>
  367. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  368. public static uint2 max(uint2 x, uint2 y) { return new uint2(max(x.x, y.x), max(x.y, y.y)); }
  369. /// <summary>Returns the componentwise maximum of two uint3 vectors.</summary>
  370. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  371. public static uint3 max(uint3 x, uint3 y) { return new uint3(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)); }
  372. /// <summary>Returns the componentwise maximum of two uint4 vectors.</summary>
  373. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  374. public static uint4 max(uint4 x, uint4 y) { return new uint4(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)); }
  375. /// <summary>Returns the maximum of two long values.</summary>
  376. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  377. public static long max(long x, long y) { return x > y ? x : y; }
  378. /// <summary>Returns the maximum of two ulong values.</summary>
  379. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  380. public static ulong max(ulong x, ulong y) { return x > y ? x : y; }
  381. /// <summary>Returns the maximum of two float values.</summary>
  382. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  383. public static float max(float x, float y) { return float.IsNaN(y) || x > y ? x : y; }
  384. /// <summary>Returns the componentwise maximum of two float2 vectors.</summary>
  385. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  386. public static float2 max(float2 x, float2 y) { return new float2(max(x.x, y.x), max(x.y, y.y)); }
  387. /// <summary>Returns the componentwise maximum of two float3 vectors.</summary>
  388. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  389. public static float3 max(float3 x, float3 y) { return new float3(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)); }
  390. /// <summary>Returns the componentwise maximum of two float4 vectors.</summary>
  391. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  392. public static float4 max(float4 x, float4 y) { return new float4(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)); }
  393. /// <summary>Returns the maximum of two double values.</summary>
  394. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  395. public static double max(double x, double y) { return double.IsNaN(y) || x > y ? x : y; }
  396. /// <summary>Returns the componentwise maximum of two double2 vectors.</summary>
  397. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  398. public static double2 max(double2 x, double2 y) { return new double2(max(x.x, y.x), max(x.y, y.y)); }
  399. /// <summary>Returns the componentwise maximum of two double3 vectors.</summary>
  400. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  401. public static double3 max(double3 x, double3 y) { return new double3(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z)); }
  402. /// <summary>Returns the componentwise maximum of two double4 vectors.</summary>
  403. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  404. public static double4 max(double4 x, double4 y) { return new double4(max(x.x, y.x), max(x.y, y.y), max(x.z, y.z), max(x.w, y.w)); }
  405. /// <summary>Returns the result of linearly interpolating from x to y using the interpolation parameter s.</summary>
  406. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  407. public static float lerp(float x, float y, float s) { return x + s * (y - x); }
  408. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  409. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  410. public static float2 lerp(float2 x, float2 y, float s) { return x + s * (y - x); }
  411. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  412. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  413. public static float3 lerp(float3 x, float3 y, float s) { return x + s * (y - x); }
  414. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  415. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  416. public static float4 lerp(float4 x, float4 y, float s) { return x + s * (y - x); }
  417. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  418. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  419. public static float2 lerp(float2 x, float2 y, float2 s) { return x + s * (y - x); }
  420. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  421. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  422. public static float3 lerp(float3 x, float3 y, float3 s) { return x + s * (y - x); }
  423. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  424. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  425. public static float4 lerp(float4 x, float4 y, float4 s) { return x + s * (y - x); }
  426. /// <summary>Returns the result of linearly interpolating from x to y using the interpolation parameter s.</summary>
  427. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  428. public static double lerp(double x, double y, double s) { return x + s * (y - x); }
  429. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  430. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  431. public static double2 lerp(double2 x, double2 y, double s) { return x + s * (y - x); }
  432. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  433. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  434. public static double3 lerp(double3 x, double3 y, double s) { return x + s * (y - x); }
  435. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  436. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  437. public static double4 lerp(double4 x, double4 y, double s) { return x + s * (y - x); }
  438. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  439. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  440. public static double2 lerp(double2 x, double2 y, double2 s) { return x + s * (y - x); }
  441. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  442. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  443. public static double3 lerp(double3 x, double3 y, double3 s) { return x + s * (y - x); }
  444. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  445. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  446. public static double4 lerp(double4 x, double4 y, double4 s) { return x + s * (y - x); }
  447. /// <summary>Returns the result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  448. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  449. public static float unlerp(float a, float b, float x) { return (x - a) / (b - a); }
  450. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  451. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  452. public static float2 unlerp(float2 a, float2 b, float2 x) { return (x - a) / (b - a); }
  453. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  454. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  455. public static float3 unlerp(float3 a, float3 b, float3 x) { return (x - a) / (b - a); }
  456. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  457. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  458. public static float4 unlerp(float4 a, float4 b, float4 x) { return (x - a) / (b - a); }
  459. /// <summary>Returns the result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  460. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  461. public static double unlerp(double a, double b, double x) { return (x - a) / (b - a); }
  462. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  463. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  464. public static double2 unlerp(double2 a, double2 b, double2 x) { return (x - a) / (b - a); }
  465. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  466. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  467. public static double3 unlerp(double3 a, double3 b, double3 x) { return (x - a) / (b - a); }
  468. /// <summary>Returns the componentwise result of normalizing a floating point value x to a range [a, b]. The opposite of lerp. Equivalent to (x - a) / (b - a).</summary>
  469. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  470. public static double4 unlerp(double4 a, double4 b, double4 x) { return (x - a) / (b - a); }
  471. /// <summary>Returns the result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  472. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  473. public static float remap(float a, float b, float c, float d, float x) { return lerp(c, d, unlerp(a, b, x)); }
  474. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  475. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  476. public static float2 remap(float2 a, float2 b, float2 c, float2 d, float2 x) { return lerp(c, d, unlerp(a, b, x)); }
  477. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  478. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  479. public static float3 remap(float3 a, float3 b, float3 c, float3 d, float3 x) { return lerp(c, d, unlerp(a, b, x)); }
  480. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  481. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  482. public static float4 remap(float4 a, float4 b, float4 c, float4 d, float4 x) { return lerp(c, d, unlerp(a, b, x)); }
  483. /// <summary>Returns the result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  484. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  485. public static double remap(double a, double b, double c, double d, double x) { return lerp(c, d, unlerp(a, b, x)); }
  486. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  487. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  488. public static double2 remap(double2 a, double2 b, double2 c, double2 d, double2 x) { return lerp(c, d, unlerp(a, b, x)); }
  489. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  490. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  491. public static double3 remap(double3 a, double3 b, double3 c, double3 d, double3 x) { return lerp(c, d, unlerp(a, b, x)); }
  492. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d].</summary>
  493. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  494. public static double4 remap(double4 a, double4 b, double4 c, double4 d, double4 x) { return lerp(c, d, unlerp(a, b, x)); }
  495. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 int values.</summary>
  496. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  497. public static int mad(int a, int b, int c) { return a * b + c; }
  498. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int2 vectors.</summary>
  499. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  500. public static int2 mad(int2 a, int2 b, int2 c) { return a * b + c; }
  501. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int3 vectors.</summary>
  502. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  503. public static int3 mad(int3 a, int3 b, int3 c) { return a * b + c; }
  504. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int4 vectors.</summary>
  505. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  506. public static int4 mad(int4 a, int4 b, int4 c) { return a * b + c; }
  507. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 uint values.</summary>
  508. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  509. public static uint mad(uint a, uint b, uint c) { return a * b + c; }
  510. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint2 vectors.</summary>
  511. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  512. public static uint2 mad(uint2 a, uint2 b, uint2 c) { return a * b + c; }
  513. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint3 vectors.</summary>
  514. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  515. public static uint3 mad(uint3 a, uint3 b, uint3 c) { return a * b + c; }
  516. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint4 vectors.</summary>
  517. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  518. public static uint4 mad(uint4 a, uint4 b, uint4 c) { return a * b + c; }
  519. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 long values.</summary>
  520. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  521. public static long mad(long a, long b, long c) { return a * b + c; }
  522. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 ulong values.</summary>
  523. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  524. public static ulong mad(ulong a, ulong b, ulong c) { return a * b + c; }
  525. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 float values.</summary>
  526. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  527. public static float mad(float a, float b, float c) { return a * b + c; }
  528. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float2 vectors.</summary>
  529. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  530. public static float2 mad(float2 a, float2 b, float2 c) { return a * b + c; }
  531. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float3 vectors.</summary>
  532. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  533. public static float3 mad(float3 a, float3 b, float3 c) { return a * b + c; }
  534. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float4 vectors.</summary>
  535. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  536. public static float4 mad(float4 a, float4 b, float4 c) { return a * b + c; }
  537. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 double values.</summary>
  538. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  539. public static double mad(double a, double b, double c) { return a * b + c; }
  540. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double2 vectors.</summary>
  541. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  542. public static double2 mad(double2 a, double2 b, double2 c) { return a * b + c; }
  543. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double3 vectors.</summary>
  544. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  545. public static double3 mad(double3 a, double3 b, double3 c) { return a * b + c; }
  546. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double4 vectors.</summary>
  547. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  548. public static double4 mad(double4 a, double4 b, double4 c) { return a * b + c; }
  549. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are int values.</summary>
  550. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  551. public static int clamp(int x, int a, int b) { return max(a, min(b, x)); }
  552. /// <summary>Returns the result of a componentwise clamping of the int2 x into the interval [a, b], where a and b are int2 vectors.</summary>
  553. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  554. public static int2 clamp(int2 x, int2 a, int2 b) { return max(a, min(b, x)); }
  555. /// <summary>Returns the result of a componentwise clamping of the int3 x into the interval [a, b], where x, a and b are int3 vectors.</summary>
  556. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  557. public static int3 clamp(int3 x, int3 a, int3 b) { return max(a, min(b, x)); }
  558. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are int4 vectors.</summary>
  559. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  560. public static int4 clamp(int4 x, int4 a, int4 b) { return max(a, min(b, x)); }
  561. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are uint values.</summary>
  562. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  563. public static uint clamp(uint x, uint a, uint b) { return max(a, min(b, x)); }
  564. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint2 vectors.</summary>
  565. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  566. public static uint2 clamp(uint2 x, uint2 a, uint2 b) { return max(a, min(b, x)); }
  567. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint3 vectors.</summary>
  568. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  569. public static uint3 clamp(uint3 x, uint3 a, uint3 b) { return max(a, min(b, x)); }
  570. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint4 vectors.</summary>
  571. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  572. public static uint4 clamp(uint4 x, uint4 a, uint4 b) { return max(a, min(b, x)); }
  573. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are long values.</summary>
  574. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  575. public static long clamp(long x, long a, long b) { return max(a, min(b, x)); }
  576. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are ulong values.</summary>
  577. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  578. public static ulong clamp(ulong x, ulong a, ulong b) { return max(a, min(b, x)); }
  579. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are float values.</summary>
  580. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  581. public static float clamp(float x, float a, float b) { return max(a, min(b, x)); }
  582. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float2 vectors.</summary>
  583. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  584. public static float2 clamp(float2 x, float2 a, float2 b) { return max(a, min(b, x)); }
  585. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float3 vectors.</summary>
  586. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  587. public static float3 clamp(float3 x, float3 a, float3 b) { return max(a, min(b, x)); }
  588. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float4 vectors.</summary>
  589. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  590. public static float4 clamp(float4 x, float4 a, float4 b) { return max(a, min(b, x)); }
  591. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are double values.</summary>
  592. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  593. public static double clamp(double x, double a, double b) { return max(a, min(b, x)); }
  594. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double2 vectors.</summary>
  595. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  596. public static double2 clamp(double2 x, double2 a, double2 b) { return max(a, min(b, x)); }
  597. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double3 vectors.</summary>
  598. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  599. public static double3 clamp(double3 x, double3 a, double3 b) { return max(a, min(b, x)); }
  600. /// <summary>Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double4 vectors.</summary>
  601. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  602. public static double4 clamp(double4 x, double4 a, double4 b) { return max(a, min(b, x)); }
  603. /// <summary>Returns the result of clamping the float value x into the interval [0, 1].</summary>
  604. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  605. public static float saturate(float x) { return clamp(x, 0.0f, 1.0f); }
  606. /// <summary>Returns the result of a componentwise clamping of the float2 vector x into the interval [0, 1].</summary>
  607. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  608. public static float2 saturate(float2 x) { return clamp(x, new float2(0.0f), new float2(1.0f)); }
  609. /// <summary>Returns the result of a componentwise clamping of the float3 vector x into the interval [0, 1].</summary>
  610. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  611. public static float3 saturate(float3 x) { return clamp(x, new float3(0.0f), new float3(1.0f)); }
  612. /// <summary>Returns the result of a componentwise clamping of the float4 vector x into the interval [0, 1].</summary>
  613. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  614. public static float4 saturate(float4 x) { return clamp(x, new float4(0.0f), new float4(1.0f)); }
  615. /// <summary>Returns the result of clamping the double value x into the interval [0, 1].</summary>
  616. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  617. public static double saturate(double x) { return clamp(x, 0.0, 1.0); }
  618. /// <summary>Returns the result of a componentwise clamping of the double2 vector x into the interval [0, 1].</summary>
  619. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  620. public static double2 saturate(double2 x) { return clamp(x, new double2(0.0), new double2(1.0)); }
  621. /// <summary>Returns the result of a componentwise clamping of the double3 vector x into the interval [0, 1].</summary>
  622. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  623. public static double3 saturate(double3 x) { return clamp(x, new double3(0.0), new double3(1.0)); }
  624. /// <summary>Returns the result of a componentwise clamping of the double4 vector x into the interval [0, 1].</summary>
  625. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  626. public static double4 saturate(double4 x) { return clamp(x, new double4(0.0), new double4(1.0)); }
  627. /// <summary>Returns the absolute value of a int value.</summary>
  628. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  629. public static int abs(int x) { return max(-x, x); }
  630. /// <summary>Returns the componentwise absolute value of a int2 vector.</summary>
  631. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  632. public static int2 abs(int2 x) { return max(-x, x); }
  633. /// <summary>Returns the componentwise absolute value of a int3 vector.</summary>
  634. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  635. public static int3 abs(int3 x) { return max(-x, x); }
  636. /// <summary>Returns the componentwise absolute value of a int4 vector.</summary>
  637. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  638. public static int4 abs(int4 x) { return max(-x, x); }
  639. /// <summary>Returns the absolute value of a long value.</summary>
  640. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  641. public static long abs(long x) { return max(-x, x); }
  642. /// <summary>Returns the absolute value of a float value.</summary>
  643. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  644. public static float abs(float x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  645. /// <summary>Returns the componentwise absolute value of a float2 vector.</summary>
  646. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  647. public static float2 abs(float2 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  648. /// <summary>Returns the componentwise absolute value of a float3 vector.</summary>
  649. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  650. public static float3 abs(float3 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  651. /// <summary>Returns the componentwise absolute value of a float4 vector.</summary>
  652. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  653. public static float4 abs(float4 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  654. /// <summary>Returns the absolute value of a double value.</summary>
  655. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  656. public static double abs(double x) { return asdouble(asulong(x) & 0x7FFFFFFFFFFFFFFF); }
  657. /// <summary>Returns the componentwise absolute value of a double2 vector.</summary>
  658. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  659. public static double2 abs(double2 x) { return double2(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF)); }
  660. /// <summary>Returns the componentwise absolute value of a double3 vector.</summary>
  661. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  662. public static double3 abs(double3 x) { return double3(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.z) & 0x7FFFFFFFFFFFFFFF)); }
  663. /// <summary>Returns the componentwise absolute value of a double4 vector.</summary>
  664. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  665. public static double4 abs(double4 x) { return double4(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.z) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.w) & 0x7FFFFFFFFFFFFFFF)); }
  666. /// <summary>Returns the dot product of two int values. Equivalent to multiplication.</summary>
  667. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  668. public static int dot(int x, int y) { return x * y; }
  669. /// <summary>Returns the dot product of two int2 vectors.</summary>
  670. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  671. public static int dot(int2 x, int2 y) { return x.x * y.x + x.y * y.y; }
  672. /// <summary>Returns the dot product of two int3 vectors.</summary>
  673. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  674. public static int dot(int3 x, int3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  675. /// <summary>Returns the dot product of two int4 vectors.</summary>
  676. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  677. public static int dot(int4 x, int4 y) { return x.x * y.x + x.y * y.y + x.z * y.z + x.w * y.w; }
  678. /// <summary>Returns the dot product of two uint values. Equivalent to multiplication.</summary>
  679. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  680. public static uint dot(uint x, uint y) { return x * y; }
  681. /// <summary>Returns the dot product of two uint2 vectors.</summary>
  682. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  683. public static uint dot(uint2 x, uint2 y) { return x.x * y.x + x.y * y.y; }
  684. /// <summary>Returns the dot product of two uint3 vectors.</summary>
  685. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  686. public static uint dot(uint3 x, uint3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  687. /// <summary>Returns the dot product of two uint4 vectors.</summary>
  688. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  689. public static uint dot(uint4 x, uint4 y) { return x.x * y.x + x.y * y.y + x.z * y.z + x.w * y.w; }
  690. /// <summary>Returns the dot product of two float values. Equivalent to multiplication.</summary>
  691. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  692. public static float dot(float x, float y) { return x * y; }
  693. /// <summary>Returns the dot product of two float2 vectors.</summary>
  694. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  695. public static float dot(float2 x, float2 y) { return x.x * y.x + x.y * y.y; }
  696. /// <summary>Returns the dot product of two float3 vectors.</summary>
  697. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  698. public static float dot(float3 x, float3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  699. /// <summary>Returns the dot product of two float4 vectors.</summary>
  700. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  701. public static float dot(float4 x, float4 y) { return x.x * y.x + x.y * y.y + x.z * y.z + x.w * y.w; }
  702. /// <summary>Returns the dot product of two double values. Equivalent to multiplication.</summary>
  703. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  704. public static double dot(double x, double y) { return x * y; }
  705. /// <summary>Returns the dot product of two double2 vectors.</summary>
  706. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  707. public static double dot(double2 x, double2 y) { return x.x * y.x + x.y * y.y; }
  708. /// <summary>Returns the dot product of two double3 vectors.</summary>
  709. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  710. public static double dot(double3 x, double3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  711. /// <summary>Returns the dot product of two double4 vectors.</summary>
  712. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  713. public static double dot(double4 x, double4 y) { return x.x * y.x + x.y * y.y + x.z * y.z + x.w * y.w; }
  714. /// <summary>Returns the tangent of a float value.</summary>
  715. public static float tan(float x) { return (float)System.Math.Tan(x); }
  716. /// <summary>Returns the componentwise tangent of a float2 vector.</summary>
  717. public static float2 tan(float2 x) { return new float2(tan(x.x), tan(x.y)); }
  718. /// <summary>Returns the componentwise tangent of a float3 vector.</summary>
  719. public static float3 tan(float3 x) { return new float3(tan(x.x), tan(x.y), tan(x.z)); }
  720. /// <summary>Returns the componentwise tangent of a float4 vector.</summary>
  721. public static float4 tan(float4 x) { return new float4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  722. /// <summary>Returns the tangent of a double value.</summary>
  723. public static double tan(double x) { return System.Math.Tan(x); }
  724. /// <summary>Returns the componentwise tangent of a double2 vector.</summary>
  725. public static double2 tan(double2 x) { return new double2(tan(x.x), tan(x.y)); }
  726. /// <summary>Returns the componentwise tangent of a double3 vector.</summary>
  727. public static double3 tan(double3 x) { return new double3(tan(x.x), tan(x.y), tan(x.z)); }
  728. /// <summary>Returns the componentwise tangent of a double4 vector.</summary>
  729. public static double4 tan(double4 x) { return new double4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  730. /// <summary>Returns the hyperbolic tangent of a float value.</summary>
  731. public static float tanh(float x) { return (float)System.Math.Tanh(x); }
  732. /// <summary>Returns the componentwise hyperbolic tangent of a float2 vector.</summary>
  733. public static float2 tanh(float2 x) { return new float2(tanh(x.x), tanh(x.y)); }
  734. /// <summary>Returns the componentwise hyperbolic tangent of a float3 vector.</summary>
  735. public static float3 tanh(float3 x) { return new float3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  736. /// <summary>Returns the componentwise hyperbolic tangent of a float4 vector.</summary>
  737. public static float4 tanh(float4 x) { return new float4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  738. /// <summary>Returns the hyperbolic tangent of a double value.</summary>
  739. public static double tanh(double x) { return System.Math.Tanh(x); }
  740. /// <summary>Returns the componentwise hyperbolic tangent of a double2 vector.</summary>
  741. public static double2 tanh(double2 x) { return new double2(tanh(x.x), tanh(x.y)); }
  742. /// <summary>Returns the componentwise hyperbolic tangent of a double3 vector.</summary>
  743. public static double3 tanh(double3 x) { return new double3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  744. /// <summary>Returns the componentwise hyperbolic tangent of a double4 vector.</summary>
  745. public static double4 tanh(double4 x) { return new double4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  746. /// <summary>Returns the arctangent of a float value.</summary>
  747. public static float atan(float x) { return (float)System.Math.Atan(x); }
  748. /// <summary>Returns the componentwise arctangent of a float2 vector.</summary>
  749. public static float2 atan(float2 x) { return new float2(atan(x.x), atan(x.y)); }
  750. /// <summary>Returns the componentwise arctangent of a float3 vector.</summary>
  751. public static float3 atan(float3 x) { return new float3(atan(x.x), atan(x.y), atan(x.z)); }
  752. /// <summary>Returns the componentwise arctangent of a float4 vector.</summary>
  753. public static float4 atan(float4 x) { return new float4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  754. /// <summary>Returns the arctangent of a double value.</summary>
  755. public static double atan(double x) { return System.Math.Atan(x); }
  756. /// <summary>Returns the componentwise arctangent of a double2 vector.</summary>
  757. public static double2 atan(double2 x) { return new double2(atan(x.x), atan(x.y)); }
  758. /// <summary>Returns the componentwise arctangent of a double3 vector.</summary>
  759. public static double3 atan(double3 x) { return new double3(atan(x.x), atan(x.y), atan(x.z)); }
  760. /// <summary>Returns the componentwise arctangent of a double4 vector.</summary>
  761. public static double4 atan(double4 x) { return new double4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  762. /// <summary>Returns the 2-argument arctangent of a pair of float values.</summary>
  763. public static float atan2(float y, float x) { return (float)System.Math.Atan2(y, x); }
  764. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats2 vectors.</summary>
  765. public static float2 atan2(float2 y, float2 x) { return new float2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  766. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats3 vectors.</summary>
  767. public static float3 atan2(float3 y, float3 x) { return new float3(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z)); }
  768. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats4 vectors.</summary>
  769. public static float4 atan2(float4 y, float4 x) { return new float4(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z), atan2(y.w, x.w)); }
  770. /// <summary>Returns the 2-argument arctangent of a pair of double values.</summary>
  771. public static double atan2(double y, double x) { return System.Math.Atan2(y, x); }
  772. /// <summary>Returns the 2-argument arctangent of a pair of double2 vectors.</summary>
  773. public static double2 atan2(double2 y, double2 x) { return new double2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  774. /// <summary>Returns the 2-argument arctangent of a pair of double3 vectors.</summary>
  775. public static double3 atan2(double3 y, double3 x) { return new double3(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z)); }
  776. /// <summary>Returns the 2-argument arctangent of a pair of double4 vectors.</summary>
  777. public static double4 atan2(double4 y, double4 x) { return new double4(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z), atan2(y.w, x.w)); }
  778. /// <summary>Returns the cosine of a float value.</summary>
  779. public static float cos(float x) { return (float)System.Math.Cos(x); }
  780. /// <summary>Returns the componentwise cosine of a float2 vector.</summary>
  781. public static float2 cos(float2 x) { return new float2(cos(x.x), cos(x.y)); }
  782. /// <summary>Returns the componentwise cosine of a float3 vector.</summary>
  783. public static float3 cos(float3 x) { return new float3(cos(x.x), cos(x.y), cos(x.z)); }
  784. /// <summary>Returns the componentwise cosine of a float4 vector.</summary>
  785. public static float4 cos(float4 x) { return new float4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  786. /// <summary>Returns the cosine of a double value.</summary>
  787. public static double cos(double x) { return System.Math.Cos(x); }
  788. /// <summary>Returns the componentwise cosine of a double2 vector.</summary>
  789. public static double2 cos(double2 x) { return new double2(cos(x.x), cos(x.y)); }
  790. /// <summary>Returns the componentwise cosine of a double3 vector.</summary>
  791. public static double3 cos(double3 x) { return new double3(cos(x.x), cos(x.y), cos(x.z)); }
  792. /// <summary>Returns the componentwise cosine of a double4 vector.</summary>
  793. public static double4 cos(double4 x) { return new double4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  794. /// <summary>Returns the hyperbolic cosine of a float value.</summary>
  795. public static float cosh(float x) { return (float)System.Math.Cosh(x); }
  796. /// <summary>Returns the componentwise hyperbolic cosine of a float2 vector.</summary>
  797. public static float2 cosh(float2 x) { return new float2(cosh(x.x), cosh(x.y)); }
  798. /// <summary>Returns the componentwise hyperbolic cosine of a float3 vector.</summary>
  799. public static float3 cosh(float3 x) { return new float3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  800. /// <summary>Returns the componentwise hyperbolic cosine of a float4 vector.</summary>
  801. public static float4 cosh(float4 x) { return new float4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  802. /// <summary>Returns the hyperbolic cosine of a double value.</summary>
  803. public static double cosh(double x) { return System.Math.Cosh(x); }
  804. /// <summary>Returns the componentwise hyperbolic cosine of a double2 vector.</summary>
  805. public static double2 cosh(double2 x) { return new double2(cosh(x.x), cosh(x.y)); }
  806. /// <summary>Returns the componentwise hyperbolic cosine of a double3 vector.</summary>
  807. public static double3 cosh(double3 x) { return new double3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  808. /// <summary>Returns the componentwise hyperbolic cosine of a double4 vector.</summary>
  809. public static double4 cosh(double4 x) { return new double4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  810. /// <summary>Returns the arccosine of a float value.</summary>
  811. public static float acos(float x) { return (float)System.Math.Acos((float)x); }
  812. /// <summary>Returns the componentwise arccosine of a float2 vector.</summary>
  813. public static float2 acos(float2 x) { return new float2(acos(x.x), acos(x.y)); }
  814. /// <summary>Returns the componentwise arccosine of a float3 vector.</summary>
  815. public static float3 acos(float3 x) { return new float3(acos(x.x), acos(x.y), acos(x.z)); }
  816. /// <summary>Returns the componentwise arccosine of a float4 vector.</summary>
  817. public static float4 acos(float4 x) { return new float4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  818. /// <summary>Returns the arccosine of a double value.</summary>
  819. public static double acos(double x) { return System.Math.Acos(x); }
  820. /// <summary>Returns the componentwise arccosine of a double2 vector.</summary>
  821. public static double2 acos(double2 x) { return new double2(acos(x.x), acos(x.y)); }
  822. /// <summary>Returns the componentwise arccosine of a double3 vector.</summary>
  823. public static double3 acos(double3 x) { return new double3(acos(x.x), acos(x.y), acos(x.z)); }
  824. /// <summary>Returns the componentwise arccosine of a double4 vector.</summary>
  825. public static double4 acos(double4 x) { return new double4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  826. /// <summary>Returns the sine of a float value.</summary>
  827. public static float sin(float x) { return (float)System.Math.Sin((float)x); }
  828. /// <summary>Returns the componentwise sine of a float2 vector.</summary>
  829. public static float2 sin(float2 x) { return new float2(sin(x.x), sin(x.y)); }
  830. /// <summary>Returns the componentwise sine of a float3 vector.</summary>
  831. public static float3 sin(float3 x) { return new float3(sin(x.x), sin(x.y), sin(x.z)); }
  832. /// <summary>Returns the componentwise sine of a float4 vector.</summary>
  833. public static float4 sin(float4 x) { return new float4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  834. /// <summary>Returns the sine of a double value.</summary>
  835. public static double sin(double x) { return System.Math.Sin(x); }
  836. /// <summary>Returns the componentwise sine of a double2 vector.</summary>
  837. public static double2 sin(double2 x) { return new double2(sin(x.x), sin(x.y)); }
  838. /// <summary>Returns the componentwise sine of a double3 vector.</summary>
  839. public static double3 sin(double3 x) { return new double3(sin(x.x), sin(x.y), sin(x.z)); }
  840. /// <summary>Returns the componentwise sine of a double4 vector.</summary>
  841. public static double4 sin(double4 x) { return new double4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  842. /// <summary>Returns the hyperbolic sine of a float value.</summary>
  843. public static float sinh(float x) { return (float)System.Math.Sinh((float)x); }
  844. /// <summary>Returns the componentwise hyperbolic sine of a float2 vector.</summary>
  845. public static float2 sinh(float2 x) { return new float2(sinh(x.x), sinh(x.y)); }
  846. /// <summary>Returns the componentwise hyperbolic sine of a float3 vector.</summary>
  847. public static float3 sinh(float3 x) { return new float3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  848. /// <summary>Returns the componentwise hyperbolic sine of a float4 vector.</summary>
  849. public static float4 sinh(float4 x) { return new float4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  850. /// <summary>Returns the hyperbolic sine of a double value.</summary>
  851. public static double sinh(double x) { return System.Math.Sinh(x); }
  852. /// <summary>Returns the componentwise hyperbolic sine of a double2 vector.</summary>
  853. public static double2 sinh(double2 x) { return new double2(sinh(x.x), sinh(x.y)); }
  854. /// <summary>Returns the componentwise hyperbolic sine of a double3 vector.</summary>
  855. public static double3 sinh(double3 x) { return new double3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  856. /// <summary>Returns the componentwise hyperbolic sine of a double4 vector.</summary>
  857. public static double4 sinh(double4 x) { return new double4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  858. /// <summary>Returns the arcsine of a float value.</summary>
  859. public static float asin(float x) { return (float)System.Math.Asin((float)x); }
  860. /// <summary>Returns the componentwise arcsine of a float2 vector.</summary>
  861. public static float2 asin(float2 x) { return new float2(asin(x.x), asin(x.y)); }
  862. /// <summary>Returns the componentwise arcsine of a float3 vector.</summary>
  863. public static float3 asin(float3 x) { return new float3(asin(x.x), asin(x.y), asin(x.z)); }
  864. /// <summary>Returns the componentwise arcsine of a float4 vector.</summary>
  865. public static float4 asin(float4 x) { return new float4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  866. /// <summary>Returns the arcsine of a double value.</summary>
  867. public static double asin(double x) { return System.Math.Asin(x); }
  868. /// <summary>Returns the componentwise arcsine of a double2 vector.</summary>
  869. public static double2 asin(double2 x) { return new double2(asin(x.x), asin(x.y)); }
  870. /// <summary>Returns the componentwise arcsine of a double3 vector.</summary>
  871. public static double3 asin(double3 x) { return new double3(asin(x.x), asin(x.y), asin(x.z)); }
  872. /// <summary>Returns the componentwise arcsine of a double4 vector.</summary>
  873. public static double4 asin(double4 x) { return new double4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  874. /// <summary>Returns the result of rounding a float value up to the nearest integral value less or equal to the original value.</summary>
  875. public static float floor(float x) { return (float)System.Math.Floor((float)x); }
  876. /// <summary>Returns the result of rounding each component of a float2 vector value down to the nearest value less or equal to the original value.</summary>
  877. public static float2 floor(float2 x) { return new float2(floor(x.x), floor(x.y)); }
  878. /// <summary>Returns the result of rounding each component of a float3 vector value down to the nearest value less or equal to the original value.</summary>
  879. public static float3 floor(float3 x) { return new float3(floor(x.x), floor(x.y), floor(x.z)); }
  880. /// <summary>Returns the result of rounding each component of a float4 vector value down to the nearest value less or equal to the original value.</summary>
  881. public static float4 floor(float4 x) { return new float4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  882. /// <summary>Returns the result of rounding a double value up to the nearest integral value less or equal to the original value.</summary>
  883. public static double floor(double x) { return System.Math.Floor(x); }
  884. /// <summary>Returns the result of rounding each component of a double2 vector value down to the nearest value less or equal to the original value.</summary>
  885. public static double2 floor(double2 x) { return new double2(floor(x.x), floor(x.y)); }
  886. /// <summary>Returns the result of rounding each component of a double3 vector value down to the nearest value less or equal to the original value.</summary>
  887. public static double3 floor(double3 x) { return new double3(floor(x.x), floor(x.y), floor(x.z)); }
  888. /// <summary>Returns the result of rounding each component of a double4 vector value down to the nearest value less or equal to the original value.</summary>
  889. public static double4 floor(double4 x) { return new double4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  890. /// <summary>Returns the result of rounding a float value up to the nearest integral value greater or equal to the original value.</summary>
  891. public static float ceil(float x) { return (float)System.Math.Ceiling((float)x); }
  892. /// <summary>Returns the result of rounding each component of a float2 vector value up to the nearest value greater or equal to the original value.</summary>
  893. public static float2 ceil(float2 x) { return new float2(ceil(x.x), ceil(x.y)); }
  894. /// <summary>Returns the result of rounding each component of a float3 vector value up to the nearest value greater or equal to the original value.</summary>
  895. public static float3 ceil(float3 x) { return new float3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  896. /// <summary>Returns the result of rounding each component of a float4 vector value up to the nearest value greater or equal to the original value.</summary>
  897. public static float4 ceil(float4 x) { return new float4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  898. /// <summary>Returns the result of rounding a double value up to the nearest greater integral value greater or equal to the original value.</summary>
  899. public static double ceil(double x) { return System.Math.Ceiling(x); }
  900. /// <summary>Returns the result of rounding each component of a double2 vector value up to the nearest integral value greater or equal to the original value.</summary>
  901. public static double2 ceil(double2 x) { return new double2(ceil(x.x), ceil(x.y)); }
  902. /// <summary>Returns the result of rounding each component of a double3 vector value up to the nearest integral value greater or equal to the original value..</summary>
  903. public static double3 ceil(double3 x) { return new double3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  904. /// <summary>Returns the result of rounding each component of a double4 vector value up to the nearest integral value greater or equal to the original value.</summary>
  905. public static double4 ceil(double4 x) { return new double4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  906. /// <summary>Returns the result of rounding a float value to the nearest integral value.</summary>
  907. public static float round(float x) { return (float)System.Math.Round((float)x); }
  908. /// <summary>Returns the result of rounding each component of a float2 vector value to the nearest integral value.</summary>
  909. public static float2 round(float2 x) { return new float2(round(x.x), round(x.y)); }
  910. /// <summary>Returns the result of rounding each component of a float3 vector value to the nearest integral value.</summary>
  911. public static float3 round(float3 x) { return new float3(round(x.x), round(x.y), round(x.z)); }
  912. /// <summary>Returns the result of rounding each component of a float4 vector value to the nearest integral value.</summary>
  913. public static float4 round(float4 x) { return new float4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  914. /// <summary>Returns the result of rounding a double value to the nearest integral value.</summary>
  915. public static double round(double x) { return System.Math.Round(x); }
  916. /// <summary>Returns the result of rounding each component of a double2 vector value to the nearest integral value.</summary>
  917. public static double2 round(double2 x) { return new double2(round(x.x), round(x.y)); }
  918. /// <summary>Returns the result of rounding each component of a double3 vector value to the nearest integral value.</summary>
  919. public static double3 round(double3 x) { return new double3(round(x.x), round(x.y), round(x.z)); }
  920. /// <summary>Returns the result of rounding each component of a double4 vector value to the nearest integral value.</summary>
  921. public static double4 round(double4 x) { return new double4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  922. /// <summary>Returns the result of truncating a float value to an integral float value.</summary>
  923. public static float trunc(float x) { return (float)System.Math.Truncate((float)x); }
  924. /// <summary>Returns the result of a componentwise truncation of a float2 value to an integral float2 value.</summary>
  925. public static float2 trunc(float2 x) { return new float2(trunc(x.x), trunc(x.y)); }
  926. /// <summary>Returns the result of a componentwise truncation of a float3 value to an integral float3 value.</summary>
  927. public static float3 trunc(float3 x) { return new float3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  928. /// <summary>Returns the result of a componentwise truncation of a float4 value to an integral float4 value.</summary>
  929. public static float4 trunc(float4 x) { return new float4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  930. /// <summary>Returns the result of truncating a double value to an integral double value.</summary>
  931. public static double trunc(double x) { return System.Math.Truncate(x); }
  932. /// <summary>Returns the result of a componentwise truncation of a double2 value to an integral double2 value.</summary>
  933. public static double2 trunc(double2 x) { return new double2(trunc(x.x), trunc(x.y)); }
  934. /// <summary>Returns the result of a componentwise truncation of a double3 value to an integral double3 value.</summary>
  935. public static double3 trunc(double3 x) { return new double3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  936. /// <summary>Returns the result of a componentwise truncation of a double4 value to an integral double4 value.</summary>
  937. public static double4 trunc(double4 x) { return new double4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  938. /// <summary>Returns the fractional part of a float value.</summary>
  939. public static float frac(float x) { return x - floor(x); }
  940. /// <summary>Returns the componentwise fractional parts of a float2 vector.</summary>
  941. public static float2 frac(float2 x) { return x - floor(x); }
  942. /// <summary>Returns the componentwise fractional parts of a float3 vector.</summary>
  943. public static float3 frac(float3 x) { return x - floor(x); }
  944. /// <summary>Returns the componentwise fractional parts of a float4 vector.</summary>
  945. public static float4 frac(float4 x) { return x - floor(x); }
  946. /// <summary>Returns the fractional part of a double value.</summary>
  947. public static double frac(double x) { return x - floor(x); }
  948. /// <summary>Returns the componentwise fractional parts of a double2 vector.</summary>
  949. public static double2 frac(double2 x) { return x - floor(x); }
  950. /// <summary>Returns the componentwise fractional parts of a double3 vector.</summary>
  951. public static double3 frac(double3 x) { return x - floor(x); }
  952. /// <summary>Returns the componentwise fractional parts of a double4 vector.</summary>
  953. public static double4 frac(double4 x) { return x - floor(x); }
  954. /// <summary>Returns the reciprocal a float value.</summary>
  955. public static float rcp(float x) { return 1.0f / x; }
  956. /// <summary>Returns the componentwise reciprocal a float2 vector.</summary>
  957. public static float2 rcp(float2 x) { return 1.0f / x; }
  958. /// <summary>Returns the componentwise reciprocal a float3 vector.</summary>
  959. public static float3 rcp(float3 x) { return 1.0f / x; }
  960. /// <summary>Returns the componentwise reciprocal a float4 vector.</summary>
  961. public static float4 rcp(float4 x) { return 1.0f / x; }
  962. /// <summary>Returns the reciprocal a double value.</summary>
  963. public static double rcp(double x) { return 1.0 / x; }
  964. /// <summary>Returns the componentwise reciprocal a double2 vector.</summary>
  965. public static double2 rcp(double2 x) { return 1.0 / x; }
  966. /// <summary>Returns the componentwise reciprocal a double3 vector.</summary>
  967. public static double3 rcp(double3 x) { return 1.0 / x; }
  968. /// <summary>Returns the componentwise reciprocal a double4 vector.</summary>
  969. public static double4 rcp(double4 x) { return 1.0 / x; }
  970. /// <summary>Returns the sign of a float value. -1.0f if it is less than zero, 0.0f if it is zero and 1.0f if it greater than zero.</summary>
  971. public static float sign(float x) { return (x > 0.0f ? 1.0f : 0.0f) - (x < 0.0f ? 1.0f : 0.0f); }
  972. /// <summary>Returns the componentwise sign of a float2 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components.</summary>
  973. public static float2 sign(float2 x) { return new float2(sign(x.x), sign(x.y)); }
  974. /// <summary>Returns the componentwise sign of a float3 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components.</summary>
  975. public static float3 sign(float3 x) { return new float3(sign(x.x), sign(x.y), sign(x.z)); }
  976. /// <summary>Returns the componentwise sign of a float4 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components.</summary>
  977. public static float4 sign(float4 x) { return new float4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  978. /// <summary>Returns the sign of a double value. -1.0 if it is less than zero, 0.0 if it is zero and 1.0 if it greater than zero.</summary>
  979. public static double sign(double x) { return x == 0 ? 0 : (x > 0.0 ? 1.0 : 0.0) - (x < 0.0 ? 1.0 : 0.0); }
  980. /// <summary>Returns the componentwise sign of a double2 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components.</summary>
  981. public static double2 sign(double2 x) { return new double2(sign(x.x), sign(x.y)); }
  982. /// <summary>Returns the componentwise sign of a double3 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components.</summary>
  983. public static double3 sign(double3 x) { return new double3(sign(x.x), sign(x.y), sign(x.z)); }
  984. /// <summary>Returns the componentwise sign of a double4 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components.</summary>
  985. public static double4 sign(double4 x) { return new double4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  986. /// <summary>Returns x raised to the power y.</summary>
  987. public static float pow(float x, float y) { return (float)System.Math.Pow((float)x, (float)y); }
  988. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  989. public static float2 pow(float2 x, float2 y) { return new float2(pow(x.x, y.x), pow(x.y, y.y)); }
  990. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  991. public static float3 pow(float3 x, float3 y) { return new float3(pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z)); }
  992. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  993. public static float4 pow(float4 x, float4 y) { return new float4(pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z), pow(x.w, y.w)); }
  994. /// <summary>Returns x raised to the power y.</summary>
  995. public static double pow(double x, double y) { return System.Math.Pow(x, y); }
  996. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  997. public static double2 pow(double2 x, double2 y) { return new double2(pow(x.x, y.x), pow(x.y, y.y)); }
  998. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  999. public static double3 pow(double3 x, double3 y) { return new double3(pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z)); }
  1000. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  1001. public static double4 pow(double4 x, double4 y) { return new double4(pow(x.x, y.x), pow(x.y, y.y), pow(x.z, y.z), pow(x.w, y.w)); }
  1002. /// <summary>Returns the base-e exponential of x.</summary>
  1003. public static float exp(float x) { return (float)System.Math.Exp((float)x); }
  1004. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1005. public static float2 exp(float2 x) { return new float2(exp(x.x), exp(x.y)); }
  1006. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1007. public static float3 exp(float3 x) { return new float3(exp(x.x), exp(x.y), exp(x.z)); }
  1008. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1009. public static float4 exp(float4 x) { return new float4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  1010. /// <summary>Returns the base-e exponential of x.</summary>
  1011. public static double exp(double x) { return System.Math.Exp(x); }
  1012. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1013. public static double2 exp(double2 x) { return new double2(exp(x.x), exp(x.y)); }
  1014. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1015. public static double3 exp(double3 x) { return new double3(exp(x.x), exp(x.y), exp(x.z)); }
  1016. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  1017. public static double4 exp(double4 x) { return new double4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  1018. /// <summary>Returns the base-2 exponential of x.</summary>
  1019. public static float exp2(float x) { return (float)System.Math.Exp((float)x * 0.69314718f); }
  1020. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1021. public static float2 exp2(float2 x) { return new float2(exp2(x.x), exp2(x.y)); }
  1022. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1023. public static float3 exp2(float3 x) { return new float3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  1024. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1025. public static float4 exp2(float4 x) { return new float4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  1026. /// <summary>Returns the base-2 exponential of x.</summary>
  1027. public static double exp2(double x) { return System.Math.Exp(x * 0.693147180559945309); }
  1028. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1029. public static double2 exp2(double2 x) { return new double2(exp2(x.x), exp2(x.y)); }
  1030. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1031. public static double3 exp2(double3 x) { return new double3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  1032. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  1033. public static double4 exp2(double4 x) { return new double4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  1034. /// <summary>Returns the base-10 exponential of x.</summary>
  1035. public static float exp10(float x) { return (float)System.Math.Exp((float)x * 2.30258509f); }
  1036. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1037. public static float2 exp10(float2 x) { return new float2(exp10(x.x), exp10(x.y)); }
  1038. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1039. public static float3 exp10(float3 x) { return new float3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  1040. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1041. public static float4 exp10(float4 x) { return new float4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  1042. /// <summary>Returns the base-10 exponential of x.</summary>
  1043. public static double exp10(double x) { return System.Math.Exp(x * 2.302585092994045684); }
  1044. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1045. public static double2 exp10(double2 x) { return new double2(exp10(x.x), exp10(x.y)); }
  1046. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1047. public static double3 exp10(double3 x) { return new double3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  1048. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  1049. public static double4 exp10(double4 x) { return new double4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  1050. /// <summary>Returns the natural logarithm of a float value.</summary>
  1051. public static float log(float x) { return (float)System.Math.Log((float)x); }
  1052. /// <summary>Returns the componentwise natural logarithm of a float2 vector.</summary>
  1053. public static float2 log(float2 x) { return new float2(log(x.x), log(x.y)); }
  1054. /// <summary>Returns the componentwise natural logarithm of a float3 vector.</summary>
  1055. public static float3 log(float3 x) { return new float3(log(x.x), log(x.y), log(x.z)); }
  1056. /// <summary>Returns the componentwise natural logarithm of a float4 vector.</summary>
  1057. public static float4 log(float4 x) { return new float4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  1058. /// <summary>Returns the natural logarithm of a double value.</summary>
  1059. public static double log(double x) { return System.Math.Log(x); }
  1060. /// <summary>Returns the componentwise natural logarithm of a double2 vector.</summary>
  1061. public static double2 log(double2 x) { return new double2(log(x.x), log(x.y)); }
  1062. /// <summary>Returns the componentwise natural logarithm of a double3 vector.</summary>
  1063. public static double3 log(double3 x) { return new double3(log(x.x), log(x.y), log(x.z)); }
  1064. /// <summary>Returns the componentwise natural logarithm of a double4 vector.</summary>
  1065. public static double4 log(double4 x) { return new double4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  1066. /// <summary>Returns the base-2 logarithm of a float value.</summary>
  1067. public static float log2(float x) { return (float)System.Math.Log((float)x, 2.0f); }
  1068. /// <summary>Returns the componentwise base-2 logarithm of a float2 vector.</summary>
  1069. public static float2 log2(float2 x) { return new float2(log2(x.x), log2(x.y)); }
  1070. /// <summary>Returns the componentwise base-2 logarithm of a float3 vector.</summary>
  1071. public static float3 log2(float3 x) { return new float3(log2(x.x), log2(x.y), log2(x.z)); }
  1072. /// <summary>Returns the componentwise base-2 logarithm of a float4 vector.</summary>
  1073. public static float4 log2(float4 x) { return new float4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  1074. /// <summary>Returns the base-2 logarithm of a double value.</summary>
  1075. public static double log2(double x) { return System.Math.Log(x, 2.0); }
  1076. /// <summary>Returns the componentwise base-2 logarithm of a double2 vector.</summary>
  1077. public static double2 log2(double2 x) { return new double2(log2(x.x), log2(x.y)); }
  1078. /// <summary>Returns the componentwise base-2 logarithm of a double3 vector.</summary>
  1079. public static double3 log2(double3 x) { return new double3(log2(x.x), log2(x.y), log2(x.z)); }
  1080. /// <summary>Returns the componentwise base-2 logarithm of a double4 vector.</summary>
  1081. public static double4 log2(double4 x) { return new double4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  1082. /// <summary>Returns the base-10 logarithm of a float value.</summary>
  1083. public static float log10(float x) { return (float)System.Math.Log10((float)x); }
  1084. /// <summary>Returns the componentwise base-10 logarithm of a float2 vector.</summary>
  1085. public static float2 log10(float2 x) { return new float2(log10(x.x), log10(x.y)); }
  1086. /// <summary>Returns the componentwise base-10 logarithm of a float3 vector.</summary>
  1087. public static float3 log10(float3 x) { return new float3(log10(x.x), log10(x.y), log10(x.z)); }
  1088. /// <summary>Returns the componentwise base-10 logarithm of a float4 vector.</summary>
  1089. public static float4 log10(float4 x) { return new float4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  1090. /// <summary>Returns the base-10 logarithm of a double value.</summary>
  1091. public static double log10(double x) { return System.Math.Log10(x); }
  1092. /// <summary>Returns the componentwise base-10 logarithm of a double2 vector.</summary>
  1093. public static double2 log10(double2 x) { return new double2(log10(x.x), log10(x.y)); }
  1094. /// <summary>Returns the componentwise base-10 logarithm of a double3 vector.</summary>
  1095. public static double3 log10(double3 x) { return new double3(log10(x.x), log10(x.y), log10(x.z)); }
  1096. /// <summary>Returns the componentwise base-10 logarithm of a double4 vector.</summary>
  1097. public static double4 log10(double4 x) { return new double4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  1098. /// <summary>Returns the floating point remainder of x/y.</summary>
  1099. public static float fmod(float x, float y) { return x % y; }
  1100. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  1101. public static float2 fmod(float2 x, float2 y) { return new float2(x.x % y.x, x.y % y.y); }
  1102. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  1103. public static float3 fmod(float3 x, float3 y) { return new float3(x.x % y.x, x.y % y.y, x.z % y.z); }
  1104. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  1105. public static float4 fmod(float4 x, float4 y) { return new float4(x.x % y.x, x.y % y.y, x.z % y.z, x.w % y.w); }
  1106. /// <summary>Returns the double precision floating point remainder of x/y.</summary>
  1107. public static double fmod(double x, double y) { return x % y; }
  1108. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  1109. public static double2 fmod(double2 x, double2 y) { return new double2(x.x % y.x, x.y % y.y); }
  1110. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  1111. public static double3 fmod(double3 x, double3 y) { return new double3(x.x % y.x, x.y % y.y, x.z % y.z); }
  1112. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  1113. public static double4 fmod(double4 x, double4 y) { return new double4(x.x % y.x, x.y % y.y, x.z % y.z, x.w % y.w); }
  1114. /// <summary>Splits a float value into an integral part i and a fractional part that gets returned. Both parts take the sign of the input.</summary>
  1115. public static float modf(float x, out float i) { i = trunc(x); return x - i; }
  1116. /// <summary>
  1117. // Performs a componentwise split of a float2 vector into an integral part i and a fractional part that gets returned.
  1118. // Both parts take the sign of the corresponding input component.
  1119. // </summary>
  1120. public static float2 modf(float2 x, out float2 i) { i = trunc(x); return x - i; }
  1121. /// <summary>
  1122. // Performs a componentwise split of a float3 vector into an integral part i and a fractional part that gets returned.
  1123. // Both parts take the sign of the corresponding input component.
  1124. // </summary>
  1125. public static float3 modf(float3 x, out float3 i) { i = trunc(x); return x - i; }
  1126. /// <summary>
  1127. // Performs a componentwise split of a float4 vector into an integral part i and a fractional part that gets returned.
  1128. // Both parts take the sign of the corresponding input component.
  1129. // </summary>
  1130. public static float4 modf(float4 x, out float4 i) { i = trunc(x); return x - i; }
  1131. /// <summary>Splits a double value into an integral part i and a fractional part that gets returned. Both parts take the sign of the input.</summary>
  1132. public static double modf(double x, out double i) { i = trunc(x); return x - i; }
  1133. /// <summary>
  1134. // Performs a componentwise split of a double2 vector into an integral part i and a fractional part that gets returned.
  1135. // Both parts take the sign of the corresponding input component.
  1136. // </summary>
  1137. public static double2 modf(double2 x, out double2 i) { i = trunc(x); return x - i; }
  1138. /// <summary>
  1139. // Performs a componentwise split of a double3 vector into an integral part i and a fractional part that gets returned.
  1140. // Both parts take the sign of the corresponding input component.
  1141. // </summary>
  1142. public static double3 modf(double3 x, out double3 i) { i = trunc(x); return x - i; }
  1143. /// <summary>
  1144. // Performs a componentwise split of a double4 vector into an integral part i and a fractional part that gets returned.
  1145. // Both parts take the sign of the corresponding input component.
  1146. // </summary>
  1147. public static double4 modf(double4 x, out double4 i) { i = trunc(x); return x - i; }
  1148. /// <summary>Returns the square root of a float value.</summary>
  1149. public static float sqrt(float x) { return (float)System.Math.Sqrt((float)x); }
  1150. /// <summary>Returns the componentwise square root of a float2 vector.</summary>
  1151. public static float2 sqrt(float2 x) { return new float2(sqrt(x.x), sqrt(x.y)); }
  1152. /// <summary>Returns the componentwise square root of a float3 vector.</summary>
  1153. public static float3 sqrt(float3 x) { return new float3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  1154. /// <summary>Returns the componentwise square root of a float4 vector.</summary>
  1155. public static float4 sqrt(float4 x) { return new float4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  1156. /// <summary>Returns the square root of a double value.</summary>
  1157. public static double sqrt(double x) { return System.Math.Sqrt(x); }
  1158. /// <summary>Returns the componentwise square root of a double2 vector.</summary>
  1159. public static double2 sqrt(double2 x) { return new double2(sqrt(x.x), sqrt(x.y)); }
  1160. /// <summary>Returns the componentwise square root of a double3 vector.</summary>
  1161. public static double3 sqrt(double3 x) { return new double3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  1162. /// <summary>Returns the componentwise square root of a double4 vector.</summary>
  1163. public static double4 sqrt(double4 x) { return new double4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  1164. /// <summary>Returns the reciprocal square root of a float value.</summary>
  1165. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1166. public static float rsqrt(float x) { return 1.0f / sqrt(x); }
  1167. /// <summary>Returns the componentwise reciprocal square root of a float2 vector.</summary>
  1168. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1169. public static float2 rsqrt(float2 x) { return 1.0f / sqrt(x); }
  1170. /// <summary>Returns the componentwise reciprocal square root of a float3 vector.</summary>
  1171. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1172. public static float3 rsqrt(float3 x) { return 1.0f / sqrt(x); }
  1173. /// <summary>Returns the componentwise reciprocal square root of a float4 vector</summary>
  1174. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1175. public static float4 rsqrt(float4 x) { return 1.0f / sqrt(x); }
  1176. /// <summary>Returns the reciprocal square root of a double value.</summary>
  1177. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1178. public static double rsqrt(double x) { return 1.0 / sqrt(x); }
  1179. /// <summary>Returns the componentwise reciprocal square root of a double2 vector.</summary>
  1180. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1181. public static double2 rsqrt(double2 x) { return 1.0 / sqrt(x); }
  1182. /// <summary>Returns the componentwise reciprocal square root of a double3 vector.</summary>
  1183. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1184. public static double3 rsqrt(double3 x) { return 1.0 / sqrt(x); }
  1185. /// <summary>Returns the componentwise reciprocal square root of a double4 vector.</summary>
  1186. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1187. public static double4 rsqrt(double4 x) { return 1.0 / sqrt(x); }
  1188. /// <summary>Returns a normalized version of the float2 vector x by scaling it by 1 / length(x).</summary>
  1189. public static float2 normalize(float2 x) { return rsqrt(dot(x, x)) * x; }
  1190. /// <summary>Returns a normalized version of the float3 vector x by scaling it by 1 / length(x).</summary>
  1191. public static float3 normalize(float3 x) { return rsqrt(dot(x, x)) * x; }
  1192. /// <summary>Returns a normalized version of the float4 vector x by scaling it by 1 / length(x).</summary>
  1193. public static float4 normalize(float4 x) { return rsqrt(dot(x, x)) * x; }
  1194. /// <summary>Returns a normalized version of the double2 vector x by scaling it by 1 / length(x).</summary>
  1195. public static double2 normalize(double2 x) { return rsqrt(dot(x, x)) * x; }
  1196. /// <summary>Returns a normalized version of the double3 vector x by scaling it by 1 / length(x).</summary>
  1197. public static double3 normalize(double3 x) { return rsqrt(dot(x, x)) * x; }
  1198. /// <summary>Returns a normalized version of the double4 vector x by scaling it by 1 / length(x).</summary>
  1199. public static double4 normalize(double4 x) { return rsqrt(dot(x, x)) * x; }
  1200. /// <summary>
  1201. /// Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x).
  1202. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1203. /// </summary>
  1204. static public float2 normalizesafe(float2 x, float2 defaultvalue = new float2())
  1205. {
  1206. float len = math.dot(x, x);
  1207. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1208. }
  1209. /// <summary>
  1210. /// Returns a safe normalized version of the float3 vector x by scaling it by 1 / length(x).
  1211. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1212. /// </summary>
  1213. static public float3 normalizesafe(float3 x, float3 defaultvalue = new float3())
  1214. {
  1215. float len = math.dot(x, x);
  1216. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1217. }
  1218. /// <summary>
  1219. /// Returns a safe normalized version of the float4 vector x by scaling it by 1 / length(x).
  1220. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1221. /// </summary>
  1222. static public float4 normalizesafe(float4 x, float4 defaultvalue = new float4())
  1223. {
  1224. float len = math.dot(x, x);
  1225. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1226. }
  1227. /// <summary>
  1228. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  1229. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1230. /// </summary>
  1231. static public double2 normalizesafe(double2 x, double2 defaultvalue = new double2())
  1232. {
  1233. double len = math.dot(x, x);
  1234. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1235. }
  1236. /// <summary>
  1237. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  1238. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1239. /// </summary>
  1240. static public double3 normalizesafe(double3 x, double3 defaultvalue = new double3())
  1241. {
  1242. double len = math.dot(x, x);
  1243. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1244. }
  1245. /// <summary>
  1246. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  1247. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  1248. /// </summary>
  1249. static public double4 normalizesafe(double4 x, double4 defaultvalue = new double4())
  1250. {
  1251. double len = math.dot(x, x);
  1252. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  1253. }
  1254. /// <summary>Returns the length of a float value. Equivalent to the absolute value.</summary>
  1255. public static float length(float x) { return abs(x); }
  1256. /// <summary>Returns the length of a float2 vector.</summary>
  1257. public static float length(float2 x) { return sqrt(dot(x, x)); }
  1258. /// <summary>Returns the length of a float3 vector.</summary>
  1259. public static float length(float3 x) { return sqrt(dot(x, x)); }
  1260. /// <summary>Returns the length of a float4 vector.</summary>
  1261. public static float length(float4 x) { return sqrt(dot(x, x)); }
  1262. /// <summary>Returns the length of a double value. Equivalent to the absolute value.</summary>
  1263. public static double length(double x) { return abs(x); }
  1264. /// <summary>Returns the length of a double2 vector.</summary>
  1265. public static double length(double2 x) { return sqrt(dot(x, x)); }
  1266. /// <summary>Returns the length of a double3 vector.</summary>
  1267. public static double length(double3 x) { return sqrt(dot(x, x)); }
  1268. /// <summary>Returns the length of a double4 vector.</summary>
  1269. public static double length(double4 x) { return sqrt(dot(x, x)); }
  1270. /// <summary>Returns the squared length of a float value. Equivalent to squaring the value.</summary>
  1271. public static float lengthsq(float x) { return x*x; }
  1272. /// <summary>Returns the squared length of a float2 vector.</summary>
  1273. public static float lengthsq(float2 x) { return dot(x, x); }
  1274. /// <summary>Returns the squared length of a float3 vector.</summary>
  1275. public static float lengthsq(float3 x) { return dot(x, x); }
  1276. /// <summary>Returns the squared length of a float4 vector.</summary>
  1277. public static float lengthsq(float4 x) { return dot(x, x); }
  1278. /// <summary>Returns the squared length of a double value. Equivalent to squaring the value.</summary>
  1279. public static double lengthsq(double x) { return x * x; }
  1280. /// <summary>Returns the squared length of a double2 vector.</summary>
  1281. public static double lengthsq(double2 x) { return dot(x, x); }
  1282. /// <summary>Returns the squared length of a double3 vector.</summary>
  1283. public static double lengthsq(double3 x) { return dot(x, x); }
  1284. /// <summary>Returns the squared length of a double4 vector.</summary>
  1285. public static double lengthsq(double4 x) { return dot(x, x); }
  1286. /// <summary>Returns the distance between two float values.</summary>
  1287. public static float distance(float x, float y) { return abs(y - x); }
  1288. /// <summary>Returns the distance between two float2 vectors.</summary>
  1289. public static float distance(float2 x, float2 y) { return length(y - x); }
  1290. /// <summary>Returns the distance between two float3 vectors.</summary>
  1291. public static float distance(float3 x, float3 y) { return length(y - x); }
  1292. /// <summary>Returns the distance between two float4 vectors.</summary>
  1293. public static float distance(float4 x, float4 y) { return length(y - x); }
  1294. /// <summary>Returns the distance between two double values.</summary>
  1295. public static double distance(double x, double y) { return abs(y - x); }
  1296. /// <summary>Returns the distance between two double2 vectors.</summary>
  1297. public static double distance(double2 x, double2 y) { return length(y - x); }
  1298. /// <summary>Returns the distance between two double3 vectors.</summary>
  1299. public static double distance(double3 x, double3 y) { return length(y - x); }
  1300. /// <summary>Returns the distance between two double4 vectors.</summary>
  1301. public static double distance(double4 x, double4 y) { return length(y - x); }
  1302. /// <summary>Returns the distance between two float values.</summary>
  1303. public static float distancesq(float x, float y) { return (y - x) * (y - x); }
  1304. /// <summary>Returns the distance between two float2 vectors.</summary>
  1305. public static float distancesq(float2 x, float2 y) { return lengthsq(y - x); }
  1306. /// <summary>Returns the distance between two float3 vectors.</summary>
  1307. public static float distancesq(float3 x, float3 y) { return lengthsq(y - x); }
  1308. /// <summary>Returns the distance between two float4 vectors.</summary>
  1309. public static float distancesq(float4 x, float4 y) { return lengthsq(y - x); }
  1310. /// <summary>Returns the distance between two double values.</summary>
  1311. public static double distancesq(double x, double y) { return (y - x) * (y - x); }
  1312. /// <summary>Returns the distance between two double2 vectors.</summary>
  1313. public static double distancesq(double2 x, double2 y) { return lengthsq(y - x); }
  1314. /// <summary>Returns the distance between two double3 vectors.</summary>
  1315. public static double distancesq(double3 x, double3 y) { return lengthsq(y - x); }
  1316. /// <summary>Returns the distance between two double4 vectors.</summary>
  1317. public static double distancesq(double4 x, double4 y) { return lengthsq(y - x); }
  1318. /// <summary>Returns the cross product of two float3 vectors.</summary>
  1319. public static float3 cross(float3 x, float3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  1320. /// <summary>Returns the cross product of two double3 vectors.</summary>
  1321. public static double3 cross(double3 x, double3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  1322. /// <summary>Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  1323. public static float smoothstep(float a, float b, float x)
  1324. {
  1325. var t = saturate((x - a) / (b - a));
  1326. return t * t * (3.0f - (2.0f * t));
  1327. }
  1328. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  1329. public static float2 smoothstep(float2 a, float2 b, float2 x)
  1330. {
  1331. var t = saturate((x - a) / (b - a));
  1332. return t * t * (3.0f - (2.0f * t));
  1333. }
  1334. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  1335. public static float3 smoothstep(float3 a, float3 b, float3 x)
  1336. {
  1337. var t = saturate((x - a) / (b - a));
  1338. return t * t * (3.0f - (2.0f * t));
  1339. }
  1340. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  1341. public static float4 smoothstep(float4 a, float4 b, float4 x)
  1342. {
  1343. var t = saturate((x - a) / (b - a));
  1344. return t * t * (3.0f - (2.0f * t));
  1345. }
  1346. /// <summary>Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  1347. public static double smoothstep(double a, double b, double x)
  1348. {
  1349. var t = saturate((x - a) / (b - a));
  1350. return t * t * (3.0 - (2.0 * t));
  1351. }
  1352. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  1353. public static double2 smoothstep(double2 a, double2 b, double2 x)
  1354. {
  1355. var t = saturate((x - a) / (b - a));
  1356. return t * t * (3.0 - (2.0 * t));
  1357. }
  1358. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  1359. public static double3 smoothstep(double3 a, double3 b, double3 x)
  1360. {
  1361. var t = saturate((x - a) / (b - a));
  1362. return t * t * (3.0 - (2.0 * t));
  1363. }
  1364. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  1365. public static double4 smoothstep(double4 a, double4 b, double4 x)
  1366. {
  1367. var t = saturate((x - a) / (b - a));
  1368. return t * t * (3.0 - (2.0 * t));
  1369. }
  1370. /// <summary>Returns true if any component of the input bool2 vector is true, false otherwise.</summary>
  1371. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1372. public static bool any(bool2 x) { return x.x || x.y; }
  1373. /// <summary>Returns true if any component of the input bool3 vector is true, false otherwise.</summary>
  1374. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1375. public static bool any(bool3 x) { return x.x || x.y || x.z; }
  1376. /// <summary>Returns true if any components of the input bool4 vector is true, false otherwise.</summary>
  1377. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1378. public static bool any(bool4 x) { return x.x || x.y || x.z || x.w; }
  1379. /// <summary>Returns true if any component of the input int2 vector is non-zero, false otherwise.</summary>
  1380. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1381. public static bool any(int2 x) { return x.x != 0 || x.y != 0; }
  1382. /// <summary>Returns true if any component of the input int3 vector is non-zero, false otherwise.</summary>
  1383. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1384. public static bool any(int3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  1385. /// <summary>Returns true if any components of the input int4 vector is non-zero, false otherwise.</summary>
  1386. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1387. public static bool any(int4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  1388. /// <summary>Returns true if any component of the input uint2 vector is non-zero, false otherwise.</summary>
  1389. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1390. public static bool any(uint2 x) { return x.x != 0 || x.y != 0; }
  1391. /// <summary>Returns true if any component of the input uint3 vector is non-zero, false otherwise.</summary>
  1392. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1393. public static bool any(uint3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  1394. /// <summary>Returns true if any components of the input uint4 vector is non-zero, false otherwise.</summary>
  1395. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1396. public static bool any(uint4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  1397. /// <summary>Returns true if any component of the input float2 vector is non-zero, false otherwise.</summary>
  1398. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1399. public static bool any(float2 x) { return x.x != 0.0f || x.y != 0.0f; }
  1400. /// <summary>Returns true if any component of the input float3 vector is non-zero, false otherwise.</summary>
  1401. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1402. public static bool any(float3 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f; }
  1403. /// <summary>Returns true if any component of the input float4 vector is non-zero, false otherwise.</summary>
  1404. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1405. public static bool any(float4 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f || x.w != 0.0f; }
  1406. /// <summary>Returns true if any component of the input double2 vector is non-zero, false otherwise.</summary>
  1407. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1408. public static bool any(double2 x) { return x.x != 0.0 || x.y != 0.0; }
  1409. /// <summary>Returns true if any component of the input double3 vector is non-zero, false otherwise.</summary>
  1410. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1411. public static bool any(double3 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0; }
  1412. /// <summary>Returns true if any component of the input double4 vector is non-zero, false otherwise.</summary>
  1413. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1414. public static bool any(double4 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0 || x.w != 0.0; }
  1415. /// <summary>Returns true if all components of the input bool2 vector are true, false otherwise.</summary>
  1416. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1417. public static bool all(bool2 x) { return x.x && x.y; }
  1418. /// <summary>Returns true if all components of the input bool3 vector are true, false otherwise.</summary>
  1419. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1420. public static bool all(bool3 x) { return x.x && x.y && x.z; }
  1421. /// <summary>Returns true if all components of the input bool4 vector are true, false otherwise.</summary>
  1422. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1423. public static bool all(bool4 x) { return x.x && x.y && x.z && x.w; }
  1424. /// <summary>Returns true if all components of the input int2 vector are non-zero, false otherwise.</summary>
  1425. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1426. public static bool all(int2 x) { return x.x != 0 && x.y != 0; }
  1427. /// <summary>Returns true if all components of the input int3 vector are non-zero, false otherwise.</summary>
  1428. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1429. public static bool all(int3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  1430. /// <summary>Returns true if all components of the input int4 vector are non-zero, false otherwise.</summary>
  1431. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1432. public static bool all(int4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  1433. /// <summary>Returns true if all components of the input uint2 vector are non-zero, false otherwise.</summary>
  1434. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1435. public static bool all(uint2 x) { return x.x != 0 && x.y != 0; }
  1436. /// <summary>Returns true if all components of the input uint3 vector are non-zero, false otherwise.</summary>
  1437. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1438. public static bool all(uint3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  1439. /// <summary>Returns true if all components of the input uint4 vector are non-zero, false otherwise.</summary>
  1440. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1441. public static bool all(uint4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  1442. /// <summary>Returns true if all components of the input float2 vector are non-zero, false otherwise.</summary>
  1443. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1444. public static bool all(float2 x) { return x.x != 0.0f && x.y != 0.0f; }
  1445. /// <summary>Returns true if all components of the input float3 vector are non-zero, false otherwise.</summary>
  1446. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1447. public static bool all(float3 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f; }
  1448. /// <summary>Returns true if all components of the input float4 vector are non-zero, false otherwise.</summary>
  1449. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1450. public static bool all(float4 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f && x.w != 0.0f; }
  1451. /// <summary>Returns true if all components of the input double2 vector are non-zero, false otherwise.</summary>
  1452. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1453. public static bool all(double2 x) { return x.x != 0.0 && x.y != 0.0; }
  1454. /// <summary>Returns true if all components of the input double3 vector are non-zero, false otherwise.</summary>
  1455. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1456. public static bool all(double3 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0; }
  1457. /// <summary>Returns true if all components of the input double4 vector are non-zero, false otherwise.</summary>
  1458. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1459. public static bool all(double4 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0 && x.w != 0.0; }
  1460. /// <summary>Returns b if c is true, a otherwise.</summary>
  1461. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1462. public static int select(int a, int b, bool c) { return c ? b : a; }
  1463. /// <summary>Returns b if c is true, a otherwise.</summary>
  1464. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1465. public static int2 select(int2 a, int2 b, bool c) { return c ? b : a; }
  1466. /// <summary>Returns b if c is true, a otherwise.</summary>
  1467. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1468. public static int3 select(int3 a, int3 b, bool c) { return c ? b : a; }
  1469. /// <summary>Returns b if c is true, a otherwise.</summary>
  1470. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1471. public static int4 select(int4 a, int4 b, bool c) { return c ? b : a; }
  1472. /// <summary>
  1473. /// Returns a componentwise selection between two int2 vectors a and b based on a bool2 selection mask c.
  1474. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1475. /// </summary>
  1476. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1477. public static int2 select(int2 a, int2 b, bool2 c) { return new int2(c.x ? b.x : a.x, c.y ? b.y : a.y); }
  1478. /// <summary>
  1479. /// Returns a componentwise selection between two int3 vectors a and b based on a bool3 selection mask c.
  1480. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1481. /// </summary>
  1482. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1483. public static int3 select(int3 a, int3 b, bool3 c) { return new int3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); }
  1484. /// <summary>
  1485. /// Returns a componentwise selection between two int4 vectors a and b based on a bool4 selection mask c.
  1486. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1487. /// </summary>
  1488. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1489. public static int4 select(int4 a, int4 b, bool4 c) { return new int4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); }
  1490. /// <summary>Returns b if c is true, a otherwise.</summary>
  1491. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1492. public static uint select(uint a, uint b, bool c) { return c ? b : a; }
  1493. /// <summary>Returns b if c is true, a otherwise.</summary>
  1494. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1495. public static uint2 select(uint2 a, uint2 b, bool c) { return c ? b : a; }
  1496. /// <summary>Returns b if c is true, a otherwise.</summary>
  1497. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1498. public static uint3 select(uint3 a, uint3 b, bool c) { return c ? b : a; }
  1499. /// <summary>Returns b if c is true, a otherwise.</summary>
  1500. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1501. public static uint4 select(uint4 a, uint4 b, bool c) { return c ? b : a; }
  1502. /// <summary>
  1503. /// Returns a componentwise selection between two uint2 vectors a and b based on a bool2 selection mask c.
  1504. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1505. /// </summary>
  1506. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1507. public static uint2 select(uint2 a, uint2 b, bool2 c) { return new uint2(c.x ? b.x : a.x, c.y ? b.y : a.y); }
  1508. /// <summary>
  1509. /// Returns a componentwise selection between two uint3 vectors a and b based on a bool3 selection mask c.
  1510. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1511. /// </summary>
  1512. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1513. public static uint3 select(uint3 a, uint3 b, bool3 c) { return new uint3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); }
  1514. /// <summary>
  1515. /// Returns a componentwise selection between two uint4 vectors a and b based on a bool4 selection mask c.
  1516. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1517. /// </summary>
  1518. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1519. public static uint4 select(uint4 a, uint4 b, bool4 c) { return new uint4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); }
  1520. /// <summary>Returns b if c is true, a otherwise.</summary>
  1521. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1522. public static long select(long a, long b, bool c) { return c ? b : a; }
  1523. /// <summary>Returns b if c is true, a otherwise.</summary>
  1524. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1525. public static ulong select(ulong a, ulong b, bool c) { return c ? b : a; }
  1526. /// <summary>Returns b if c is true, a otherwise.</summary>
  1527. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1528. public static float select(float a, float b, bool c) { return c ? b : a; }
  1529. /// <summary>Returns b if c is true, a otherwise.</summary>
  1530. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1531. public static float2 select(float2 a, float2 b, bool c) { return c ? b : a; }
  1532. /// <summary>Returns b if c is true, a otherwise.</summary>
  1533. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1534. public static float3 select(float3 a, float3 b, bool c) { return c ? b : a; }
  1535. /// <summary>Returns b if c is true, a otherwise.</summary>
  1536. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1537. public static float4 select(float4 a, float4 b, bool c) { return c ? b : a; }
  1538. /// <summary>
  1539. /// Returns a componentwise selection between two float2 vectors a and b based on a bool2 selection mask c.
  1540. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1541. /// </summary>
  1542. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1543. public static float2 select(float2 a, float2 b, bool2 c) { return new float2(c.x ? b.x : a.x, c.y ? b.y : a.y); }
  1544. /// <summary>
  1545. /// Returns a componentwise selection between two float3 vectors a and b based on a bool3 selection mask c.
  1546. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1547. /// </summary>
  1548. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1549. public static float3 select(float3 a, float3 b, bool3 c) { return new float3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); }
  1550. /// <summary>
  1551. /// Returns a componentwise selection between two float4 vectors a and b based on a bool4 selection mask c.
  1552. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1553. /// </summary>
  1554. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1555. public static float4 select(float4 a, float4 b, bool4 c) { return new float4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); }
  1556. /// <summary>Returns b if c is true, a otherwise.</summary>
  1557. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1558. public static double select(double a, double b, bool c) { return c ? b : a; }
  1559. /// <summary>Returns b if c is true, a otherwise.</summary>
  1560. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1561. public static double2 select(double2 a, double2 b, bool c) { return c ? b : a; }
  1562. /// <summary>Returns b if c is true, a otherwise.</summary>
  1563. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1564. public static double3 select(double3 a, double3 b, bool c) { return c ? b : a; }
  1565. /// <summary>Returns b if c is true, a otherwise.</summary>
  1566. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1567. public static double4 select(double4 a, double4 b, bool c) { return c ? b : a; }
  1568. /// <summary>
  1569. /// Returns a componentwise selection between two double2 vectors a and b based on a bool2 selection mask c.
  1570. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1571. /// </summary>
  1572. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1573. public static double2 select(double2 a, double2 b, bool2 c) { return new double2(c.x ? b.x : a.x, c.y ? b.y : a.y); }
  1574. /// <summary>
  1575. /// Returns a componentwise selection between two double3 vectors a and b based on a bool3 selection mask c.
  1576. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1577. /// </summary>
  1578. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1579. public static double3 select(double3 a, double3 b, bool3 c) { return new double3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); }
  1580. /// <summary>
  1581. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  1582. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  1583. /// </summary>
  1584. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1585. public static double4 select(double4 a, double4 b, bool4 c) { return new double4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); }
  1586. /// <summary>Computes a step function. Returns 1.0f when x >= y, 0.0f otherwise.</summary>
  1587. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1588. public static float step(float y, float x) { return select(0.0f, 1.0f, x >= y); }
  1589. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1590. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1591. public static float2 step(float2 y, float2 x) { return select(float2(0.0f), float2(1.0f), x >= y); }
  1592. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1593. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1594. public static float3 step(float3 y, float3 x) { return select(float3(0.0f), float3(1.0f), x >= y); }
  1595. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1596. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1597. public static float4 step(float4 y, float4 x) { return select(float4(0.0f), float4(1.0f), x >= y); }
  1598. /// <summary>Computes a step function. Returns 1.0 when x >= y, 0.0 otherwise.</summary>
  1599. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1600. public static double step(double y, double x) { return select(0.0, 1.0, x >= y); }
  1601. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1602. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1603. public static double2 step(double2 y, double2 x) { return select(double2(0.0), double2(1.0), x >= y); }
  1604. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1605. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1606. public static double3 step(double3 y, double3 x) { return select(double3(0.0), double3(1.0), x >= y); }
  1607. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise.</summary>
  1608. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1609. public static double4 step(double4 y, double4 x) { return select(double4(0.0), double4(1.0), x >= y); }
  1610. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  1611. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1612. public static float2 reflect(float2 i, float2 n) { return i - 2f * n * dot(i, n); }
  1613. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  1614. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1615. public static float3 reflect(float3 i, float3 n) { return i - 2f * n * dot(i, n); }
  1616. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  1617. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1618. public static float4 reflect(float4 i, float4 n) { return i - 2f * n * dot(i, n); }
  1619. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  1620. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1621. public static double2 reflect(double2 i, double2 n) { return i - 2 * n * dot(i, n); }
  1622. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  1623. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1624. public static double3 reflect(double3 i, double3 n) { return i - 2 * n * dot(i, n); }
  1625. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  1626. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1627. public static double4 reflect(double4 i, double4 n) { return i - 2 * n * dot(i, n); }
  1628. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1629. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1630. public static float2 refract(float2 i, float2 n, float eta)
  1631. {
  1632. float ni = dot(n, i);
  1633. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  1634. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1635. }
  1636. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1637. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1638. public static float3 refract(float3 i, float3 n, float eta)
  1639. {
  1640. float ni = dot(n, i);
  1641. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  1642. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1643. }
  1644. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1645. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1646. public static float4 refract(float4 i, float4 n, float eta)
  1647. {
  1648. float ni = dot(n, i);
  1649. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  1650. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1651. }
  1652. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1653. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1654. public static double2 refract(double2 i, double2 n, double eta)
  1655. {
  1656. double ni = dot(n, i);
  1657. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  1658. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1659. }
  1660. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1661. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1662. public static double3 refract(double3 i, double3 n, double eta)
  1663. {
  1664. double ni = dot(n, i);
  1665. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  1666. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1667. }
  1668. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  1669. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1670. public static double4 refract(double4 i, double4 n, double eta)
  1671. {
  1672. double ni = dot(n, i);
  1673. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  1674. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  1675. }
  1676. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1677. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1678. public static float2 faceforward(float2 n, float2 i, float2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1679. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1680. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1681. public static float3 faceforward(float3 n, float3 i, float3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1682. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1683. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1684. public static float4 faceforward(float4 n, float4 i, float4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1685. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1686. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1687. public static double2 faceforward(double2 n, double2 i, double2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1688. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1689. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1690. public static double3 faceforward(double3 n, double3 i, double3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1691. /// <summary>Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise.</summary>
  1692. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1693. public static double4 faceforward(double4 n, double4 i, double4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  1694. /// <summary>Returns the sine and cosine of the input float value x through the out parameters s and c.</summary>
  1695. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1696. public static void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); }
  1697. /// <summary>Returns the componentwise sine and cosine of the input float2 vector x through the out parameters s and c.</summary>
  1698. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1699. public static void sincos(float2 x, out float2 s, out float2 c) { s = sin(x); c = cos(x); }
  1700. /// <summary>Returns the componentwise sine and cosine of the input float3 vector x through the out parameters s and c.</summary>
  1701. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1702. public static void sincos(float3 x, out float3 s, out float3 c) { s = sin(x); c = cos(x); }
  1703. /// <summary>Returns the componentwise sine and cosine of the input float4 vector x through the out parameters s and c.</summary>
  1704. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1705. public static void sincos(float4 x, out float4 s, out float4 c) { s = sin(x); c = cos(x); }
  1706. /// <summary>Returns the sine and cosine of the input double value x through the out parameters s and c.</summary>
  1707. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1708. public static void sincos(double x, out double s, out double c) { s = sin(x); c = cos(x); }
  1709. /// <summary>Returns the componentwise sine and cosine of the input double2 vector x through the out parameters s and c.</summary>
  1710. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1711. public static void sincos(double2 x, out double2 s, out double2 c) { s = sin(x); c = cos(x); }
  1712. /// <summary>Returns the componentwise sine and cosine of the input double3 vector x through the out parameters s and c.</summary>
  1713. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1714. public static void sincos(double3 x, out double3 s, out double3 c) { s = sin(x); c = cos(x); }
  1715. /// <summary>Returns the componentwise sine and cosine of the input double4 vector x through the out parameters s and c.</summary>
  1716. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1717. public static void sincos(double4 x, out double4 s, out double4 c) { s = sin(x); c = cos(x); }
  1718. /// <summary>Returns number of 1-bits in the binary representations of an int value.</summary>
  1719. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1720. public static int countbits(int x) { return countbits((uint)x); }
  1721. /// <summary>Returns componentwise number of 1-bits in the binary representations of an int2 vector.</summary>
  1722. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1723. public static int2 countbits(int2 x) { return countbits((uint2)x); }
  1724. /// <summary>Returns componentwise number of 1-bits in the binary representations of an int3 vector.</summary>
  1725. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1726. public static int3 countbits(int3 x) { return countbits((uint3)x); }
  1727. /// <summary>Returns componentwise number of 1-bits in the binary representations of an int4 vector.</summary>
  1728. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1729. public static int4 countbits(int4 x) { return countbits((uint4)x); }
  1730. /// <summary>Returns number of 1-bits in the binary representations of a uint value.</summary>
  1731. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1732. public static int countbits(uint x)
  1733. {
  1734. x = x - ((x >> 1) & 0x55555555);
  1735. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1736. return (int)((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  1737. }
  1738. /// <summary>Returns componentwise number of 1-bits in the binary representations of a uint2 vector.</summary>
  1739. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1740. public static int2 countbits(uint2 x)
  1741. {
  1742. x = x - ((x >> 1) & 0x55555555);
  1743. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1744. return int2((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  1745. }
  1746. /// <summary>Returns componentwise number of 1-bits in the binary representations of a uint3 vector.</summary>
  1747. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1748. public static int3 countbits(uint3 x)
  1749. {
  1750. x = x - ((x >> 1) & 0x55555555);
  1751. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1752. return int3((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  1753. }
  1754. /// <summary>Returns componentwise number of 1-bits in the binary representations of a uint4 vector.</summary>
  1755. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1756. public static int4 countbits(uint4 x)
  1757. {
  1758. x = x - ((x >> 1) & 0x55555555);
  1759. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1760. return int4((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  1761. }
  1762. /// <summary>Returns number of 1-bits in the binary representations of a ulong value.</summary>
  1763. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1764. public static int countbits(ulong x)
  1765. {
  1766. x = x - ((x >> 1) & 0x5555555555555555);
  1767. x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
  1768. return (int)((((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56);
  1769. }
  1770. /// <summary>Returns number of 1-bits in the binary representations of a long value.</summary>
  1771. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1772. public static int countbits(long x) { return countbits((ulong)x); }
  1773. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int vector.</summary>
  1774. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1775. public static int lzcnt(int x) { return lzcnt((uint)x); }
  1776. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int2 vector.</summary>
  1777. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1778. public static int2 lzcnt(int2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  1779. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int3 vector.</summary>
  1780. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1781. public static int3 lzcnt(int3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  1782. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int4 vector.</summary>
  1783. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1784. public static int4 lzcnt(int4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  1785. /// <summary>Returns number of leading zeros in the binary representations of a uint value.</summary>
  1786. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1787. public static int lzcnt(uint x)
  1788. {
  1789. if (x == 0)
  1790. return 32;
  1791. LongDoubleUnion u;
  1792. u.doubleValue = 0.0;
  1793. u.longValue = 0x4330000000000000L + x;
  1794. u.doubleValue -= 4503599627370496.0;
  1795. return 0x41E - (int)(u.longValue >> 52);
  1796. }
  1797. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint2 vector.</summary>
  1798. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1799. public static int2 lzcnt(uint2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  1800. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint3 vector.</summary>
  1801. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1802. public static int3 lzcnt(uint3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  1803. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint4 vector.</summary>
  1804. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1805. public static int4 lzcnt(uint4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  1806. /// <summary>Returns number of leading zeros in the binary representations of a long value.</summary>
  1807. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1808. public static int lzcnt(long x) { return lzcnt((ulong)x); }
  1809. /// <summary>Returns number of leading zeros in the binary representations of a ulong value.</summary>
  1810. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1811. public static int lzcnt(ulong x)
  1812. {
  1813. if (x == 0)
  1814. return 64;
  1815. uint xh = (uint)(x >> 32);
  1816. uint bits = xh != 0 ? xh : (uint)x;
  1817. int offset = xh != 0 ? 0x41E : 0x43E;
  1818. LongDoubleUnion u;
  1819. u.doubleValue = 0.0;
  1820. u.longValue = 0x4330000000000000L + bits;
  1821. u.doubleValue -= 4503599627370496.0;
  1822. return offset - (int)(u.longValue >> 52);
  1823. }
  1824. /// <summary>Returns number of trailing zeros in the binary representations of an int value.</summary>
  1825. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1826. public static int tzcnt(int x) { return tzcnt((uint)x); }
  1827. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int2 vector.</summary>
  1828. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1829. public static int2 tzcnt(int2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  1830. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int3 vector.</summary>
  1831. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1832. public static int3 tzcnt(int3 v) { return int3(tzcnt(v.x), tzcnt(v.y), tzcnt(v.z)); }
  1833. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int4 vector.</summary>
  1834. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1835. public static int4 tzcnt(int4 v) { return int4(tzcnt(v.x), tzcnt(v.y), tzcnt(v.z), tzcnt(v.w)); }
  1836. /// <summary>Returns number of trailing zeros in the binary representations of a uint value.</summary>
  1837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1838. public static int tzcnt(uint x)
  1839. {
  1840. if (x == 0)
  1841. return 32;
  1842. x &= (uint)-x;
  1843. LongDoubleUnion u;
  1844. u.doubleValue = 0.0;
  1845. u.longValue = 0x4330000000000000L + x;
  1846. u.doubleValue -= 4503599627370496.0;
  1847. return (int)(u.longValue >> 52) - 0x3FF;
  1848. }
  1849. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an uint2 vector.</summary>
  1850. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1851. public static int2 tzcnt(uint2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  1852. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an uint3 vector.</summary>
  1853. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1854. public static int3 tzcnt(uint3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); }
  1855. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an uint4 vector.</summary>
  1856. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1857. public static int4 tzcnt(uint4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); }
  1858. /// <summary>Returns number of trailing zeros in the binary representations of a long value.</summary>
  1859. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1860. public static int tzcnt(long x) { return tzcnt((ulong)x); }
  1861. /// <summary>Returns number of trailing zeros in the binary representations of a ulong value.</summary>
  1862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1863. public static int tzcnt(ulong x)
  1864. {
  1865. if (x == 0)
  1866. return 64;
  1867. x = x & (ulong)-(long)x;
  1868. uint xl = (uint)x;
  1869. uint bits = xl != 0 ? xl : (uint)(x >> 32);
  1870. int offset = xl != 0 ? 0x3FF : 0x3DF;
  1871. LongDoubleUnion u;
  1872. u.doubleValue = 0.0;
  1873. u.longValue = 0x4330000000000000L + bits;
  1874. u.doubleValue -= 4503599627370496.0;
  1875. return (int)(u.longValue >> 52) - offset;
  1876. }
  1877. /// <summary>Returns the result of performing a reversal of the bit pattern of an int value.</summary>
  1878. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1879. public static int reversebits(int x) { return (int)reversebits((uint)x); }
  1880. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int2 vector.</summary>
  1881. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1882. public static int2 reversebits(int2 x) { return (int2)reversebits((uint2)x); }
  1883. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int3 vector.</summary>
  1884. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1885. public static int3 reversebits(int3 x) { return (int3)reversebits((uint3)x); }
  1886. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int4 vector.</summary>
  1887. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1888. public static int4 reversebits(int4 x) { return (int4)reversebits((uint4)x); }
  1889. /// <summary>Returns the result of performing a reversal of the bit pattern of a uint value.</summary>
  1890. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1891. public static uint reversebits(uint x) {
  1892. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  1893. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  1894. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  1895. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  1896. return (x >> 16) | (x << 16);
  1897. }
  1898. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint2 vector.</summary>
  1899. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1900. public static uint2 reversebits(uint2 x)
  1901. {
  1902. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  1903. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  1904. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  1905. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  1906. return (x >> 16) | (x << 16);
  1907. }
  1908. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint3 vector.</summary>
  1909. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1910. public static uint3 reversebits(uint3 x)
  1911. {
  1912. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  1913. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  1914. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  1915. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  1916. return (x >> 16) | (x << 16);
  1917. }
  1918. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint4 vector.</summary>
  1919. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1920. public static uint4 reversebits(uint4 x)
  1921. {
  1922. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  1923. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  1924. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  1925. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  1926. return (x >> 16) | (x << 16);
  1927. }
  1928. /// <summary>Returns the result of performing a reversal of the bit pattern of a long value.</summary>
  1929. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1930. public static long reversebits(long x) { return (long)reversebits((ulong)x); }
  1931. /// <summary>Returns the result of performing a reversal of the bit pattern of a ulong value.</summary>
  1932. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1933. public static ulong reversebits(ulong x)
  1934. {
  1935. x = ((x >> 1) & 0x5555555555555555ul) | ((x & 0x5555555555555555ul) << 1);
  1936. x = ((x >> 2) & 0x3333333333333333ul) | ((x & 0x3333333333333333ul) << 2);
  1937. x = ((x >> 4) & 0x0F0F0F0F0F0F0F0Ful) | ((x & 0x0F0F0F0F0F0F0F0Ful) << 4);
  1938. x = ((x >> 8) & 0x00FF00FF00FF00FFul) | ((x & 0x00FF00FF00FF00FFul) << 8);
  1939. x = ((x >> 16) & 0x0000FFFF0000FFFFul) | ((x & 0x0000FFFF0000FFFFul) << 16);
  1940. return (x >> 32) | (x << 32);
  1941. }
  1942. /// <summary>Returns the result of rotating the bits of an int left by bits n.</summary>
  1943. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1944. public static int rol(int x, int n) { return (int)rol((uint)x, n); }
  1945. /// <summary>Returns the componentwise result of rotating the bits of an int2 left by bits n.</summary>
  1946. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1947. public static int2 rol(int2 x, int n) { return (int2)rol((uint2)x, n); }
  1948. /// <summary>Returns the componentwise result of rotating the bits of an int3 left by bits n.</summary>
  1949. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1950. public static int3 rol(int3 x, int n) { return (int3)rol((uint3)x, n); }
  1951. /// <summary>Returns the componentwise result of rotating the bits of an int4 left by bits n.</summary>
  1952. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1953. public static int4 rol(int4 x, int n) { return (int4)rol((uint4)x, n); }
  1954. /// <summary>Returns the result of rotating the bits of a uint left by bits n.</summary>
  1955. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1956. public static uint rol(uint x, int n) { return (x << n) | (x >> (32 - n)); }
  1957. /// <summary>Returns the componentwise result of rotating the bits of a uint2 left by bits n.</summary>
  1958. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1959. public static uint2 rol(uint2 x, int n) { return (x << n) | (x >> (32 - n)); }
  1960. /// <summary>Returns the componentwise result of rotating the bits of a uint3 left by bits n.</summary>
  1961. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1962. public static uint3 rol(uint3 x, int n) { return (x << n) | (x >> (32 - n)); }
  1963. /// <summary>Returns the componentwise result of rotating the bits of a uint4 left by bits n.</summary>
  1964. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1965. public static uint4 rol(uint4 x, int n) { return (x << n) | (x >> (32 - n)); }
  1966. /// <summary>Returns the result of rotating the bits of a long left by bits n.</summary>
  1967. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1968. public static long rol(long x, int n) { return (long)rol((ulong)x, n); }
  1969. /// <summary>Returns the result of rotating the bits of a ulong left by bits n.</summary>
  1970. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1971. public static ulong rol(ulong x, int n) { return (x << n) | (x >> (64 - n)); }
  1972. /// <summary>Returns the result of rotating the bits of an int right by bits n.</summary>
  1973. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1974. public static int ror(int x, int n) { return (int)ror((uint)x, n); }
  1975. /// <summary>Returns the componentwise result of rotating the bits of an int2 right by bits n.</summary>
  1976. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1977. public static int2 ror(int2 x, int n) { return (int2)ror((uint2)x, n); }
  1978. /// <summary>Returns the componentwise result of rotating the bits of an int3 right by bits n.</summary>
  1979. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1980. public static int3 ror(int3 x, int n) { return (int3)ror((uint3)x, n); }
  1981. /// <summary>Returns the componentwise result of rotating the bits of an int4 right by bits n.</summary>
  1982. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1983. public static int4 ror(int4 x, int n) { return (int4)ror((uint4)x, n); }
  1984. /// <summary>Returns the result of rotating the bits of a uint right by bits n.</summary>
  1985. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1986. public static uint ror(uint x, int n) { return (x >> n) | (x << (32 - n)); }
  1987. /// <summary>Returns the componentwise result of rotating the bits of a uint2 right by bits n.</summary>
  1988. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1989. public static uint2 ror(uint2 x, int n) { return (x >> n) | (x << (32 - n)); }
  1990. /// <summary>Returns the componentwise result of rotating the bits of a uint3 right by bits n.</summary>
  1991. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1992. public static uint3 ror(uint3 x, int n) { return (x >> n) | (x << (32 - n)); }
  1993. /// <summary>Returns the componentwise result of rotating the bits of a uint4 right by bits n.</summary>
  1994. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1995. public static uint4 ror(uint4 x, int n) { return (x >> n) | (x << (32 - n)); }
  1996. /// <summary>Returns the result of rotating the bits of a long right by bits n.</summary>
  1997. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1998. public static long ror(long x, int n) { return (long)ror((ulong)x, n); }
  1999. /// <summary>Returns the result of rotating the bits of a ulong right by bits n.</summary>
  2000. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2001. public static ulong ror(ulong x, int n) { return (x >> n) | (x << (64 - n)); }
  2002. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  2003. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2004. public static int ceilpow2(int x)
  2005. {
  2006. x -= 1;
  2007. x |= x >> 1;
  2008. x |= x >> 2;
  2009. x |= x >> 4;
  2010. x |= x >> 8;
  2011. x |= x >> 16;
  2012. return x + 1;
  2013. }
  2014. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2015. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2016. public static int2 ceilpow2(int2 x)
  2017. {
  2018. x -= 1;
  2019. x |= x >> 1;
  2020. x |= x >> 2;
  2021. x |= x >> 4;
  2022. x |= x >> 8;
  2023. x |= x >> 16;
  2024. return x + 1;
  2025. }
  2026. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2027. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2028. public static int3 ceilpow2(int3 x)
  2029. {
  2030. x -= 1;
  2031. x |= x >> 1;
  2032. x |= x >> 2;
  2033. x |= x >> 4;
  2034. x |= x >> 8;
  2035. x |= x >> 16;
  2036. return x + 1;
  2037. }
  2038. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2039. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2040. public static int4 ceilpow2(int4 x)
  2041. {
  2042. x -= 1;
  2043. x |= x >> 1;
  2044. x |= x >> 2;
  2045. x |= x >> 4;
  2046. x |= x >> 8;
  2047. x |= x >> 16;
  2048. return x + 1;
  2049. }
  2050. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  2051. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2052. public static uint ceilpow2(uint x)
  2053. {
  2054. x -= 1;
  2055. x |= x >> 1;
  2056. x |= x >> 2;
  2057. x |= x >> 4;
  2058. x |= x >> 8;
  2059. x |= x >> 16;
  2060. return x + 1;
  2061. }
  2062. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2063. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2064. public static uint2 ceilpow2(uint2 x)
  2065. {
  2066. x -= 1;
  2067. x |= x >> 1;
  2068. x |= x >> 2;
  2069. x |= x >> 4;
  2070. x |= x >> 8;
  2071. x |= x >> 16;
  2072. return x + 1;
  2073. }
  2074. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2075. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2076. public static uint3 ceilpow2(uint3 x)
  2077. {
  2078. x -= 1;
  2079. x |= x >> 1;
  2080. x |= x >> 2;
  2081. x |= x >> 4;
  2082. x |= x >> 8;
  2083. x |= x >> 16;
  2084. return x + 1;
  2085. }
  2086. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  2087. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2088. public static uint4 ceilpow2(uint4 x)
  2089. {
  2090. x -= 1;
  2091. x |= x >> 1;
  2092. x |= x >> 2;
  2093. x |= x >> 4;
  2094. x |= x >> 8;
  2095. x |= x >> 16;
  2096. return x + 1;
  2097. }
  2098. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  2099. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2100. public static long ceilpow2(long x)
  2101. {
  2102. x -= 1;
  2103. x |= x >> 1;
  2104. x |= x >> 2;
  2105. x |= x >> 4;
  2106. x |= x >> 8;
  2107. x |= x >> 16;
  2108. x |= x >> 32;
  2109. return x + 1;
  2110. }
  2111. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  2112. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2113. public static ulong ceilpow2(ulong x)
  2114. {
  2115. x -= 1;
  2116. x |= x >> 1;
  2117. x |= x >> 2;
  2118. x |= x >> 4;
  2119. x |= x >> 8;
  2120. x |= x >> 16;
  2121. x |= x >> 32;
  2122. return x + 1;
  2123. }
  2124. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  2125. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2126. public static float radians(float x) { return x * 0.0174532925f; }
  2127. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  2128. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2129. public static float2 radians(float2 x) { return x * 0.0174532925f; }
  2130. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  2131. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2132. public static float3 radians(float3 x) { return x * 0.0174532925f; }
  2133. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  2134. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2135. public static float4 radians(float4 x) { return x * 0.0174532925f; }
  2136. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  2137. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2138. public static double radians(double x) { return x * 0.017453292519943296; }
  2139. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  2140. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2141. public static double2 radians(double2 x) { return x * 0.017453292519943296; }
  2142. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  2143. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2144. public static double3 radians(double3 x) { return x * 0.017453292519943296; }
  2145. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  2146. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2147. public static double4 radians(double4 x) { return x * 0.017453292519943296; }
  2148. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  2149. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2150. public static float degrees(float x) { return x * 57.295779513f; }
  2151. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  2152. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2153. public static float2 degrees(float2 x) { return x * 57.295779513f; }
  2154. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  2155. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2156. public static float3 degrees(float3 x) { return x * 57.295779513f; }
  2157. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  2158. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2159. public static float4 degrees(float4 x) { return x * 57.295779513f; }
  2160. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  2161. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2162. public static double degrees(double x) { return x * 57.29577951308232; }
  2163. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  2164. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2165. public static double2 degrees(double2 x) { return x * 57.29577951308232; }
  2166. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  2167. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2168. public static double3 degrees(double3 x) { return x * 57.29577951308232; }
  2169. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  2170. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2171. public static double4 degrees(double4 x) { return x * 57.29577951308232; }
  2172. /// <summary>Returns the minimum component of an int2 vector.</summary>
  2173. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2174. public static int cmin(int2 x) { return min(x.x, x.y); }
  2175. /// <summary>Returns the minimum component of an int3 vector.</summary>
  2176. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2177. public static int cmin(int3 x) { return min(min(x.x, x.y), x.z); }
  2178. /// <summary>Returns the minimum component of an int4 vector.</summary>
  2179. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2180. public static int cmin(int4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  2181. /// <summary>Returns the minimum component of a uint2 vector.</summary>
  2182. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2183. public static uint cmin(uint2 x) { return min(x.x, x.y); }
  2184. /// <summary>Returns the minimum component of a uint3 vector.</summary>
  2185. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2186. public static uint cmin(uint3 x) { return min(min(x.x, x.y), x.z); }
  2187. /// <summary>Returns the minimum component of a uint4 vector.</summary>
  2188. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2189. public static uint cmin(uint4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  2190. /// <summary>Returns the minimum component of a float2 vector.</summary>
  2191. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2192. public static float cmin(float2 x) { return min(x.x, x.y); }
  2193. /// <summary>Returns the minimum component of a float3 vector.</summary>
  2194. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2195. public static float cmin(float3 x) { return min(min(x.x, x.y), x.z); }
  2196. /// <summary>Returns the maximum component of a float3 vector.</summary>
  2197. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2198. public static float cmin(float4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  2199. /// <summary>Returns the minimum component of a float2 vector.</summary>
  2200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2201. public static double cmin(double2 x) { return min(x.x, x.y); }
  2202. /// <summary>Returns the minimum component of a float3 vector.</summary>
  2203. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2204. public static double cmin(double3 x) { return min(min(x.x, x.y), x.z); }
  2205. /// <summary>Returns the maximum component of a float3 vector.</summary>
  2206. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2207. public static double cmin(double4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  2208. /// <summary>Returns the maximum component of an int2 vector.</summary>
  2209. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2210. public static int cmax(int2 x) { return max(x.x, x.y); }
  2211. /// <summary>Returns the maximum component of an int3 vector.</summary>
  2212. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2213. public static int cmax(int3 x) { return max(max(x.x, x.y), x.z); }
  2214. /// <summary>Returns the maximum component of an int4 vector.</summary>
  2215. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2216. public static int cmax(int4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  2217. /// <summary>Returns the maximum component of a uint2 vector.</summary>
  2218. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2219. public static uint cmax(uint2 x) { return max(x.x, x.y); }
  2220. /// <summary>Returns the maximum component of a uint3 vector.</summary>
  2221. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2222. public static uint cmax(uint3 x) { return max(max(x.x, x.y), x.z); }
  2223. /// <summary>Returns the maximum component of a uint4 vector.</summary>
  2224. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2225. public static uint cmax(uint4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  2226. /// <summary>Returns the maximum component of a float2 vector.</summary>
  2227. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2228. public static float cmax(float2 x) { return max(x.x, x.y); }
  2229. /// <summary>Returns the maximum component of a float3 vector.</summary>
  2230. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2231. public static float cmax(float3 x) { return max(max(x.x, x.y), x.z); }
  2232. /// <summary>Returns the maximum component of a float4 vector.</summary>
  2233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2234. public static float cmax(float4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  2235. /// <summary>Returns the maximum component of a double2 vector.</summary>
  2236. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2237. public static double cmax(double2 x) { return max(x.x, x.y); }
  2238. /// <summary>Returns the maximum component of a double3 vector.</summary>
  2239. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2240. public static double cmax(double3 x) { return max(max(x.x, x.y), x.z); }
  2241. /// <summary>Returns the maximum component of a double4 vector.</summary>
  2242. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2243. public static double cmax(double4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  2244. /// <summary>Returns the horizontal sum of components of an int2 vector.</summary>
  2245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2246. public static int csum(int2 x) { return x.x + x.y; }
  2247. /// <summary>Returns the horizontal sum of components of an int3 vector.</summary>
  2248. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2249. public static int csum(int3 x) { return x.x + x.y + x.z; }
  2250. /// <summary>Returns the horizontal sum of components of an int4 vector.</summary>
  2251. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2252. public static int csum(int4 x) { return x.x + x.y + x.z + x.w; }
  2253. /// <summary>Returns the horizontal sum of components of a uint2 vector.</summary>
  2254. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2255. public static uint csum(uint2 x) { return x.x + x.y; }
  2256. /// <summary>Returns the horizontal sum of components of a uint3 vector.</summary>
  2257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2258. public static uint csum(uint3 x) { return x.x + x.y + x.z; }
  2259. /// <summary>Returns the horizontal sum of components of a uint4 vector.</summary>
  2260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2261. public static uint csum(uint4 x) { return x.x + x.y + x.z + x.w; }
  2262. /// <summary>Returns the horizontal sum of components of a float2 vector.</summary>
  2263. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2264. public static float csum(float2 x) { return x.x + x.y; }
  2265. /// <summary>Returns the horizontal sum of components of a float3 vector.</summary>
  2266. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2267. public static float csum(float3 x) { return x.x + x.y + x.z; }
  2268. /// <summary>Returns the horizontal sum of components of a float4 vector.</summary>
  2269. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2270. public static float csum(float4 x) { return (x.x + x.y) + (x.z + x.w); }
  2271. /// <summary>Returns the horizontal sum of components of a double2 vector.</summary>
  2272. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2273. public static double csum(double2 x) { return x.x + x.y; }
  2274. /// <summary>Returns the horizontal sum of components of a double3 vector.</summary>
  2275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2276. public static double csum(double3 x) { return x.x + x.y + x.z; }
  2277. /// <summary>Returns the horizontal sum of components of a double4 vector.</summary>
  2278. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2279. public static double csum(double4 x) { return (x.x + x.y) + (x.z + x.w); }
  2280. /// <summary>
  2281. /// Packs components with an enabled mask (LSB) to the left
  2282. /// The value of components after the last packed component are undefined.
  2283. /// Returns the number of enabled mask bits. (0 ... 4)
  2284. /// </summary>
  2285. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2286. public static unsafe int compress(int* output, int index, int4 val, bool4 mask)
  2287. {
  2288. if (mask.x)
  2289. output[index++] = val.x;
  2290. if (mask.y)
  2291. output[index++] = val.y;
  2292. if (mask.z)
  2293. output[index++] = val.z;
  2294. if (mask.w)
  2295. output[index++] = val.w;
  2296. return index;
  2297. }
  2298. /// <summary>Returns the floating point representation of a half-precision floating point value.</summary>
  2299. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2300. public static float f16tof32(uint x)
  2301. {
  2302. const uint shifted_exp = (0x7c00 << 13);
  2303. uint uf = (x & 0x7fff) << 13;
  2304. uint e = uf & shifted_exp;
  2305. uf += (127 - 15) << 23;
  2306. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  2307. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  2308. uf |= (x & 0x8000) << 16;
  2309. return asfloat(uf);
  2310. }
  2311. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  2312. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2313. public static float2 f16tof32(uint2 x)
  2314. {
  2315. const uint shifted_exp = (0x7c00 << 13);
  2316. uint2 uf = (x & 0x7fff) << 13;
  2317. uint2 e = uf & shifted_exp;
  2318. uf += (127 - 15) << 23;
  2319. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  2320. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  2321. uf |= (x & 0x8000) << 16;
  2322. return asfloat(uf);
  2323. }
  2324. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  2325. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2326. public static float3 f16tof32(uint3 x)
  2327. {
  2328. const uint shifted_exp = (0x7c00 << 13);
  2329. uint3 uf = (x & 0x7fff) << 13;
  2330. uint3 e = uf & shifted_exp;
  2331. uf += (127 - 15) << 23;
  2332. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  2333. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  2334. uf |= (x & 0x8000) << 16;
  2335. return asfloat(uf);
  2336. }
  2337. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  2338. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2339. public static float4 f16tof32(uint4 x)
  2340. {
  2341. const uint shifted_exp = (0x7c00 << 13);
  2342. uint4 uf = (x & 0x7fff) << 13;
  2343. uint4 e = uf & shifted_exp;
  2344. uf += (127 - 15) << 23;
  2345. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  2346. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  2347. uf |= (x & 0x8000) << 16;
  2348. return asfloat(uf);
  2349. }
  2350. /// <summary>Returns the result converting a float value to its nearest half-precision floating point representation.</summary>
  2351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2352. public static uint f32tof16(float x)
  2353. {
  2354. const int infinity_32 = 255 << 23;
  2355. const uint msk = 0x7FFFF000u;
  2356. uint ux = asuint(x);
  2357. uint uux = ux & msk;
  2358. uint h = (uint)(asuint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  2359. h = select(h, select(0x7c00u, 0x7e00u, (int)uux > infinity_32), (int)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  2360. return h | (ux & ~msk) >> 16;
  2361. }
  2362. /// <summary>Returns the result of a componentwise conversion of a float2 vector to its nearest half-precision floating point representation.</summary>
  2363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2364. public static uint2 f32tof16(float2 x)
  2365. {
  2366. const int infinity_32 = 255 << 23;
  2367. const uint msk = 0x7FFFF000u;
  2368. uint2 ux = asuint(x);
  2369. uint2 uux = ux & msk;
  2370. uint2 h = (uint2)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  2371. h = select(h, select(0x7c00u, 0x7e00u, (int2)uux > infinity_32), (int2)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  2372. return h | (ux & ~msk) >> 16;
  2373. }
  2374. /// <summary>Returns the result of a componentwise conversion of a float3 vector to its nearest half-precision floating point representation.</summary>
  2375. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2376. public static uint3 f32tof16(float3 x)
  2377. {
  2378. const int infinity_32 = 255 << 23;
  2379. const uint msk = 0x7FFFF000u;
  2380. uint3 ux = asuint(x);
  2381. uint3 uux = ux & msk;
  2382. uint3 h = (uint3)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  2383. h = select(h, select(0x7c00u, 0x7e00u, (int3)uux > infinity_32), (int3)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  2384. return h | (ux & ~msk) >> 16;
  2385. }
  2386. /// <summary>Returns the result of a componentwise conversion of a float4 vector to its nearest half-precision floating point representation.</summary>
  2387. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2388. public static uint4 f32tof16(float4 x)
  2389. {
  2390. const int infinity_32 = 255 << 23;
  2391. const uint msk = 0x7FFFF000u;
  2392. uint4 ux = asuint(x);
  2393. uint4 uux = ux & msk;
  2394. uint4 h = (uint4)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  2395. h = select(h, select(0x7c00u, 0x7e00u, (int4)uux > infinity_32), (int4)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  2396. return h | (ux & ~msk) >> 16;
  2397. }
  2398. /// <summary>Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context.</summary>
  2399. /// <param name="pBuffer">A pointer to the beginning of the data.</param>
  2400. /// <param name="numBytes">Number of bytes to hash.</param>
  2401. /// <param name="seed">Starting seed value.</param>
  2402. public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0)
  2403. {
  2404. unchecked
  2405. {
  2406. const uint Prime1 = 2654435761;
  2407. const uint Prime2 = 2246822519;
  2408. const uint Prime3 = 3266489917;
  2409. const uint Prime4 = 668265263;
  2410. const uint Prime5 = 374761393;
  2411. uint4* p = (uint4*)pBuffer;
  2412. uint hash = seed + Prime5;
  2413. if (numBytes >= 16)
  2414. {
  2415. uint4 state = new uint4(Prime1 + Prime2, Prime2, 0, (uint)-Prime1) + seed;
  2416. int count = numBytes >> 4;
  2417. for (int i = 0; i < count; ++i)
  2418. {
  2419. state += *p++ * Prime2;
  2420. state = (state << 13) | (state >> 19);
  2421. state *= Prime1;
  2422. }
  2423. hash = rol(state.x, 1) + rol(state.y, 7) + rol(state.z, 12) + rol(state.w, 18);
  2424. }
  2425. hash += (uint)numBytes;
  2426. uint* puint = (uint*)p;
  2427. for (int i = 0; i < ((numBytes >> 2) & 3); ++i)
  2428. {
  2429. hash += *puint++ * Prime3;
  2430. hash = rol(hash, 17) * Prime4;
  2431. }
  2432. byte* pbyte = (byte*)puint;
  2433. for (int i = 0; i < ((numBytes) & 3); ++i)
  2434. {
  2435. hash += (*pbyte++) * Prime5;
  2436. hash = rol(hash, 11) * Prime1;
  2437. }
  2438. hash ^= hash >> 15;
  2439. hash *= Prime2;
  2440. hash ^= hash >> 13;
  2441. hash *= Prime3;
  2442. hash ^= hash >> 16;
  2443. return hash;
  2444. }
  2445. }
  2446. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2447. public static float3 up() { return new float3(0.0f, 1.0f, 0.0f); } // for compatibility
  2448. // Internal
  2449. // SSE shuffles
  2450. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2451. internal static float4 unpacklo(float4 a, float4 b)
  2452. {
  2453. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  2454. }
  2455. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2456. internal static double4 unpacklo(double4 a, double4 b)
  2457. {
  2458. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  2459. }
  2460. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2461. internal static float4 unpackhi(float4 a, float4 b)
  2462. {
  2463. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  2464. }
  2465. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2466. internal static double4 unpackhi(double4 a, double4 b)
  2467. {
  2468. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  2469. }
  2470. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2471. internal static float4 movelh(float4 a, float4 b)
  2472. {
  2473. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  2474. }
  2475. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2476. internal static double4 movelh(double4 a, double4 b)
  2477. {
  2478. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  2479. }
  2480. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2481. internal static float4 movehl(float4 a, float4 b)
  2482. {
  2483. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  2484. }
  2485. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2486. internal static double4 movehl(double4 a, double4 b)
  2487. {
  2488. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  2489. }
  2490. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2491. internal static uint fold_to_uint(double x) // utility for double hashing
  2492. {
  2493. LongDoubleUnion u;
  2494. u.longValue = 0;
  2495. u.doubleValue = x;
  2496. return (uint)(u.longValue >> 32) ^ (uint)u.longValue;
  2497. }
  2498. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2499. internal static uint2 fold_to_uint(double2 x) { return uint2(fold_to_uint(x.x), fold_to_uint(x.y)); }
  2500. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2501. internal static uint3 fold_to_uint(double3 x) { return uint3(fold_to_uint(x.x), fold_to_uint(x.y), fold_to_uint(x.z)); }
  2502. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2503. internal static uint4 fold_to_uint(double4 x) { return uint4(fold_to_uint(x.x), fold_to_uint(x.y), fold_to_uint(x.z), fold_to_uint(x.w)); }
  2504. [StructLayout(LayoutKind.Explicit)]
  2505. internal struct IntFloatUnion
  2506. {
  2507. [FieldOffset(0)]
  2508. public int intValue;
  2509. [FieldOffset(0)]
  2510. public float floatValue;
  2511. }
  2512. [StructLayout(LayoutKind.Explicit)]
  2513. internal struct LongDoubleUnion
  2514. {
  2515. [FieldOffset(0)]
  2516. public long longValue;
  2517. [FieldOffset(0)]
  2518. public double doubleValue;
  2519. }
  2520. }
  2521. }