Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

math.cs 375KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Runtime.CompilerServices;
  4. using Unity.IL2CPP.CompilerServices;
  5. namespace Unity.Mathematics
  6. {
  7. /// <summary>
  8. /// A static class to contain various math functions and constants.
  9. /// </summary>
  10. [Il2CppEagerStaticClassConstruction]
  11. public static partial class math
  12. {
  13. /// <summary>Extrinsic rotation order. Specifies in which order rotations around the principal axes (x, y and z) are to be applied.</summary>
  14. public enum RotationOrder : byte
  15. {
  16. /// <summary>Extrinsic rotation around the x axis, then around the y axis and finally around the z axis.</summary>
  17. XYZ,
  18. /// <summary>Extrinsic rotation around the x axis, then around the z axis and finally around the y axis.</summary>
  19. XZY,
  20. /// <summary>Extrinsic rotation around the y axis, then around the x axis and finally around the z axis.</summary>
  21. YXZ,
  22. /// <summary>Extrinsic rotation around the y axis, then around the z axis and finally around the x axis.</summary>
  23. YZX,
  24. /// <summary>Extrinsic rotation around the z axis, then around the x axis and finally around the y axis.</summary>
  25. ZXY,
  26. /// <summary>Extrinsic rotation around the z axis, then around the y axis and finally around the x axis.</summary>
  27. ZYX,
  28. /// <summary>Unity default rotation order. Extrinsic Rotation around the z axis, then around the x axis and finally around the y axis.</summary>
  29. Default = ZXY
  30. };
  31. /// <summary>Specifies a shuffle component.</summary>
  32. public enum ShuffleComponent : byte
  33. {
  34. /// <summary>Specified the x component of the left vector.</summary>
  35. LeftX,
  36. /// <summary>Specified the y component of the left vector.</summary>
  37. LeftY,
  38. /// <summary>Specified the z component of the left vector.</summary>
  39. LeftZ,
  40. /// <summary>Specified the w component of the left vector.</summary>
  41. LeftW,
  42. /// <summary>Specified the x component of the right vector.</summary>
  43. RightX,
  44. /// <summary>Specified the y component of the right vector.</summary>
  45. RightY,
  46. /// <summary>Specified the z component of the right vector.</summary>
  47. RightZ,
  48. /// <summary>Specified the w component of the right vector.</summary>
  49. RightW
  50. };
  51. /// <summary>The mathematical constant e also known as Euler's number. Approximately 2.72. This is a f64/double precision constant.</summary>
  52. public const double E_DBL = 2.71828182845904523536;
  53. /// <summary>The base 2 logarithm of e. Approximately 1.44. This is a f64/double precision constant.</summary>
  54. public const double LOG2E_DBL = 1.44269504088896340736;
  55. /// <summary>The base 10 logarithm of e. Approximately 0.43. This is a f64/double precision constant.</summary>
  56. public const double LOG10E_DBL = 0.434294481903251827651;
  57. /// <summary>The natural logarithm of 2. Approximately 0.69. This is a f64/double precision constant.</summary>
  58. public const double LN2_DBL = 0.693147180559945309417;
  59. /// <summary>The natural logarithm of 10. Approximately 2.30. This is a f64/double precision constant.</summary>
  60. public const double LN10_DBL = 2.30258509299404568402;
  61. /// <summary>The mathematical constant pi. Approximately 3.14. This is a f64/double precision constant.</summary>
  62. public const double PI_DBL = 3.14159265358979323846;
  63. /// <summary>The square root 2. Approximately 1.41. This is a f64/double precision constant.</summary>
  64. public const double SQRT2_DBL = 1.41421356237309504880;
  65. /// <summary>
  66. /// The difference between 1.0 and the next representable f64/double precision number.
  67. ///
  68. /// Beware:
  69. /// This value is different from System.Double.Epsilon, which is the smallest, positive, denormalized f64/double.
  70. /// </summary>
  71. public const double EPSILON_DBL = 2.22044604925031308085e-16;
  72. /// <summary>
  73. /// Double precision constant for positive infinity.
  74. /// </summary>
  75. public const double INFINITY_DBL = Double.PositiveInfinity;
  76. /// <summary>
  77. /// Double precision constant for Not a Number.
  78. ///
  79. /// NAN_DBL is considered unordered, which means all comparisons involving it are false except for not equal (operator !=).
  80. /// As a consequence, NAN_DBL == NAN_DBL is false but NAN_DBL != NAN_DBL is true.
  81. ///
  82. /// Additionally, there are multiple bit representations for Not a Number, so if you must test if your value
  83. /// is NAN_DBL, use isnan().
  84. /// </summary>
  85. public const double NAN_DBL = Double.NaN;
  86. /// <summary>The smallest positive normal number representable in a float.</summary>
  87. public const float FLT_MIN_NORMAL = 1.175494351e-38F;
  88. /// <summary>The smallest positive normal number representable in a double. This is a f64/double precision constant.</summary>
  89. public const double DBL_MIN_NORMAL = 2.2250738585072014e-308;
  90. /// <summary>The mathematical constant e also known as Euler's number. Approximately 2.72.</summary>
  91. public const float E = (float)E_DBL;
  92. /// <summary>The base 2 logarithm of e. Approximately 1.44.</summary>
  93. public const float LOG2E = (float)LOG2E_DBL;
  94. /// <summary>The base 10 logarithm of e. Approximately 0.43.</summary>
  95. public const float LOG10E = (float)LOG10E_DBL;
  96. /// <summary>The natural logarithm of 2. Approximately 0.69.</summary>
  97. public const float LN2 = (float)LN2_DBL;
  98. /// <summary>The natural logarithm of 10. Approximately 2.30.</summary>
  99. public const float LN10 = (float)LN10_DBL;
  100. /// <summary>The mathematical constant pi. Approximately 3.14.</summary>
  101. public const float PI = (float)PI_DBL;
  102. /// <summary>The square root 2. Approximately 1.41.</summary>
  103. public const float SQRT2 = (float)SQRT2_DBL;
  104. /// <summary>
  105. /// The difference between 1.0f and the next representable f32/single precision number.
  106. ///
  107. /// Beware:
  108. /// This value is different from System.Single.Epsilon, which is the smallest, positive, denormalized f32/single.
  109. /// </summary>
  110. public const float EPSILON = 1.1920928955078125e-7f;
  111. /// <summary>
  112. /// Single precision constant for positive infinity.
  113. /// </summary>
  114. public const float INFINITY = Single.PositiveInfinity;
  115. /// <summary>
  116. /// Single precision constant for Not a Number.
  117. ///
  118. /// NAN is considered unordered, which means all comparisons involving it are false except for not equal (operator !=).
  119. /// As a consequence, NAN == NAN is false but NAN != NAN is true.
  120. ///
  121. /// Additionally, there are multiple bit representations for Not a Number, so if you must test if your value
  122. /// is NAN, use isnan().
  123. /// </summary>
  124. public const float NAN = Single.NaN;
  125. /// <summary>Returns the bit pattern of a uint as an int.</summary>
  126. /// <param name="x">The uint bits to copy.</param>
  127. /// <returns>The int with the same bit pattern as the input.</returns>
  128. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  129. public static int asint(uint x) { return (int)x; }
  130. /// <summary>Returns the bit pattern of a uint2 as an int2.</summary>
  131. /// <param name="x">The uint2 bits to copy.</param>
  132. /// <returns>The int2 with the same bit pattern as the input.</returns>
  133. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  134. public static int2 asint(uint2 x) { return int2((int)x.x, (int)x.y); }
  135. /// <summary>Returns the bit pattern of a uint3 as an int3.</summary>
  136. /// <param name="x">The uint3 bits to copy.</param>
  137. /// <returns>The int3 with the same bit pattern as the input.</returns>
  138. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  139. public static int3 asint(uint3 x) { return int3((int)x.x, (int)x.y, (int)x.z); }
  140. /// <summary>Returns the bit pattern of a uint4 as an int4.</summary>
  141. /// <param name="x">The uint4 bits to copy.</param>
  142. /// <returns>The int4 with the same bit pattern as the input.</returns>
  143. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  144. public static int4 asint(uint4 x) { return int4((int)x.x, (int)x.y, (int)x.z, (int)x.w); }
  145. /// <summary>Returns the bit pattern of a float as an int.</summary>
  146. /// <param name="x">The float bits to copy.</param>
  147. /// <returns>The int with the same bit pattern as the input.</returns>
  148. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  149. public static int asint(float x) {
  150. IntFloatUnion u;
  151. u.intValue = 0;
  152. u.floatValue = x;
  153. return u.intValue;
  154. }
  155. /// <summary>Returns the bit pattern of a float2 as an int2.</summary>
  156. /// <param name="x">The float2 bits to copy.</param>
  157. /// <returns>The int2 with the same bit pattern as the input.</returns>
  158. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  159. public static int2 asint(float2 x) { return int2(asint(x.x), asint(x.y)); }
  160. /// <summary>Returns the bit pattern of a float3 as an int3.</summary>
  161. /// <param name="x">The float3 bits to copy.</param>
  162. /// <returns>The int3 with the same bit pattern as the input.</returns>
  163. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  164. public static int3 asint(float3 x) { return int3(asint(x.x), asint(x.y), asint(x.z)); }
  165. /// <summary>Returns the bit pattern of a float4 as an int4.</summary>
  166. /// <param name="x">The float4 bits to copy.</param>
  167. /// <returns>The int4 with the same bit pattern as the input.</returns>
  168. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  169. public static int4 asint(float4 x) { return int4(asint(x.x), asint(x.y), asint(x.z), asint(x.w)); }
  170. /// <summary>Returns the bit pattern of an int as a uint.</summary>
  171. /// <param name="x">The int bits to copy.</param>
  172. /// <returns>The uint with the same bit pattern as the input.</returns>
  173. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  174. public static uint asuint(int x) { return (uint)x; }
  175. /// <summary>Returns the bit pattern of an int2 as a uint2.</summary>
  176. /// <param name="x">The int2 bits to copy.</param>
  177. /// <returns>The uint2 with the same bit pattern as the input.</returns>
  178. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  179. public static uint2 asuint(int2 x) { return uint2((uint)x.x, (uint)x.y); }
  180. /// <summary>Returns the bit pattern of an int3 as a uint3.</summary>
  181. /// <param name="x">The int3 bits to copy.</param>
  182. /// <returns>The uint3 with the same bit pattern as the input.</returns>
  183. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  184. public static uint3 asuint(int3 x) { return uint3((uint)x.x, (uint)x.y, (uint)x.z); }
  185. /// <summary>Returns the bit pattern of an int4 as a uint4.</summary>
  186. /// <param name="x">The int4 bits to copy.</param>
  187. /// <returns>The uint4 with the same bit pattern as the input.</returns>
  188. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  189. public static uint4 asuint(int4 x) { return uint4((uint)x.x, (uint)x.y, (uint)x.z, (uint)x.w); }
  190. /// <summary>Returns the bit pattern of a float as a uint.</summary>
  191. /// <param name="x">The float bits to copy.</param>
  192. /// <returns>The uint with the same bit pattern as the input.</returns>
  193. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  194. public static uint asuint(float x) { return (uint)asint(x); }
  195. /// <summary>Returns the bit pattern of a float2 as a uint2.</summary>
  196. /// <param name="x">The float2 bits to copy.</param>
  197. /// <returns>The uint2 with the same bit pattern as the input.</returns>
  198. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  199. public static uint2 asuint(float2 x) { return uint2(asuint(x.x), asuint(x.y)); }
  200. /// <summary>Returns the bit pattern of a float3 as a uint3.</summary>
  201. /// <param name="x">The float3 bits to copy.</param>
  202. /// <returns>The uint3 with the same bit pattern as the input.</returns>
  203. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  204. public static uint3 asuint(float3 x) { return uint3(asuint(x.x), asuint(x.y), asuint(x.z)); }
  205. /// <summary>Returns the bit pattern of a float4 as a uint4.</summary>
  206. /// <param name="x">The float4 bits to copy.</param>
  207. /// <returns>The uint4 with the same bit pattern as the input.</returns>
  208. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  209. public static uint4 asuint(float4 x) { return uint4(asuint(x.x), asuint(x.y), asuint(x.z), asuint(x.w)); }
  210. /// <summary>Returns the bit pattern of a ulong as a long.</summary>
  211. /// <param name="x">The ulong bits to copy.</param>
  212. /// <returns>The long with the same bit pattern as the input.</returns>
  213. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  214. public static long aslong(ulong x) { return (long)x; }
  215. /// <summary>Returns the bit pattern of a double as a long.</summary>
  216. /// <param name="x">The double bits to copy.</param>
  217. /// <returns>The long with the same bit pattern as the input.</returns>
  218. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  219. public static long aslong(double x)
  220. {
  221. LongDoubleUnion u;
  222. u.longValue = 0;
  223. u.doubleValue = x;
  224. return u.longValue;
  225. }
  226. /// <summary>Returns the bit pattern of a long as a ulong.</summary>
  227. /// <param name="x">The long bits to copy.</param>
  228. /// <returns>The ulong with the same bit pattern as the input.</returns>
  229. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  230. public static ulong asulong(long x) { return (ulong)x; }
  231. /// <summary>Returns the bit pattern of a double as a ulong.</summary>
  232. /// <param name="x">The double bits to copy.</param>
  233. /// <returns>The ulong with the same bit pattern as the input.</returns>
  234. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  235. public static ulong asulong(double x) { return (ulong) aslong(x); }
  236. /// <summary>Returns the bit pattern of an int as a float.</summary>
  237. /// <param name="x">The int bits to copy.</param>
  238. /// <returns>The float with the same bit pattern as the input.</returns>
  239. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  240. public static float asfloat(int x)
  241. {
  242. IntFloatUnion u;
  243. u.floatValue = 0;
  244. u.intValue = x;
  245. return u.floatValue;
  246. }
  247. /// <summary>Returns the bit pattern of an int2 as a float2.</summary>
  248. /// <param name="x">The int2 bits to copy.</param>
  249. /// <returns>The float2 with the same bit pattern as the input.</returns>
  250. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  251. public static float2 asfloat(int2 x) { return float2(asfloat(x.x), asfloat(x.y)); }
  252. /// <summary>Returns the bit pattern of an int3 as a float3.</summary>
  253. /// <param name="x">The int3 bits to copy.</param>
  254. /// <returns>The float3 with the same bit pattern as the input.</returns>
  255. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  256. public static float3 asfloat(int3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); }
  257. /// <summary>Returns the bit pattern of an int4 as a float4.</summary>
  258. /// <param name="x">The int4 bits to copy.</param>
  259. /// <returns>The float4 with the same bit pattern as the input.</returns>
  260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  261. public static float4 asfloat(int4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); }
  262. /// <summary>Returns the bit pattern of a uint as a float.</summary>
  263. /// <param name="x">The uint bits to copy.</param>
  264. /// <returns>The float with the same bit pattern as the input.</returns>
  265. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  266. public static float asfloat(uint x) { return asfloat((int)x); }
  267. /// <summary>Returns the bit pattern of a uint2 as a float2.</summary>
  268. /// <param name="x">The uint2 bits to copy.</param>
  269. /// <returns>The float2 with the same bit pattern as the input.</returns>
  270. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  271. public static float2 asfloat(uint2 x) { return float2(asfloat(x.x), asfloat(x.y)); }
  272. /// <summary>Returns the bit pattern of a uint3 as a float3.</summary>
  273. /// <param name="x">The uint3 bits to copy.</param>
  274. /// <returns>The float3 with the same bit pattern as the input.</returns>
  275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  276. public static float3 asfloat(uint3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); }
  277. /// <summary>Returns the bit pattern of a uint4 as a float4.</summary>
  278. /// <param name="x">The uint4 bits to copy.</param>
  279. /// <returns>The float4 with the same bit pattern as the input.</returns>
  280. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  281. public static float4 asfloat(uint4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); }
  282. /// <summary>
  283. /// Returns a bitmask representation of a bool4. Storing one 1 bit per component
  284. /// in LSB order, from lower to higher bits (so 4 bits in total).
  285. /// The component x is stored at bit 0,
  286. /// The component y is stored at bit 1,
  287. /// The component z is stored at bit 2,
  288. /// The component w is stored at bit 3
  289. /// The bool4(x = true, y = true, z = false, w = true) would produce the value 1011 = 0xB
  290. /// </summary>
  291. /// <param name="value">The input bool4 to calculate the bitmask for</param>
  292. /// <returns>A bitmask representation of the bool4, in LSB order</returns>
  293. public static int bitmask(bool4 value)
  294. {
  295. int mask = 0;
  296. if (value.x) mask |= 0x01;
  297. if (value.y) mask |= 0x02;
  298. if (value.z) mask |= 0x04;
  299. if (value.w) mask |= 0x08;
  300. return mask;
  301. }
  302. /// <summary>Returns the bit pattern of a long as a double.</summary>
  303. /// <param name="x">The long bits to copy.</param>
  304. /// <returns>The double with the same bit pattern as the input.</returns>
  305. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  306. public static double asdouble(long x)
  307. {
  308. LongDoubleUnion u;
  309. u.doubleValue = 0;
  310. u.longValue = x;
  311. return u.doubleValue;
  312. }
  313. /// <summary>Returns the bit pattern of a ulong as a double.</summary>
  314. /// <param name="x">The ulong bits to copy.</param>
  315. /// <returns>The double with the same bit pattern as the input.</returns>
  316. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  317. public static double asdouble(ulong x) { return asdouble((long)x); }
  318. /// <summary>Returns true if the input float is a finite floating point value, false otherwise.</summary>
  319. /// <param name="x">The float value to test.</param>
  320. /// <returns>True if the float is finite, false otherwise.</returns>
  321. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  322. public static bool isfinite(float x) { return abs(x) < float.PositiveInfinity; }
  323. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a finite floating point value.</summary>
  324. /// <param name="x">The float2 value to test.</param>
  325. /// <returns>A bool2 where it is true in a component if that component is finite, false otherwise.</returns>
  326. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  327. public static bool2 isfinite(float2 x) { return abs(x) < float.PositiveInfinity; }
  328. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a finite floating point value.</summary>
  329. /// <param name="x">The float3 value to test.</param>
  330. /// <returns>A bool3 where it is true in a component if that component is finite, false otherwise.</returns>
  331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  332. public static bool3 isfinite(float3 x) { return abs(x) < float.PositiveInfinity; }
  333. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a finite floating point value.</summary>
  334. /// <param name="x">The float4 value to test.</param>
  335. /// <returns>A bool4 where it is true in a component if that component is finite, false otherwise.</returns>
  336. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  337. public static bool4 isfinite(float4 x) { return abs(x) < float.PositiveInfinity; }
  338. /// <summary>Returns true if the input double is a finite floating point value, false otherwise.</summary>
  339. /// <param name="x">The double value to test.</param>
  340. /// <returns>True if the double is finite, false otherwise.</returns>
  341. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  342. public static bool isfinite(double x) { return abs(x) < double.PositiveInfinity; }
  343. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a finite floating point value.</summary>
  344. /// <param name="x">The double2 value to test.</param>
  345. /// <returns>A bool2 where it is true in a component if that component is finite, false otherwise.</returns>
  346. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  347. public static bool2 isfinite(double2 x) { return abs(x) < double.PositiveInfinity; }
  348. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a finite floating point value.</summary>
  349. /// <param name="x">The double3 value to test.</param>
  350. /// <returns>A bool3 where it is true in a component if that component is finite, false otherwise.</returns>
  351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  352. public static bool3 isfinite(double3 x) { return abs(x) < double.PositiveInfinity; }
  353. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a finite floating point value.</summary>
  354. /// <param name="x">The double4 value to test.</param>
  355. /// <returns>A bool4 where it is true in a component if that component is finite, false otherwise.</returns>
  356. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  357. public static bool4 isfinite(double4 x) { return abs(x) < double.PositiveInfinity; }
  358. /// <summary>Returns true if the input float is an infinite floating point value, false otherwise.</summary>
  359. /// <param name="x">Input value.</param>
  360. /// <returns>True if the input was an infinite value; false otherwise.</returns>
  361. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  362. public static bool isinf(float x) { return abs(x) == float.PositiveInfinity; }
  363. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is an infinite floating point value.</summary>
  364. /// <param name="x">Input value.</param>
  365. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  366. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  367. public static bool2 isinf(float2 x) { return abs(x) == float.PositiveInfinity; }
  368. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is an infinite floating point value.</summary>
  369. /// <param name="x">Input value.</param>
  370. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  371. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  372. public static bool3 isinf(float3 x) { return abs(x) == float.PositiveInfinity; }
  373. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is an infinite floating point value.</summary>
  374. /// <param name="x">Input value.</param>
  375. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  376. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  377. public static bool4 isinf(float4 x) { return abs(x) == float.PositiveInfinity; }
  378. /// <summary>Returns true if the input double is an infinite floating point value, false otherwise.</summary>
  379. /// <param name="x">Input value.</param>
  380. /// <returns>True if the input was an infinite value; false otherwise.</returns>
  381. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  382. public static bool isinf(double x) { return abs(x) == double.PositiveInfinity; }
  383. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is an infinite floating point value.</summary>
  384. /// <param name="x">Input value.</param>
  385. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  386. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  387. public static bool2 isinf(double2 x) { return abs(x) == double.PositiveInfinity; }
  388. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is an infinite floating point value.</summary>
  389. /// <param name="x">Input value.</param>
  390. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  391. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  392. public static bool3 isinf(double3 x) { return abs(x) == double.PositiveInfinity; }
  393. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is an infinite floating point value.</summary>
  394. /// <param name="x">Input value.</param>
  395. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  396. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  397. public static bool4 isinf(double4 x) { return abs(x) == double.PositiveInfinity; }
  398. /// <summary>Returns true if the input float is a NaN (not a number) floating point value, false otherwise.</summary>
  399. /// <remarks>
  400. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  401. /// </remarks>
  402. /// <param name="x">Input value.</param>
  403. /// <returns>True if the value was NaN; false otherwise.</returns>
  404. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  405. public static bool isnan(float x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  406. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a NaN (not a number) floating point value.</summary>
  407. /// <remarks>
  408. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  409. /// </remarks>
  410. /// <param name="x">Input value.</param>
  411. /// <returns>True if the component was NaN; false otherwise.</returns>
  412. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  413. public static bool2 isnan(float2 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  414. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a NaN (not a number) floating point value.</summary>
  415. /// <remarks>
  416. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  417. /// </remarks>
  418. /// <param name="x">Input value.</param>
  419. /// <returns>True if the component was NaN; false otherwise.</returns>
  420. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  421. public static bool3 isnan(float3 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  422. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a NaN (not a number) floating point value.</summary>
  423. /// <remarks>
  424. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  425. /// </remarks>
  426. /// <param name="x">Input value.</param>
  427. /// <returns>True if the component was NaN; false otherwise.</returns>
  428. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  429. public static bool4 isnan(float4 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  430. /// <summary>Returns true if the input double is a NaN (not a number) floating point value, false otherwise.</summary>
  431. /// <remarks>
  432. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  433. /// </remarks>
  434. /// <param name="x">Input value.</param>
  435. /// <returns>True if the value was NaN; false otherwise.</returns>
  436. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  437. public static bool isnan(double x) { return (asulong(x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000; }
  438. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a NaN (not a number) floating point value.</summary>
  439. /// <remarks>
  440. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  441. /// </remarks>
  442. /// <param name="x">Input value.</param>
  443. /// <returns>True if the component was NaN; false otherwise.</returns>
  444. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  445. public static bool2 isnan(double2 x) {
  446. return bool2((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  447. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  448. }
  449. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a NaN (not a number) floating point value.</summary>
  450. /// <remarks>
  451. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  452. /// </remarks>
  453. /// <param name="x">Input value.</param>
  454. /// <returns>True if the component was NaN; false otherwise.</returns>
  455. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  456. public static bool3 isnan(double3 x)
  457. {
  458. return bool3((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  459. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  460. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  461. }
  462. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a NaN (not a number) floating point value.</summary>
  463. /// <remarks>
  464. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  465. /// </remarks>
  466. /// <param name="x">Input value.</param>
  467. /// <returns>True if the component was NaN; false otherwise.</returns>
  468. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  469. public static bool4 isnan(double4 x)
  470. {
  471. return bool4((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  472. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  473. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  474. (asulong(x.w) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  475. }
  476. /// <summary>
  477. /// Checks if the input is a power of two.
  478. /// </summary>
  479. /// <remarks>If x is less than or equal to zero, then this function returns false.</remarks>
  480. /// <param name="x">Integer input.</param>
  481. /// <returns>bool where true indicates that input was a power of two.</returns>
  482. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  483. public static bool ispow2(int x)
  484. {
  485. return x > 0 && ((x & (x - 1)) == 0);
  486. }
  487. /// <summary>
  488. /// Checks if each component of the input is a power of two.
  489. /// </summary>
  490. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  491. /// <param name="x">int2 input</param>
  492. /// <returns>bool2 where true in a component indicates the same component in the input was a power of two.</returns>
  493. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  494. public static bool2 ispow2(int2 x)
  495. {
  496. return new bool2(ispow2(x.x), ispow2(x.y));
  497. }
  498. /// <summary>
  499. /// Checks if each component of the input is a power of two.
  500. /// </summary>
  501. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  502. /// <param name="x">int3 input</param>
  503. /// <returns>bool3 where true in a component indicates the same component in the input was a power of two.</returns>
  504. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  505. public static bool3 ispow2(int3 x)
  506. {
  507. return new bool3(ispow2(x.x), ispow2(x.y), ispow2(x.z));
  508. }
  509. /// <summary>
  510. /// Checks if each component of the input is a power of two.
  511. /// </summary>
  512. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  513. /// <param name="x">int4 input</param>
  514. /// <returns>bool4 where true in a component indicates the same component in the input was a power of two.</returns>
  515. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  516. public static bool4 ispow2(int4 x)
  517. {
  518. return new bool4(ispow2(x.x), ispow2(x.y), ispow2(x.z), ispow2(x.w));
  519. }
  520. /// <summary>
  521. /// Checks if the input is a power of two.
  522. /// </summary>
  523. /// <remarks>If x is less than or equal to zero, then this function returns false.</remarks>
  524. /// <param name="x">Unsigned integer input.</param>
  525. /// <returns>bool where true indicates that input was a power of two.</returns>
  526. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  527. public static bool ispow2(uint x)
  528. {
  529. return x > 0 && ((x & (x - 1)) == 0);
  530. }
  531. /// <summary>
  532. /// Checks if each component of the input is a power of two.
  533. /// </summary>
  534. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  535. /// <param name="x">uint2 input</param>
  536. /// <returns>bool2 where true in a component indicates the same component in the input was a power of two.</returns>
  537. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  538. public static bool2 ispow2(uint2 x)
  539. {
  540. return new bool2(ispow2(x.x), ispow2(x.y));
  541. }
  542. /// <summary>
  543. /// Checks if each component of the input is a power of two.
  544. /// </summary>
  545. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  546. /// <param name="x">uint3 input</param>
  547. /// <returns>bool3 where true in a component indicates the same component in the input was a power of two.</returns>
  548. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  549. public static bool3 ispow2(uint3 x)
  550. {
  551. return new bool3(ispow2(x.x), ispow2(x.y), ispow2(x.z));
  552. }
  553. /// <summary>
  554. /// Checks if each component of the input is a power of two.
  555. /// </summary>
  556. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  557. /// <param name="x">uint4 input</param>
  558. /// <returns>bool4 where true in a component indicates the same component in the input was a power of two.</returns>
  559. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  560. public static bool4 ispow2(uint4 x)
  561. {
  562. return new bool4(ispow2(x.x), ispow2(x.y), ispow2(x.z), ispow2(x.w));
  563. }
  564. /// <summary>Returns the minimum of two int values.</summary>
  565. /// <param name="x">The first input value.</param>
  566. /// <param name="y">The second input value.</param>
  567. /// <returns>The minimum of the two input values.</returns>
  568. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  569. public static int min(int x, int y) { return x < y ? x : y; }
  570. /// <summary>Returns the componentwise minimum of two int2 vectors.</summary>
  571. /// <param name="x">The first input value.</param>
  572. /// <param name="y">The second input value.</param>
  573. /// <returns>The componentwise minimum of the two input values.</returns>
  574. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  575. public static int2 min(int2 x, int2 y) { return new int2(min(x.x, y.x), min(x.y, y.y)); }
  576. /// <summary>Returns the componentwise minimum of two int3 vectors.</summary>
  577. /// <param name="x">The first input value.</param>
  578. /// <param name="y">The second input value.</param>
  579. /// <returns>The componentwise minimum of the two input values.</returns>
  580. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  581. 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)); }
  582. /// <summary>Returns the componentwise minimum of two int4 vectors.</summary>
  583. /// <param name="x">The first input value.</param>
  584. /// <param name="y">The second input value.</param>
  585. /// <returns>The componentwise minimum of the two input values.</returns>
  586. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  587. 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)); }
  588. /// <summary>Returns the minimum of two uint values.</summary>
  589. /// <param name="x">The first input value.</param>
  590. /// <param name="y">The second input value.</param>
  591. /// <returns>The minimum of the two input values.</returns>
  592. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  593. public static uint min(uint x, uint y) { return x < y ? x : y; }
  594. /// <summary>Returns the componentwise minimum of two uint2 vectors.</summary>
  595. /// <param name="x">The first input value.</param>
  596. /// <param name="y">The second input value.</param>
  597. /// <returns>The componentwise minimum of the two input values.</returns>
  598. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  599. public static uint2 min(uint2 x, uint2 y) { return new uint2(min(x.x, y.x), min(x.y, y.y)); }
  600. /// <summary>Returns the componentwise minimum of two uint3 vectors.</summary>
  601. /// <param name="x">The first input value.</param>
  602. /// <param name="y">The second input value.</param>
  603. /// <returns>The componentwise minimum of the two input values.</returns>
  604. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  605. 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)); }
  606. /// <summary>Returns the componentwise minimum of two uint4 vectors.</summary>
  607. /// <param name="x">The first input value.</param>
  608. /// <param name="y">The second input value.</param>
  609. /// <returns>The componentwise minimum of the two input values.</returns>
  610. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  611. 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)); }
  612. /// <summary>Returns the minimum of two long values.</summary>
  613. /// <param name="x">The first input value.</param>
  614. /// <param name="y">The second input value.</param>
  615. /// <returns>The minimum of the two input values.</returns>
  616. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  617. public static long min(long x, long y) { return x < y ? x : y; }
  618. /// <summary>Returns the minimum of two ulong values.</summary>
  619. /// <param name="x">The first input value.</param>
  620. /// <param name="y">The second input value.</param>
  621. /// <returns>The minimum of the two input values.</returns>
  622. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  623. public static ulong min(ulong x, ulong y) { return x < y ? x : y; }
  624. /// <summary>Returns the minimum of two float values.</summary>
  625. /// <param name="x">The first input value.</param>
  626. /// <param name="y">The second input value.</param>
  627. /// <returns>The minimum of the two input values.</returns>
  628. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  629. public static float min(float x, float y) { return float.IsNaN(y) || x < y ? x : y; }
  630. /// <summary>Returns the componentwise minimum of two float2 vectors.</summary>
  631. /// <param name="x">The first input value.</param>
  632. /// <param name="y">The second input value.</param>
  633. /// <returns>The componentwise minimum of the two input values.</returns>
  634. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  635. public static float2 min(float2 x, float2 y) { return new float2(min(x.x, y.x), min(x.y, y.y)); }
  636. /// <summary>Returns the componentwise minimum of two float3 vectors.</summary>
  637. /// <param name="x">The first input value.</param>
  638. /// <param name="y">The second input value.</param>
  639. /// <returns>The componentwise minimum of the two input values.</returns>
  640. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  641. 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)); }
  642. /// <summary>Returns the componentwise minimum of two float4 vectors.</summary>
  643. /// <param name="x">The first input value.</param>
  644. /// <param name="y">The second input value.</param>
  645. /// <returns>The componentwise minimum of the two input values.</returns>
  646. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  647. 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)); }
  648. /// <summary>Returns the minimum of two double values.</summary>
  649. /// <param name="x">The first input value.</param>
  650. /// <param name="y">The second input value.</param>
  651. /// <returns>The minimum of the two input values.</returns>
  652. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  653. public static double min(double x, double y) { return double.IsNaN(y) || x < y ? x : y; }
  654. /// <summary>Returns the componentwise minimum of two double2 vectors.</summary>
  655. /// <param name="x">The first input value.</param>
  656. /// <param name="y">The second input value.</param>
  657. /// <returns>The componentwise minimum of the two input values.</returns>
  658. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  659. public static double2 min(double2 x, double2 y) { return new double2(min(x.x, y.x), min(x.y, y.y)); }
  660. /// <summary>Returns the componentwise minimum of two double3 vectors.</summary>
  661. /// <param name="x">The first input value.</param>
  662. /// <param name="y">The second input value.</param>
  663. /// <returns>The componentwise minimum of the two input values.</returns>
  664. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  665. 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)); }
  666. /// <summary>Returns the componentwise minimum of two double4 vectors.</summary>
  667. /// <param name="x">The first input value.</param>
  668. /// <param name="y">The second input value.</param>
  669. /// <returns>The componentwise minimum of the two input values.</returns>
  670. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  671. 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)); }
  672. /// <summary>Returns the maximum of two int values.</summary>
  673. /// <param name="x">The first input value.</param>
  674. /// <param name="y">The second input value.</param>
  675. /// <returns>The maximum of the two input values.</returns>
  676. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  677. public static int max(int x, int y) { return x > y ? x : y; }
  678. /// <summary>Returns the componentwise maximum of two int2 vectors.</summary>
  679. /// <param name="x">The first input value.</param>
  680. /// <param name="y">The second input value.</param>
  681. /// <returns>The componentwise maximum of the two input values.</returns>
  682. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  683. public static int2 max(int2 x, int2 y) { return new int2(max(x.x, y.x), max(x.y, y.y)); }
  684. /// <summary>Returns the componentwise maximum of two int3 vectors.</summary>
  685. /// <param name="x">The first input value.</param>
  686. /// <param name="y">The second input value.</param>
  687. /// <returns>The componentwise maximum of the two input values.</returns>
  688. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  689. 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)); }
  690. /// <summary>Returns the componentwise maximum of two int4 vectors.</summary>
  691. /// <param name="x">The first input value.</param>
  692. /// <param name="y">The second input value.</param>
  693. /// <returns>The componentwise maximum of the two input values.</returns>
  694. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  695. 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)); }
  696. /// <summary>Returns the maximum of two uint values.</summary>
  697. /// <param name="x">The first input value.</param>
  698. /// <param name="y">The second input value.</param>
  699. /// <returns>The maximum of the two input values.</returns>
  700. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  701. public static uint max(uint x, uint y) { return x > y ? x : y; }
  702. /// <summary>Returns the componentwise maximum of two uint2 vectors.</summary>
  703. /// <param name="x">The first input value.</param>
  704. /// <param name="y">The second input value.</param>
  705. /// <returns>The componentwise maximum of the two input values.</returns>
  706. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  707. public static uint2 max(uint2 x, uint2 y) { return new uint2(max(x.x, y.x), max(x.y, y.y)); }
  708. /// <summary>Returns the componentwise maximum of two uint3 vectors.</summary>
  709. /// <param name="x">The first input value.</param>
  710. /// <param name="y">The second input value.</param>
  711. /// <returns>The componentwise maximum of the two input values.</returns>
  712. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  713. 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)); }
  714. /// <summary>Returns the componentwise maximum of two uint4 vectors.</summary>
  715. /// <param name="x">The first input value.</param>
  716. /// <param name="y">The second input value.</param>
  717. /// <returns>The componentwise maximum of the two input values.</returns>
  718. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  719. 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)); }
  720. /// <summary>Returns the maximum of two long values.</summary>
  721. /// <param name="x">The first input value.</param>
  722. /// <param name="y">The second input value.</param>
  723. /// <returns>The maximum of the two input values.</returns>
  724. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  725. public static long max(long x, long y) { return x > y ? x : y; }
  726. /// <summary>Returns the maximum of two ulong values.</summary>
  727. /// <param name="x">The first input value.</param>
  728. /// <param name="y">The second input value.</param>
  729. /// <returns>The maximum of the two input values.</returns>
  730. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  731. public static ulong max(ulong x, ulong y) { return x > y ? x : y; }
  732. /// <summary>Returns the maximum of two float values.</summary>
  733. /// <param name="x">The first input value.</param>
  734. /// <param name="y">The second input value.</param>
  735. /// <returns>The maximum of the two input values.</returns>
  736. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  737. public static float max(float x, float y) { return float.IsNaN(y) || x > y ? x : y; }
  738. /// <summary>Returns the componentwise maximum of two float2 vectors.</summary>
  739. /// <param name="x">The first input value.</param>
  740. /// <param name="y">The second input value.</param>
  741. /// <returns>The componentwise maximum of the two input values.</returns>
  742. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  743. public static float2 max(float2 x, float2 y) { return new float2(max(x.x, y.x), max(x.y, y.y)); }
  744. /// <summary>Returns the componentwise maximum of two float3 vectors.</summary>
  745. /// <param name="x">The first input value.</param>
  746. /// <param name="y">The second input value.</param>
  747. /// <returns>The componentwise maximum of the two input values.</returns>
  748. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  749. 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)); }
  750. /// <summary>Returns the componentwise maximum of two float4 vectors.</summary>
  751. /// <param name="x">The first input value.</param>
  752. /// <param name="y">The second input value.</param>
  753. /// <returns>The componentwise maximum of the two input values.</returns>
  754. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  755. 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)); }
  756. /// <summary>Returns the maximum of two double values.</summary>
  757. /// <param name="x">The first input value.</param>
  758. /// <param name="y">The second input value.</param>
  759. /// <returns>The maximum of the two input values.</returns>
  760. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  761. public static double max(double x, double y) { return double.IsNaN(y) || x > y ? x : y; }
  762. /// <summary>Returns the componentwise maximum of two double2 vectors.</summary>
  763. /// <param name="x">The first input value.</param>
  764. /// <param name="y">The second input value.</param>
  765. /// <returns>The componentwise maximum of the two input values.</returns>
  766. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  767. public static double2 max(double2 x, double2 y) { return new double2(max(x.x, y.x), max(x.y, y.y)); }
  768. /// <summary>Returns the componentwise maximum of two double3 vectors.</summary>
  769. /// <param name="x">The first input value.</param>
  770. /// <param name="y">The second input value.</param>
  771. /// <returns>The componentwise maximum of the two input values.</returns>
  772. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  773. 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)); }
  774. /// <summary>Returns the componentwise maximum of two double4 vectors.</summary>
  775. /// <param name="x">The first input value.</param>
  776. /// <param name="y">The second input value.</param>
  777. /// <returns>The componentwise maximum of the two input values.</returns>
  778. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  779. 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)); }
  780. /// <summary>Returns the result of linearly interpolating from x to y using the interpolation parameter s.</summary>
  781. /// <remarks>
  782. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  783. /// </remarks>
  784. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  785. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  786. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  787. /// <returns>The interpolation from x to y.</returns>
  788. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  789. public static float lerp(float x, float y, float s) { return x + s * (y - x); }
  790. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  791. /// <remarks>
  792. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  793. /// </remarks>
  794. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  795. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  796. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  797. /// <returns>The componentwise interpolation from x to y.</returns>
  798. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  799. public static float2 lerp(float2 x, float2 y, float s) { return x + s * (y - x); }
  800. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  801. /// <remarks>
  802. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  803. /// </remarks>
  804. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  805. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  806. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  807. /// <returns>The componentwise interpolation from x to y.</returns>
  808. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  809. public static float3 lerp(float3 x, float3 y, float s) { return x + s * (y - x); }
  810. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  811. /// <remarks>
  812. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  813. /// </remarks>
  814. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  815. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  816. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  817. /// <returns>The componentwise interpolation from x to y.</returns>
  818. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  819. public static float4 lerp(float4 x, float4 y, float s) { return x + s * (y - x); }
  820. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  821. /// <remarks>
  822. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  823. /// </remarks>
  824. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  825. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  826. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  827. /// <returns>The componentwise interpolation from x to y.</returns>
  828. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  829. public static float2 lerp(float2 x, float2 y, float2 s) { return x + s * (y - x); }
  830. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  831. /// <remarks>
  832. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  833. /// </remarks>
  834. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  835. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  836. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  837. /// <returns>The componentwise interpolation from x to y.</returns>
  838. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  839. public static float3 lerp(float3 x, float3 y, float3 s) { return x + s * (y - x); }
  840. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  841. /// <remarks>
  842. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  843. /// </remarks>
  844. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  845. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  846. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  847. /// <returns>The componentwise interpolation from x to y.</returns>
  848. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  849. public static float4 lerp(float4 x, float4 y, float4 s) { return x + s * (y - x); }
  850. /// <summary>Returns the result of linearly interpolating from x to y using the interpolation parameter s.</summary>
  851. /// <remarks>
  852. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  853. /// </remarks>
  854. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  855. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  856. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  857. /// <returns>The interpolation from x to y.</returns>
  858. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  859. public static double lerp(double x, double y, double s) { return x + s * (y - x); }
  860. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  861. /// <remarks>
  862. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  863. /// </remarks>
  864. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  865. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  866. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  867. /// <returns>The componentwise interpolation from x to y.</returns>
  868. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  869. public static double2 lerp(double2 x, double2 y, double s) { return x + s * (y - x); }
  870. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  871. /// <remarks>
  872. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  873. /// </remarks>
  874. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  875. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  876. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  877. /// <returns>The componentwise interpolation from x to y.</returns>
  878. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  879. public static double3 lerp(double3 x, double3 y, double s) { return x + s * (y - x); }
  880. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s.</summary>
  881. /// <remarks>
  882. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  883. /// </remarks>
  884. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  885. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  886. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  887. /// <returns>The componentwise interpolation from x to y.</returns>
  888. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  889. public static double4 lerp(double4 x, double4 y, double s) { return x + s * (y - x); }
  890. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  891. /// <remarks>
  892. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  893. /// </remarks>
  894. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  895. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  896. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  897. /// <returns>The componentwise interpolation from x to y.</returns>
  898. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  899. public static double2 lerp(double2 x, double2 y, double2 s) { return x + s * (y - x); }
  900. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  901. /// <remarks>
  902. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  903. /// </remarks>
  904. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  905. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  906. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  907. /// <returns>The componentwise interpolation from x to y.</returns>
  908. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  909. public static double3 lerp(double3 x, double3 y, double3 s) { return x + s * (y - x); }
  910. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s.</summary>
  911. /// <remarks>
  912. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  913. /// </remarks>
  914. /// <param name="x">The first endpoint, corresponding to the interpolation parameter value of 0.</param>
  915. /// <param name="y">The second endpoint, corresponding to the interpolation parameter value of 1.</param>
  916. /// <param name="s">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  917. /// <returns>The componentwise interpolation from x to y.</returns>
  918. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  919. public static double4 lerp(double4 x, double4 y, double4 s) { return x + s * (y - x); }
  920. /// <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>
  921. /// <param name="a">The first endpoint of the range.</param>
  922. /// <param name="b">The second endpoint of the range.</param>
  923. /// <param name="x">The value to normalize to the range.</param>
  924. /// <returns>The interpolation parameter of x with respect to the input range [a, b].</returns>
  925. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  926. public static float unlerp(float a, float b, float x) { return (x - a) / (b - a); }
  927. /// <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>
  928. /// <param name="a">The first endpoint of the range.</param>
  929. /// <param name="b">The second endpoint of the range.</param>
  930. /// <param name="x">The value to normalize to the range.</param>
  931. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  932. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  933. public static float2 unlerp(float2 a, float2 b, float2 x) { return (x - a) / (b - a); }
  934. /// <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>
  935. /// <param name="a">The first endpoint of the range.</param>
  936. /// <param name="b">The second endpoint of the range.</param>
  937. /// <param name="x">The value to normalize to the range.</param>
  938. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  939. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  940. public static float3 unlerp(float3 a, float3 b, float3 x) { return (x - a) / (b - a); }
  941. /// <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>
  942. /// <param name="a">The first endpoint of the range.</param>
  943. /// <param name="b">The second endpoint of the range.</param>
  944. /// <param name="x">The value to normalize to the range.</param>
  945. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  946. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  947. public static float4 unlerp(float4 a, float4 b, float4 x) { return (x - a) / (b - a); }
  948. /// <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>
  949. /// <param name="a">The first endpoint of the range.</param>
  950. /// <param name="b">The second endpoint of the range.</param>
  951. /// <param name="x">The value to normalize to the range.</param>
  952. /// <returns>The interpolation parameter of x with respect to the input range [a, b].</returns>
  953. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  954. public static double unlerp(double a, double b, double x) { return (x - a) / (b - a); }
  955. /// <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>
  956. /// <param name="a">The first endpoint of the range.</param>
  957. /// <param name="b">The second endpoint of the range.</param>
  958. /// <param name="x">The value to normalize to the range.</param>
  959. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  960. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  961. public static double2 unlerp(double2 a, double2 b, double2 x) { return (x - a) / (b - a); }
  962. /// <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>
  963. /// <param name="a">The first endpoint of the range.</param>
  964. /// <param name="b">The second endpoint of the range.</param>
  965. /// <param name="x">The value to normalize to the range.</param>
  966. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  967. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  968. public static double3 unlerp(double3 a, double3 b, double3 x) { return (x - a) / (b - a); }
  969. /// <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>
  970. /// <param name="a">The first endpoint of the range.</param>
  971. /// <param name="b">The second endpoint of the range.</param>
  972. /// <param name="x">The value to normalize to the range.</param>
  973. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  974. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  975. public static double4 unlerp(double4 a, double4 b, double4 x) { return (x - a) / (b - a); }
  976. /// <summary>Returns the result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  977. /// <param name="a">The first endpoint of the source range [a,b].</param>
  978. /// <param name="b">The second endpoint of the source range [a, b].</param>
  979. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  980. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  981. /// <param name="x">The value to remap from the source to destination range.</param>
  982. /// <returns>The remap of input x from the source range to the destination range.</returns>
  983. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  984. public static float remap(float a, float b, float c, float d, float x) { return lerp(c, d, unlerp(a, b, x)); }
  985. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  986. /// <param name="a">The first endpoint of the source range [a,b].</param>
  987. /// <param name="b">The second endpoint of the source range [a, b].</param>
  988. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  989. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  990. /// <param name="x">The value to remap from the source to destination range.</param>
  991. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  992. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  993. public static float2 remap(float2 a, float2 b, float2 c, float2 d, float2 x) { return lerp(c, d, unlerp(a, b, x)); }
  994. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  995. /// <param name="a">The first endpoint of the source range [a,b].</param>
  996. /// <param name="b">The second endpoint of the source range [a, b].</param>
  997. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  998. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  999. /// <param name="x">The value to remap from the source to destination range.</param>
  1000. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1001. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1002. public static float3 remap(float3 a, float3 b, float3 c, float3 d, float3 x) { return lerp(c, d, unlerp(a, b, x)); }
  1003. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  1004. /// <param name="a">The first endpoint of the source range [a,b].</param>
  1005. /// <param name="b">The second endpoint of the source range [a, b].</param>
  1006. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  1007. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  1008. /// <param name="x">The value to remap from the source to destination range.</param>
  1009. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1010. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1011. public static float4 remap(float4 a, float4 b, float4 c, float4 d, float4 x) { return lerp(c, d, unlerp(a, b, x)); }
  1012. /// <summary>Returns the result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  1013. /// <param name="a">The first endpoint of the source range [a,b].</param>
  1014. /// <param name="b">The second endpoint of the source range [a, b].</param>
  1015. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  1016. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  1017. /// <param name="x">The value to remap from the source to destination range.</param>
  1018. /// <returns>The remap of input x from the source range to the destination range.</returns>
  1019. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1020. public static double remap(double a, double b, double c, double d, double x) { return lerp(c, d, unlerp(a, b, x)); }
  1021. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  1022. /// <param name="a">The first endpoint of the source range [a,b].</param>
  1023. /// <param name="b">The second endpoint of the source range [a, b].</param>
  1024. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  1025. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  1026. /// <param name="x">The value to remap from the source to destination range.</param>
  1027. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1028. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1029. public static double2 remap(double2 a, double2 b, double2 c, double2 d, double2 x) { return lerp(c, d, unlerp(a, b, x)); }
  1030. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  1031. /// <param name="a">The first endpoint of the source range [a,b].</param>
  1032. /// <param name="b">The second endpoint of the source range [a, b].</param>
  1033. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  1034. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  1035. /// <param name="x">The value to remap from the source to destination range.</param>
  1036. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1037. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1038. public static double3 remap(double3 a, double3 b, double3 c, double3 d, double3 x) { return lerp(c, d, unlerp(a, b, x)); }
  1039. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [a, b] to the destination range [c, d].</summary>
  1040. /// <param name="a">The first endpoint of the source range [a,b].</param>
  1041. /// <param name="b">The second endpoint of the source range [a, b].</param>
  1042. /// <param name="c">The first endpoint of the destination range [c, d].</param>
  1043. /// <param name="d">The second endpoint of the destination range [c, d].</param>
  1044. /// <param name="x">The value to remap from the source to destination range.</param>
  1045. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1046. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1047. public static double4 remap(double4 a, double4 b, double4 c, double4 d, double4 x) { return lerp(c, d, unlerp(a, b, x)); }
  1048. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 int values.</summary>
  1049. /// <param name="a">First value to multiply.</param>
  1050. /// <param name="b">Second value to multiply.</param>
  1051. /// <param name="c">Third value to add to the product of a and b.</param>
  1052. /// <returns>The multiply-add of the inputs.</returns>
  1053. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1054. public static int mad(int a, int b, int c) { return a * b + c; }
  1055. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int2 vectors.</summary>
  1056. /// <param name="a">First value to multiply.</param>
  1057. /// <param name="b">Second value to multiply.</param>
  1058. /// <param name="c">Third value to add to the product of a and b.</param>
  1059. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1060. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1061. public static int2 mad(int2 a, int2 b, int2 c) { return a * b + c; }
  1062. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int3 vectors.</summary>
  1063. /// <param name="a">First value to multiply.</param>
  1064. /// <param name="b">Second value to multiply.</param>
  1065. /// <param name="c">Third value to add to the product of a and b.</param>
  1066. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1067. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1068. public static int3 mad(int3 a, int3 b, int3 c) { return a * b + c; }
  1069. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int4 vectors.</summary>
  1070. /// <param name="a">First value to multiply.</param>
  1071. /// <param name="b">Second value to multiply.</param>
  1072. /// <param name="c">Third value to add to the product of a and b.</param>
  1073. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1074. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1075. public static int4 mad(int4 a, int4 b, int4 c) { return a * b + c; }
  1076. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 uint values.</summary>
  1077. /// <param name="a">First value to multiply.</param>
  1078. /// <param name="b">Second value to multiply.</param>
  1079. /// <param name="c">Third value to add to the product of a and b.</param>
  1080. /// <returns>The multiply-add of the inputs.</returns>
  1081. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1082. public static uint mad(uint a, uint b, uint c) { return a * b + c; }
  1083. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint2 vectors.</summary>
  1084. /// <param name="a">First value to multiply.</param>
  1085. /// <param name="b">Second value to multiply.</param>
  1086. /// <param name="c">Third value to add to the product of a and b.</param>
  1087. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1088. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1089. public static uint2 mad(uint2 a, uint2 b, uint2 c) { return a * b + c; }
  1090. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint3 vectors.</summary>
  1091. /// <param name="a">First value to multiply.</param>
  1092. /// <param name="b">Second value to multiply.</param>
  1093. /// <param name="c">Third value to add to the product of a and b.</param>
  1094. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1095. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1096. public static uint3 mad(uint3 a, uint3 b, uint3 c) { return a * b + c; }
  1097. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint4 vectors.</summary>
  1098. /// <param name="a">First value to multiply.</param>
  1099. /// <param name="b">Second value to multiply.</param>
  1100. /// <param name="c">Third value to add to the product of a and b.</param>
  1101. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1102. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1103. public static uint4 mad(uint4 a, uint4 b, uint4 c) { return a * b + c; }
  1104. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 long values.</summary>
  1105. /// <param name="a">First value to multiply.</param>
  1106. /// <param name="b">Second value to multiply.</param>
  1107. /// <param name="c">Third value to add to the product of a and b.</param>
  1108. /// <returns>The multiply-add of the inputs.</returns>
  1109. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1110. public static long mad(long a, long b, long c) { return a * b + c; }
  1111. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 ulong values.</summary>
  1112. /// <param name="a">First value to multiply.</param>
  1113. /// <param name="b">Second value to multiply.</param>
  1114. /// <param name="c">Third value to add to the product of a and b.</param>
  1115. /// <returns>The multiply-add of the inputs.</returns>
  1116. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1117. public static ulong mad(ulong a, ulong b, ulong c) { return a * b + c; }
  1118. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 float values.</summary>
  1119. /// <remarks>
  1120. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1121. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1122. /// this computation is not fused.
  1123. /// </remarks>
  1124. /// <param name="a">First value to multiply.</param>
  1125. /// <param name="b">Second value to multiply.</param>
  1126. /// <param name="c">Third value to add to the product of a and b.</param>
  1127. /// <returns>The multiply-add of the inputs.</returns>
  1128. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1129. public static float mad(float a, float b, float c) { return a * b + c; }
  1130. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float2 vectors.</summary>
  1131. /// <remarks>
  1132. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1133. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1134. /// this computation is not fused.
  1135. /// </remarks>
  1136. /// <param name="a">First value to multiply.</param>
  1137. /// <param name="b">Second value to multiply.</param>
  1138. /// <param name="c">Third value to add to the product of a and b.</param>
  1139. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1140. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1141. public static float2 mad(float2 a, float2 b, float2 c) { return a * b + c; }
  1142. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float3 vectors.</summary>
  1143. /// <remarks>
  1144. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1145. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1146. /// this computation is not fused.
  1147. /// </remarks>
  1148. /// <param name="a">First value to multiply.</param>
  1149. /// <param name="b">Second value to multiply.</param>
  1150. /// <param name="c">Third value to add to the product of a and b.</param>
  1151. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1152. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1153. public static float3 mad(float3 a, float3 b, float3 c) { return a * b + c; }
  1154. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float4 vectors.</summary>
  1155. /// <remarks>
  1156. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1157. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1158. /// this computation is not fused.
  1159. /// </remarks>
  1160. /// <param name="a">First value to multiply.</param>
  1161. /// <param name="b">Second value to multiply.</param>
  1162. /// <param name="c">Third value to add to the product of a and b.</param>
  1163. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1164. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1165. public static float4 mad(float4 a, float4 b, float4 c) { return a * b + c; }
  1166. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 double values.</summary>
  1167. /// <remarks>
  1168. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1169. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1170. /// this computation is not fused.
  1171. /// </remarks>
  1172. /// <param name="a">First value to multiply.</param>
  1173. /// <param name="b">Second value to multiply.</param>
  1174. /// <param name="c">Third value to add to the product of a and b.</param>
  1175. /// <returns>The multiply-add of the inputs.</returns>
  1176. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1177. public static double mad(double a, double b, double c) { return a * b + c; }
  1178. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double2 vectors.</summary>
  1179. /// <remarks>
  1180. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1181. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1182. /// this computation is not fused.
  1183. /// </remarks>
  1184. /// <param name="a">First value to multiply.</param>
  1185. /// <param name="b">Second value to multiply.</param>
  1186. /// <param name="c">Third value to add to the product of a and b.</param>
  1187. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1188. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1189. public static double2 mad(double2 a, double2 b, double2 c) { return a * b + c; }
  1190. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double3 vectors.</summary>
  1191. /// <remarks>
  1192. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1193. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1194. /// this computation is not fused.
  1195. /// </remarks>
  1196. /// <param name="a">First value to multiply.</param>
  1197. /// <param name="b">Second value to multiply.</param>
  1198. /// <param name="c">Third value to add to the product of a and b.</param>
  1199. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1201. public static double3 mad(double3 a, double3 b, double3 c) { return a * b + c; }
  1202. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double4 vectors.</summary>
  1203. /// <remarks>
  1204. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1205. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1206. /// this computation is not fused.
  1207. /// </remarks>
  1208. /// <param name="a">First value to multiply.</param>
  1209. /// <param name="b">Second value to multiply.</param>
  1210. /// <param name="c">Third value to add to the product of a and b.</param>
  1211. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1212. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1213. public static double4 mad(double4 a, double4 b, double4 c) { return a * b + c; }
  1214. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are int values.</summary>
  1215. /// <param name="x">Input value to be clamped.</param>
  1216. /// <param name="a">Lower bound of the interval.</param>
  1217. /// <param name="b">Upper bound of the interval.</param>
  1218. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1219. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1220. public static int clamp(int x, int a, int b) { return max(a, min(b, x)); }
  1221. /// <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>
  1222. /// <param name="x">Input value to be clamped.</param>
  1223. /// <param name="a">Lower bound of the interval.</param>
  1224. /// <param name="b">Upper bound of the interval.</param>
  1225. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1226. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1227. public static int2 clamp(int2 x, int2 a, int2 b) { return max(a, min(b, x)); }
  1228. /// <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>
  1229. /// <param name="x">Input value to be clamped.</param>
  1230. /// <param name="a">Lower bound of the interval.</param>
  1231. /// <param name="b">Upper bound of the interval.</param>
  1232. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1234. public static int3 clamp(int3 x, int3 a, int3 b) { return max(a, min(b, x)); }
  1235. /// <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>
  1236. /// <param name="x">Input value to be clamped.</param>
  1237. /// <param name="a">Lower bound of the interval.</param>
  1238. /// <param name="b">Upper bound of the interval.</param>
  1239. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1240. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1241. public static int4 clamp(int4 x, int4 a, int4 b) { return max(a, min(b, x)); }
  1242. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are uint values.</summary>
  1243. /// <param name="x">Input value to be clamped.</param>
  1244. /// <param name="a">Lower bound of the interval.</param>
  1245. /// <param name="b">Upper bound of the interval.</param>
  1246. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1247. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1248. public static uint clamp(uint x, uint a, uint b) { return max(a, min(b, x)); }
  1249. /// <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>
  1250. /// <param name="x">Input value to be clamped.</param>
  1251. /// <param name="a">Lower bound of the interval.</param>
  1252. /// <param name="b">Upper bound of the interval.</param>
  1253. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1254. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1255. public static uint2 clamp(uint2 x, uint2 a, uint2 b) { return max(a, min(b, x)); }
  1256. /// <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>
  1257. /// <param name="x">Input value to be clamped.</param>
  1258. /// <param name="a">Lower bound of the interval.</param>
  1259. /// <param name="b">Upper bound of the interval.</param>
  1260. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1261. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1262. public static uint3 clamp(uint3 x, uint3 a, uint3 b) { return max(a, min(b, x)); }
  1263. /// <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>
  1264. /// <param name="x">Input value to be clamped.</param>
  1265. /// <param name="a">Lower bound of the interval.</param>
  1266. /// <param name="b">Upper bound of the interval.</param>
  1267. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1268. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1269. public static uint4 clamp(uint4 x, uint4 a, uint4 b) { return max(a, min(b, x)); }
  1270. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are long values.</summary>
  1271. /// <param name="x">Input value to be clamped.</param>
  1272. /// <param name="a">Lower bound of the interval.</param>
  1273. /// <param name="b">Upper bound of the interval.</param>
  1274. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1276. public static long clamp(long x, long a, long b) { return max(a, min(b, x)); }
  1277. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are ulong values.</summary>
  1278. /// <param name="x">Input value to be clamped.</param>
  1279. /// <param name="a">Lower bound of the interval.</param>
  1280. /// <param name="b">Upper bound of the interval.</param>
  1281. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1282. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1283. public static ulong clamp(ulong x, ulong a, ulong b) { return max(a, min(b, x)); }
  1284. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are float values.</summary>
  1285. /// <param name="x">Input value to be clamped.</param>
  1286. /// <param name="a">Lower bound of the interval.</param>
  1287. /// <param name="b">Upper bound of the interval.</param>
  1288. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1289. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1290. public static float clamp(float x, float a, float b) { return max(a, min(b, x)); }
  1291. /// <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>
  1292. /// <param name="x">Input value to be clamped.</param>
  1293. /// <param name="a">Lower bound of the interval.</param>
  1294. /// <param name="b">Upper bound of the interval.</param>
  1295. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1296. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1297. public static float2 clamp(float2 x, float2 a, float2 b) { return max(a, min(b, x)); }
  1298. /// <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>
  1299. /// <param name="x">Input value to be clamped.</param>
  1300. /// <param name="a">Lower bound of the interval.</param>
  1301. /// <param name="b">Upper bound of the interval.</param>
  1302. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1303. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1304. public static float3 clamp(float3 x, float3 a, float3 b) { return max(a, min(b, x)); }
  1305. /// <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>
  1306. /// <param name="x">Input value to be clamped.</param>
  1307. /// <param name="a">Lower bound of the interval.</param>
  1308. /// <param name="b">Upper bound of the interval.</param>
  1309. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1310. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1311. public static float4 clamp(float4 x, float4 a, float4 b) { return max(a, min(b, x)); }
  1312. /// <summary>Returns the result of clamping the value x into the interval [a, b], where x, a and b are double values.</summary>
  1313. /// <param name="x">Input value to be clamped.</param>
  1314. /// <param name="a">Lower bound of the interval.</param>
  1315. /// <param name="b">Upper bound of the interval.</param>
  1316. /// <returns>The clamping of the input x into the interval [a, b].</returns>
  1317. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1318. public static double clamp(double x, double a, double b) { return max(a, min(b, x)); }
  1319. /// <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>
  1320. /// <param name="x">Input value to be clamped.</param>
  1321. /// <param name="a">Lower bound of the interval.</param>
  1322. /// <param name="b">Upper bound of the interval.</param>
  1323. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1324. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1325. public static double2 clamp(double2 x, double2 a, double2 b) { return max(a, min(b, x)); }
  1326. /// <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>
  1327. /// <param name="x">Input value to be clamped.</param>
  1328. /// <param name="a">Lower bound of the interval.</param>
  1329. /// <param name="b">Upper bound of the interval.</param>
  1330. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1332. public static double3 clamp(double3 x, double3 a, double3 b) { return max(a, min(b, x)); }
  1333. /// <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>
  1334. /// <param name="x">Input value to be clamped.</param>
  1335. /// <param name="a">Lower bound of the interval.</param>
  1336. /// <param name="b">Upper bound of the interval.</param>
  1337. /// <returns>The componentwise clamping of the input x into the interval [a, b].</returns>
  1338. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1339. public static double4 clamp(double4 x, double4 a, double4 b) { return max(a, min(b, x)); }
  1340. /// <summary>Returns the result of clamping the float value x into the interval [0, 1].</summary>
  1341. /// <param name="x">Input value.</param>
  1342. /// <returns>The clamping of the input into the interval [0, 1].</returns>
  1343. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1344. public static float saturate(float x) { return clamp(x, 0.0f, 1.0f); }
  1345. /// <summary>Returns the result of a componentwise clamping of the float2 vector x into the interval [0, 1].</summary>
  1346. /// <param name="x">Input value.</param>
  1347. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1348. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1349. public static float2 saturate(float2 x) { return clamp(x, new float2(0.0f), new float2(1.0f)); }
  1350. /// <summary>Returns the result of a componentwise clamping of the float3 vector x into the interval [0, 1].</summary>
  1351. /// <param name="x">Input value.</param>
  1352. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1353. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1354. public static float3 saturate(float3 x) { return clamp(x, new float3(0.0f), new float3(1.0f)); }
  1355. /// <summary>Returns the result of a componentwise clamping of the float4 vector x into the interval [0, 1].</summary>
  1356. /// <param name="x">Input value.</param>
  1357. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1358. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1359. public static float4 saturate(float4 x) { return clamp(x, new float4(0.0f), new float4(1.0f)); }
  1360. /// <summary>Returns the result of clamping the double value x into the interval [0, 1].</summary>
  1361. /// <param name="x">Input value.</param>
  1362. /// <returns>The clamping of the input into the interval [0, 1].</returns>
  1363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1364. public static double saturate(double x) { return clamp(x, 0.0, 1.0); }
  1365. /// <summary>Returns the result of a componentwise clamping of the double2 vector x into the interval [0, 1].</summary>
  1366. /// <param name="x">Input value.</param>
  1367. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1368. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1369. public static double2 saturate(double2 x) { return clamp(x, new double2(0.0), new double2(1.0)); }
  1370. /// <summary>Returns the result of a componentwise clamping of the double3 vector x into the interval [0, 1].</summary>
  1371. /// <param name="x">Input value.</param>
  1372. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1373. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1374. public static double3 saturate(double3 x) { return clamp(x, new double3(0.0), new double3(1.0)); }
  1375. /// <summary>Returns the result of a componentwise clamping of the double4 vector x into the interval [0, 1].</summary>
  1376. /// <param name="x">Input value.</param>
  1377. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1378. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1379. public static double4 saturate(double4 x) { return clamp(x, new double4(0.0), new double4(1.0)); }
  1380. /// <summary>Returns the absolute value of a int value.</summary>
  1381. /// <param name="x">Input value.</param>
  1382. /// <returns>The absolute value of the input.</returns>
  1383. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1384. public static int abs(int x) { return max(-x, x); }
  1385. /// <summary>Returns the componentwise absolute value of a int2 vector.</summary>
  1386. /// <param name="x">Input value.</param>
  1387. /// <returns>The componentwise absolute value of the input.</returns>
  1388. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1389. public static int2 abs(int2 x) { return max(-x, x); }
  1390. /// <summary>Returns the componentwise absolute value of a int3 vector.</summary>
  1391. /// <param name="x">Input value.</param>
  1392. /// <returns>The componentwise absolute value of the input.</returns>
  1393. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1394. public static int3 abs(int3 x) { return max(-x, x); }
  1395. /// <summary>Returns the componentwise absolute value of a int4 vector.</summary>
  1396. /// <param name="x">Input value.</param>
  1397. /// <returns>The componentwise absolute value of the input.</returns>
  1398. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1399. public static int4 abs(int4 x) { return max(-x, x); }
  1400. /// <summary>Returns the absolute value of a long value.</summary>
  1401. /// <param name="x">Input value.</param>
  1402. /// <returns>The absolute value of the input.</returns>
  1403. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1404. public static long abs(long x) { return max(-x, x); }
  1405. /// <summary>Returns the absolute value of a float value.</summary>
  1406. /// <param name="x">Input value.</param>
  1407. /// <returns>The absolute value of the input.</returns>
  1408. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1409. public static float abs(float x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1410. /// <summary>Returns the componentwise absolute value of a float2 vector.</summary>
  1411. /// <param name="x">Input value.</param>
  1412. /// <returns>The componentwise absolute value of the input.</returns>
  1413. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1414. public static float2 abs(float2 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1415. /// <summary>Returns the componentwise absolute value of a float3 vector.</summary>
  1416. /// <param name="x">Input value.</param>
  1417. /// <returns>The componentwise absolute value of the input.</returns>
  1418. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1419. public static float3 abs(float3 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1420. /// <summary>Returns the componentwise absolute value of a float4 vector.</summary>
  1421. /// <param name="x">Input value.</param>
  1422. /// <returns>The componentwise absolute value of the input.</returns>
  1423. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1424. public static float4 abs(float4 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1425. /// <summary>Returns the absolute value of a double value.</summary>
  1426. /// <param name="x">Input value.</param>
  1427. /// <returns>The absolute value of the input.</returns>
  1428. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1429. public static double abs(double x) { return asdouble(asulong(x) & 0x7FFFFFFFFFFFFFFF); }
  1430. /// <summary>Returns the componentwise absolute value of a double2 vector.</summary>
  1431. /// <param name="x">Input value.</param>
  1432. /// <returns>The componentwise absolute value of the input.</returns>
  1433. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1434. public static double2 abs(double2 x) { return double2(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF)); }
  1435. /// <summary>Returns the componentwise absolute value of a double3 vector.</summary>
  1436. /// <param name="x">Input value.</param>
  1437. /// <returns>The componentwise absolute value of the input.</returns>
  1438. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1439. public static double3 abs(double3 x) { return double3(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.z) & 0x7FFFFFFFFFFFFFFF)); }
  1440. /// <summary>Returns the componentwise absolute value of a double4 vector.</summary>
  1441. /// <param name="x">Input value.</param>
  1442. /// <returns>The componentwise absolute value of the input.</returns>
  1443. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1444. 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)); }
  1445. /// <summary>Returns the dot product of two int values. Equivalent to multiplication.</summary>
  1446. /// <param name="x">The first value.</param>
  1447. /// <param name="y">The second value.</param>
  1448. /// <returns>The dot product of two values.</returns>
  1449. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1450. public static int dot(int x, int y) { return x * y; }
  1451. /// <summary>Returns the dot product of two int2 vectors.</summary>
  1452. /// <param name="x">The first vector.</param>
  1453. /// <param name="y">The second vector.</param>
  1454. /// <returns>The dot product of two vectors.</returns>
  1455. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1456. public static int dot(int2 x, int2 y) { return x.x * y.x + x.y * y.y; }
  1457. /// <summary>Returns the dot product of two int3 vectors.</summary>
  1458. /// <param name="x">The first vector.</param>
  1459. /// <param name="y">The second vector.</param>
  1460. /// <returns>The dot product of two vectors.</returns>
  1461. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1462. public static int dot(int3 x, int3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1463. /// <summary>Returns the dot product of two int4 vectors.</summary>
  1464. /// <param name="x">The first vector.</param>
  1465. /// <param name="y">The second vector.</param>
  1466. /// <returns>The dot product of two vectors.</returns>
  1467. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1468. 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; }
  1469. /// <summary>Returns the dot product of two uint values. Equivalent to multiplication.</summary>
  1470. /// <param name="x">The first value.</param>
  1471. /// <param name="y">The second value.</param>
  1472. /// <returns>The dot product of two values.</returns>
  1473. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1474. public static uint dot(uint x, uint y) { return x * y; }
  1475. /// <summary>Returns the dot product of two uint2 vectors.</summary>
  1476. /// <param name="x">The first vector.</param>
  1477. /// <param name="y">The second vector.</param>
  1478. /// <returns>The dot product of two vectors.</returns>
  1479. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1480. public static uint dot(uint2 x, uint2 y) { return x.x * y.x + x.y * y.y; }
  1481. /// <summary>Returns the dot product of two uint3 vectors.</summary>
  1482. /// <param name="x">The first vector.</param>
  1483. /// <param name="y">The second vector.</param>
  1484. /// <returns>The dot product of two vectors.</returns>
  1485. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1486. public static uint dot(uint3 x, uint3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1487. /// <summary>Returns the dot product of two uint4 vectors.</summary>
  1488. /// <param name="x">The first vector.</param>
  1489. /// <param name="y">The second vector.</param>
  1490. /// <returns>The dot product of two vectors.</returns>
  1491. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1492. 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; }
  1493. /// <summary>Returns the dot product of two float values. Equivalent to multiplication.</summary>
  1494. /// <param name="x">The first value.</param>
  1495. /// <param name="y">The second value.</param>
  1496. /// <returns>The dot product of two values.</returns>
  1497. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1498. public static float dot(float x, float y) { return x * y; }
  1499. /// <summary>Returns the dot product of two float2 vectors.</summary>
  1500. /// <param name="x">The first vector.</param>
  1501. /// <param name="y">The second vector.</param>
  1502. /// <returns>The dot product of two vectors.</returns>
  1503. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1504. public static float dot(float2 x, float2 y) { return x.x * y.x + x.y * y.y; }
  1505. /// <summary>Returns the dot product of two float3 vectors.</summary>
  1506. /// <param name="x">The first vector.</param>
  1507. /// <param name="y">The second vector.</param>
  1508. /// <returns>The dot product of two vectors.</returns>
  1509. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1510. public static float dot(float3 x, float3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1511. /// <summary>Returns the dot product of two float4 vectors.</summary>
  1512. /// <param name="x">The first vector.</param>
  1513. /// <param name="y">The second vector.</param>
  1514. /// <returns>The dot product of two vectors.</returns>
  1515. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1516. 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; }
  1517. /// <summary>Returns the dot product of two double values. Equivalent to multiplication.</summary>
  1518. /// <param name="x">The first value.</param>
  1519. /// <param name="y">The second value.</param>
  1520. /// <returns>The dot product of two values.</returns>
  1521. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1522. public static double dot(double x, double y) { return x * y; }
  1523. /// <summary>Returns the dot product of two double2 vectors.</summary>
  1524. /// <param name="x">The first vector.</param>
  1525. /// <param name="y">The second vector.</param>
  1526. /// <returns>The dot product of two vectors.</returns>
  1527. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1528. public static double dot(double2 x, double2 y) { return x.x * y.x + x.y * y.y; }
  1529. /// <summary>Returns the dot product of two double3 vectors.</summary>
  1530. /// <param name="x">The first vector.</param>
  1531. /// <param name="y">The second vector.</param>
  1532. /// <returns>The dot product of two vectors.</returns>
  1533. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1534. public static double dot(double3 x, double3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1535. /// <summary>Returns the dot product of two double4 vectors.</summary>
  1536. /// <param name="x">The first vector.</param>
  1537. /// <param name="y">The second vector.</param>
  1538. /// <returns>The dot product of two vectors.</returns>
  1539. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1540. 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; }
  1541. /// <summary>Returns the tangent of a float value.</summary>
  1542. /// <param name="x">Input value.</param>
  1543. /// <returns>The tangent of the input.</returns>
  1544. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1545. public static float tan(float x) { return (float)System.Math.Tan(x); }
  1546. /// <summary>Returns the componentwise tangent of a float2 vector.</summary>
  1547. /// <param name="x">Input value.</param>
  1548. /// <returns>The componentwise tangent of the input.</returns>
  1549. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1550. public static float2 tan(float2 x) { return new float2(tan(x.x), tan(x.y)); }
  1551. /// <summary>Returns the componentwise tangent of a float3 vector.</summary>
  1552. /// <param name="x">Input value.</param>
  1553. /// <returns>The componentwise tangent of the input.</returns>
  1554. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1555. public static float3 tan(float3 x) { return new float3(tan(x.x), tan(x.y), tan(x.z)); }
  1556. /// <summary>Returns the componentwise tangent of a float4 vector.</summary>
  1557. /// <param name="x">Input value.</param>
  1558. /// <returns>The componentwise tangent of the input.</returns>
  1559. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1560. public static float4 tan(float4 x) { return new float4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  1561. /// <summary>Returns the tangent of a double value.</summary>
  1562. /// <param name="x">Input value.</param>
  1563. /// <returns>The tangent of the input.</returns>
  1564. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1565. public static double tan(double x) { return System.Math.Tan(x); }
  1566. /// <summary>Returns the componentwise tangent of a double2 vector.</summary>
  1567. /// <param name="x">Input value.</param>
  1568. /// <returns>The componentwise tangent of the input.</returns>
  1569. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1570. public static double2 tan(double2 x) { return new double2(tan(x.x), tan(x.y)); }
  1571. /// <summary>Returns the componentwise tangent of a double3 vector.</summary>
  1572. /// <param name="x">Input value.</param>
  1573. /// <returns>The componentwise tangent of the input.</returns>
  1574. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1575. public static double3 tan(double3 x) { return new double3(tan(x.x), tan(x.y), tan(x.z)); }
  1576. /// <summary>Returns the componentwise tangent of a double4 vector.</summary>
  1577. /// <param name="x">Input value.</param>
  1578. /// <returns>The componentwise tangent of the input.</returns>
  1579. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1580. public static double4 tan(double4 x) { return new double4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  1581. /// <summary>Returns the hyperbolic tangent of a float value.</summary>
  1582. /// <param name="x">Input value.</param>
  1583. /// <returns>The hyperbolic tangent of the input.</returns>
  1584. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1585. public static float tanh(float x) { return (float)System.Math.Tanh(x); }
  1586. /// <summary>Returns the componentwise hyperbolic tangent of a float2 vector.</summary>
  1587. /// <param name="x">Input value.</param>
  1588. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1589. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1590. public static float2 tanh(float2 x) { return new float2(tanh(x.x), tanh(x.y)); }
  1591. /// <summary>Returns the componentwise hyperbolic tangent of a float3 vector.</summary>
  1592. /// <param name="x">Input value.</param>
  1593. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1594. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1595. public static float3 tanh(float3 x) { return new float3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  1596. /// <summary>Returns the componentwise hyperbolic tangent of a float4 vector.</summary>
  1597. /// <param name="x">Input value.</param>
  1598. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1599. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1600. public static float4 tanh(float4 x) { return new float4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  1601. /// <summary>Returns the hyperbolic tangent of a double value.</summary>
  1602. /// <param name="x">Input value.</param>
  1603. /// <returns>The hyperbolic tangent of the input.</returns>
  1604. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1605. public static double tanh(double x) { return System.Math.Tanh(x); }
  1606. /// <summary>Returns the componentwise hyperbolic tangent of a double2 vector.</summary>
  1607. /// <param name="x">Input value.</param>
  1608. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1609. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1610. public static double2 tanh(double2 x) { return new double2(tanh(x.x), tanh(x.y)); }
  1611. /// <summary>Returns the componentwise hyperbolic tangent of a double3 vector.</summary>
  1612. /// <param name="x">Input value.</param>
  1613. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1614. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1615. public static double3 tanh(double3 x) { return new double3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  1616. /// <summary>Returns the componentwise hyperbolic tangent of a double4 vector.</summary>
  1617. /// <param name="x">Input value.</param>
  1618. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1619. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1620. public static double4 tanh(double4 x) { return new double4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  1621. /// <summary>Returns the arctangent of a float value.</summary>
  1622. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1623. /// <returns>The arctangent of the input, in radians.</returns>
  1624. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1625. public static float atan(float x) { return (float)System.Math.Atan(x); }
  1626. /// <summary>Returns the componentwise arctangent of a float2 vector.</summary>
  1627. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1628. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1629. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1630. public static float2 atan(float2 x) { return new float2(atan(x.x), atan(x.y)); }
  1631. /// <summary>Returns the componentwise arctangent of a float3 vector.</summary>
  1632. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1633. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1634. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1635. public static float3 atan(float3 x) { return new float3(atan(x.x), atan(x.y), atan(x.z)); }
  1636. /// <summary>Returns the componentwise arctangent of a float4 vector.</summary>
  1637. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1638. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1639. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1640. public static float4 atan(float4 x) { return new float4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  1641. /// <summary>Returns the arctangent of a double value.</summary>
  1642. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1643. /// <returns>The arctangent of the input, in radians.</returns>
  1644. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1645. public static double atan(double x) { return System.Math.Atan(x); }
  1646. /// <summary>Returns the componentwise arctangent of a double2 vector.</summary>
  1647. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1648. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1649. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1650. public static double2 atan(double2 x) { return new double2(atan(x.x), atan(x.y)); }
  1651. /// <summary>Returns the componentwise arctangent of a double3 vector.</summary>
  1652. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1653. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1654. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1655. public static double3 atan(double3 x) { return new double3(atan(x.x), atan(x.y), atan(x.z)); }
  1656. /// <summary>Returns the componentwise arctangent of a double4 vector.</summary>
  1657. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1658. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1659. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1660. public static double4 atan(double4 x) { return new double4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  1661. /// <summary>Returns the 2-argument arctangent of a pair of float values.</summary>
  1662. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1663. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1664. /// <returns>The arctangent of the ratio y/x, in radians.</returns>
  1665. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1666. public static float atan2(float y, float x) { return (float)System.Math.Atan2(y, x); }
  1667. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats2 vectors.</summary>
  1668. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1669. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1670. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1671. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1672. public static float2 atan2(float2 y, float2 x) { return new float2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  1673. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats3 vectors.</summary>
  1674. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1675. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1676. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1677. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1678. 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)); }
  1679. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats4 vectors.</summary>
  1680. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1681. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1682. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1683. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1684. 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)); }
  1685. /// <summary>Returns the 2-argument arctangent of a pair of double values.</summary>
  1686. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1687. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1688. /// <returns>The arctangent of the ratio y/x, in radians.</returns>
  1689. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1690. public static double atan2(double y, double x) { return System.Math.Atan2(y, x); }
  1691. /// <summary>Returns the 2-argument arctangent of a pair of double2 vectors.</summary>
  1692. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1693. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1694. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1695. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1696. public static double2 atan2(double2 y, double2 x) { return new double2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  1697. /// <summary>Returns the 2-argument arctangent of a pair of double3 vectors.</summary>
  1698. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1699. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1700. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1701. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1702. 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)); }
  1703. /// <summary>Returns the 2-argument arctangent of a pair of double4 vectors.</summary>
  1704. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1705. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1706. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1707. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1708. 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)); }
  1709. /// <summary>Returns the cosine of a float value.</summary>
  1710. /// <param name="x">Input value.</param>
  1711. /// <returns>The cosine cosine of the input.</returns>
  1712. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1713. public static float cos(float x) { return (float)System.Math.Cos(x); }
  1714. /// <summary>Returns the componentwise cosine of a float2 vector.</summary>
  1715. /// <param name="x">Input value.</param>
  1716. /// <returns>The componentwise cosine cosine of the input.</returns>
  1717. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1718. public static float2 cos(float2 x) { return new float2(cos(x.x), cos(x.y)); }
  1719. /// <summary>Returns the componentwise cosine of a float3 vector.</summary>
  1720. /// <param name="x">Input value.</param>
  1721. /// <returns>The componentwise cosine cosine of the input.</returns>
  1722. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1723. public static float3 cos(float3 x) { return new float3(cos(x.x), cos(x.y), cos(x.z)); }
  1724. /// <summary>Returns the componentwise cosine of a float4 vector.</summary>
  1725. /// <param name="x">Input value.</param>
  1726. /// <returns>The componentwise cosine cosine of the input.</returns>
  1727. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1728. public static float4 cos(float4 x) { return new float4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  1729. /// <summary>Returns the cosine of a double value.</summary>
  1730. /// <param name="x">Input value.</param>
  1731. /// <returns>The cosine cosine of the input.</returns>
  1732. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1733. public static double cos(double x) { return System.Math.Cos(x); }
  1734. /// <summary>Returns the componentwise cosine of a double2 vector.</summary>
  1735. /// <param name="x">Input value.</param>
  1736. /// <returns>The componentwise cosine cosine of the input.</returns>
  1737. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1738. public static double2 cos(double2 x) { return new double2(cos(x.x), cos(x.y)); }
  1739. /// <summary>Returns the componentwise cosine of a double3 vector.</summary>
  1740. /// <param name="x">Input value.</param>
  1741. /// <returns>The componentwise cosine cosine of the input.</returns>
  1742. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1743. public static double3 cos(double3 x) { return new double3(cos(x.x), cos(x.y), cos(x.z)); }
  1744. /// <summary>Returns the componentwise cosine of a double4 vector.</summary>
  1745. /// <param name="x">Input value.</param>
  1746. /// <returns>The componentwise cosine cosine of the input.</returns>
  1747. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1748. public static double4 cos(double4 x) { return new double4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  1749. /// <summary>Returns the hyperbolic cosine of a float value.</summary>
  1750. /// <param name="x">Input value.</param>
  1751. /// <returns>The hyperbolic cosine of the input.</returns>
  1752. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1753. public static float cosh(float x) { return (float)System.Math.Cosh(x); }
  1754. /// <summary>Returns the componentwise hyperbolic cosine of a float2 vector.</summary>
  1755. /// <param name="x">Input value.</param>
  1756. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1757. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1758. public static float2 cosh(float2 x) { return new float2(cosh(x.x), cosh(x.y)); }
  1759. /// <summary>Returns the componentwise hyperbolic cosine of a float3 vector.</summary>
  1760. /// <param name="x">Input value.</param>
  1761. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1762. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1763. public static float3 cosh(float3 x) { return new float3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  1764. /// <summary>Returns the componentwise hyperbolic cosine of a float4 vector.</summary>
  1765. /// <param name="x">Input value.</param>
  1766. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1767. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1768. public static float4 cosh(float4 x) { return new float4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  1769. /// <summary>Returns the hyperbolic cosine of a double value.</summary>
  1770. /// <param name="x">Input value.</param>
  1771. /// <returns>The hyperbolic cosine of the input.</returns>
  1772. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1773. public static double cosh(double x) { return System.Math.Cosh(x); }
  1774. /// <summary>Returns the componentwise hyperbolic cosine of a double2 vector.</summary>
  1775. /// <param name="x">Input value.</param>
  1776. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1777. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1778. public static double2 cosh(double2 x) { return new double2(cosh(x.x), cosh(x.y)); }
  1779. /// <summary>Returns the componentwise hyperbolic cosine of a double3 vector.</summary>
  1780. /// <param name="x">Input value.</param>
  1781. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1782. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1783. public static double3 cosh(double3 x) { return new double3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  1784. /// <summary>Returns the componentwise hyperbolic cosine of a double4 vector.</summary>
  1785. /// <param name="x">Input value.</param>
  1786. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1787. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1788. public static double4 cosh(double4 x) { return new double4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  1789. /// <summary>Returns the arccosine of a float value.</summary>
  1790. /// <param name="x">Input value.</param>
  1791. /// <returns>The arccosine of the input.</returns>
  1792. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1793. public static float acos(float x) { return (float)System.Math.Acos((float)x); }
  1794. /// <summary>Returns the componentwise arccosine of a float2 vector.</summary>
  1795. /// <param name="x">Input value.</param>
  1796. /// <returns>The componentwise arccosine of the input.</returns>
  1797. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1798. public static float2 acos(float2 x) { return new float2(acos(x.x), acos(x.y)); }
  1799. /// <summary>Returns the componentwise arccosine of a float3 vector.</summary>
  1800. /// <param name="x">Input value.</param>
  1801. /// <returns>The componentwise arccosine of the input.</returns>
  1802. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1803. public static float3 acos(float3 x) { return new float3(acos(x.x), acos(x.y), acos(x.z)); }
  1804. /// <summary>Returns the componentwise arccosine of a float4 vector.</summary>
  1805. /// <param name="x">Input value.</param>
  1806. /// <returns>The componentwise arccosine of the input.</returns>
  1807. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1808. public static float4 acos(float4 x) { return new float4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  1809. /// <summary>Returns the arccosine of a double value.</summary>
  1810. /// <param name="x">Input value.</param>
  1811. /// <returns>The arccosine of the input.</returns>
  1812. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1813. public static double acos(double x) { return System.Math.Acos(x); }
  1814. /// <summary>Returns the componentwise arccosine of a double2 vector.</summary>
  1815. /// <param name="x">Input value.</param>
  1816. /// <returns>The componentwise arccosine of the input.</returns>
  1817. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1818. public static double2 acos(double2 x) { return new double2(acos(x.x), acos(x.y)); }
  1819. /// <summary>Returns the componentwise arccosine of a double3 vector.</summary>
  1820. /// <param name="x">Input value.</param>
  1821. /// <returns>The componentwise arccosine of the input.</returns>
  1822. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1823. public static double3 acos(double3 x) { return new double3(acos(x.x), acos(x.y), acos(x.z)); }
  1824. /// <summary>Returns the componentwise arccosine of a double4 vector.</summary>
  1825. /// <param name="x">Input value.</param>
  1826. /// <returns>The componentwise arccosine of the input.</returns>
  1827. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1828. public static double4 acos(double4 x) { return new double4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  1829. /// <summary>Returns the sine of a float value.</summary>
  1830. /// <param name="x">Input value.</param>
  1831. /// <returns>The sine of the input.</returns>
  1832. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1833. public static float sin(float x) { return (float)System.Math.Sin((float)x); }
  1834. /// <summary>Returns the componentwise sine of a float2 vector.</summary>
  1835. /// <param name="x">Input value.</param>
  1836. /// <returns>The componentwise sine of the input.</returns>
  1837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1838. public static float2 sin(float2 x) { return new float2(sin(x.x), sin(x.y)); }
  1839. /// <summary>Returns the componentwise sine of a float3 vector.</summary>
  1840. /// <param name="x">Input value.</param>
  1841. /// <returns>The componentwise sine of the input.</returns>
  1842. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1843. public static float3 sin(float3 x) { return new float3(sin(x.x), sin(x.y), sin(x.z)); }
  1844. /// <summary>Returns the componentwise sine of a float4 vector.</summary>
  1845. /// <param name="x">Input value.</param>
  1846. /// <returns>The componentwise sine of the input.</returns>
  1847. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1848. public static float4 sin(float4 x) { return new float4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  1849. /// <summary>Returns the sine of a double value.</summary>
  1850. /// <param name="x">Input value.</param>
  1851. /// <returns>The sine of the input.</returns>
  1852. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1853. public static double sin(double x) { return System.Math.Sin(x); }
  1854. /// <summary>Returns the componentwise sine of a double2 vector.</summary>
  1855. /// <param name="x">Input value.</param>
  1856. /// <returns>The componentwise sine of the input.</returns>
  1857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1858. public static double2 sin(double2 x) { return new double2(sin(x.x), sin(x.y)); }
  1859. /// <summary>Returns the componentwise sine of a double3 vector.</summary>
  1860. /// <param name="x">Input value.</param>
  1861. /// <returns>The componentwise sine of the input.</returns>
  1862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1863. public static double3 sin(double3 x) { return new double3(sin(x.x), sin(x.y), sin(x.z)); }
  1864. /// <summary>Returns the componentwise sine of a double4 vector.</summary>
  1865. /// <param name="x">Input value.</param>
  1866. /// <returns>The componentwise sine of the input.</returns>
  1867. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1868. public static double4 sin(double4 x) { return new double4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  1869. /// <summary>Returns the hyperbolic sine of a float value.</summary>
  1870. /// <param name="x">Input value.</param>
  1871. /// <returns>The hyperbolic sine of the input.</returns>
  1872. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1873. public static float sinh(float x) { return (float)System.Math.Sinh((float)x); }
  1874. /// <summary>Returns the componentwise hyperbolic sine of a float2 vector.</summary>
  1875. /// <param name="x">Input value.</param>
  1876. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1877. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1878. public static float2 sinh(float2 x) { return new float2(sinh(x.x), sinh(x.y)); }
  1879. /// <summary>Returns the componentwise hyperbolic sine of a float3 vector.</summary>
  1880. /// <param name="x">Input value.</param>
  1881. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1882. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1883. public static float3 sinh(float3 x) { return new float3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  1884. /// <summary>Returns the componentwise hyperbolic sine of a float4 vector.</summary>
  1885. /// <param name="x">Input value.</param>
  1886. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1887. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1888. public static float4 sinh(float4 x) { return new float4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  1889. /// <summary>Returns the hyperbolic sine of a double value.</summary>
  1890. /// <param name="x">Input value.</param>
  1891. /// <returns>The hyperbolic sine of the input.</returns>
  1892. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1893. public static double sinh(double x) { return System.Math.Sinh(x); }
  1894. /// <summary>Returns the componentwise hyperbolic sine of a double2 vector.</summary>
  1895. /// <param name="x">Input value.</param>
  1896. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1897. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1898. public static double2 sinh(double2 x) { return new double2(sinh(x.x), sinh(x.y)); }
  1899. /// <summary>Returns the componentwise hyperbolic sine of a double3 vector.</summary>
  1900. /// <param name="x">Input value.</param>
  1901. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1902. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1903. public static double3 sinh(double3 x) { return new double3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  1904. /// <summary>Returns the componentwise hyperbolic sine of a double4 vector.</summary>
  1905. /// <param name="x">Input value.</param>
  1906. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  1907. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1908. public static double4 sinh(double4 x) { return new double4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  1909. /// <summary>Returns the arcsine of a float value.</summary>
  1910. /// <param name="x">Input value.</param>
  1911. /// <returns>The arcsine of the input.</returns>
  1912. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1913. public static float asin(float x) { return (float)System.Math.Asin((float)x); }
  1914. /// <summary>Returns the componentwise arcsine of a float2 vector.</summary>
  1915. /// <param name="x">Input value.</param>
  1916. /// <returns>The componentwise arcsine of the input.</returns>
  1917. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1918. public static float2 asin(float2 x) { return new float2(asin(x.x), asin(x.y)); }
  1919. /// <summary>Returns the componentwise arcsine of a float3 vector.</summary>
  1920. /// <param name="x">Input value.</param>
  1921. /// <returns>The componentwise arcsine of the input.</returns>
  1922. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1923. public static float3 asin(float3 x) { return new float3(asin(x.x), asin(x.y), asin(x.z)); }
  1924. /// <summary>Returns the componentwise arcsine of a float4 vector.</summary>
  1925. /// <param name="x">Input value.</param>
  1926. /// <returns>The componentwise arcsine of the input.</returns>
  1927. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1928. public static float4 asin(float4 x) { return new float4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  1929. /// <summary>Returns the arcsine of a double value.</summary>
  1930. /// <param name="x">Input value.</param>
  1931. /// <returns>The arcsine of the input.</returns>
  1932. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1933. public static double asin(double x) { return System.Math.Asin(x); }
  1934. /// <summary>Returns the componentwise arcsine of a double2 vector.</summary>
  1935. /// <param name="x">Input value.</param>
  1936. /// <returns>The componentwise arcsine of the input.</returns>
  1937. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1938. public static double2 asin(double2 x) { return new double2(asin(x.x), asin(x.y)); }
  1939. /// <summary>Returns the componentwise arcsine of a double3 vector.</summary>
  1940. /// <param name="x">Input value.</param>
  1941. /// <returns>The componentwise arcsine of the input.</returns>
  1942. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1943. public static double3 asin(double3 x) { return new double3(asin(x.x), asin(x.y), asin(x.z)); }
  1944. /// <summary>Returns the componentwise arcsine of a double4 vector.</summary>
  1945. /// <param name="x">Input value.</param>
  1946. /// <returns>The componentwise arcsine of the input.</returns>
  1947. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1948. public static double4 asin(double4 x) { return new double4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  1949. /// <summary>Returns the result of rounding a float value up to the nearest integral value less or equal to the original value.</summary>
  1950. /// <param name="x">Input value.</param>
  1951. /// <returns>The round down to nearest integral value of the input.</returns>
  1952. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1953. public static float floor(float x) { return (float)System.Math.Floor((float)x); }
  1954. /// <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>
  1955. /// <param name="x">Input value.</param>
  1956. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1957. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1958. public static float2 floor(float2 x) { return new float2(floor(x.x), floor(x.y)); }
  1959. /// <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>
  1960. /// <param name="x">Input value.</param>
  1961. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1962. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1963. public static float3 floor(float3 x) { return new float3(floor(x.x), floor(x.y), floor(x.z)); }
  1964. /// <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>
  1965. /// <param name="x">Input value.</param>
  1966. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1967. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1968. public static float4 floor(float4 x) { return new float4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  1969. /// <summary>Returns the result of rounding a double value up to the nearest integral value less or equal to the original value.</summary>
  1970. /// <param name="x">Input value.</param>
  1971. /// <returns>The round down to nearest integral value of the input.</returns>
  1972. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1973. public static double floor(double x) { return System.Math.Floor(x); }
  1974. /// <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>
  1975. /// <param name="x">Input value.</param>
  1976. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1977. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1978. public static double2 floor(double2 x) { return new double2(floor(x.x), floor(x.y)); }
  1979. /// <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>
  1980. /// <param name="x">Input value.</param>
  1981. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1982. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1983. public static double3 floor(double3 x) { return new double3(floor(x.x), floor(x.y), floor(x.z)); }
  1984. /// <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>
  1985. /// <param name="x">Input value.</param>
  1986. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  1987. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1988. public static double4 floor(double4 x) { return new double4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  1989. /// <summary>Returns the result of rounding a float value up to the nearest integral value greater or equal to the original value.</summary>
  1990. /// <param name="x">Input value.</param>
  1991. /// <returns>The round up to nearest integral value of the input.</returns>
  1992. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1993. public static float ceil(float x) { return (float)System.Math.Ceiling((float)x); }
  1994. /// <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>
  1995. /// <param name="x">Input value.</param>
  1996. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  1997. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1998. public static float2 ceil(float2 x) { return new float2(ceil(x.x), ceil(x.y)); }
  1999. /// <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>
  2000. /// <param name="x">Input value.</param>
  2001. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2002. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2003. public static float3 ceil(float3 x) { return new float3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  2004. /// <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>
  2005. /// <param name="x">Input value.</param>
  2006. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2007. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2008. public static float4 ceil(float4 x) { return new float4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  2009. /// <summary>Returns the result of rounding a double value up to the nearest greater integral value greater or equal to the original value.</summary>
  2010. /// <param name="x">Input value.</param>
  2011. /// <returns>The round up to nearest integral value of the input.</returns>
  2012. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2013. public static double ceil(double x) { return System.Math.Ceiling(x); }
  2014. /// <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>
  2015. /// <param name="x">Input value.</param>
  2016. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2017. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2018. public static double2 ceil(double2 x) { return new double2(ceil(x.x), ceil(x.y)); }
  2019. /// <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>
  2020. /// <param name="x">Input value.</param>
  2021. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2022. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2023. public static double3 ceil(double3 x) { return new double3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  2024. /// <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>
  2025. /// <param name="x">Input value.</param>
  2026. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2027. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2028. public static double4 ceil(double4 x) { return new double4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  2029. /// <summary>Returns the result of rounding a float value to the nearest integral value.</summary>
  2030. /// <param name="x">Input value.</param>
  2031. /// <returns>The round to nearest integral value of the input.</returns>
  2032. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2033. public static float round(float x) { return (float)System.Math.Round((float)x); }
  2034. /// <summary>Returns the result of rounding each component of a float2 vector value to the nearest integral value.</summary>
  2035. /// <param name="x">Input value.</param>
  2036. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2037. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2038. public static float2 round(float2 x) { return new float2(round(x.x), round(x.y)); }
  2039. /// <summary>Returns the result of rounding each component of a float3 vector value to the nearest integral value.</summary>
  2040. /// <param name="x">Input value.</param>
  2041. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2042. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2043. public static float3 round(float3 x) { return new float3(round(x.x), round(x.y), round(x.z)); }
  2044. /// <summary>Returns the result of rounding each component of a float4 vector value to the nearest integral value.</summary>
  2045. /// <param name="x">Input value.</param>
  2046. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2047. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2048. public static float4 round(float4 x) { return new float4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  2049. /// <summary>Returns the result of rounding a double value to the nearest integral value.</summary>
  2050. /// <param name="x">Input value.</param>
  2051. /// <returns>The round to nearest integral value of the input.</returns>
  2052. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2053. public static double round(double x) { return System.Math.Round(x); }
  2054. /// <summary>Returns the result of rounding each component of a double2 vector value to the nearest integral value.</summary>
  2055. /// <param name="x">Input value.</param>
  2056. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2057. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2058. public static double2 round(double2 x) { return new double2(round(x.x), round(x.y)); }
  2059. /// <summary>Returns the result of rounding each component of a double3 vector value to the nearest integral value.</summary>
  2060. /// <param name="x">Input value.</param>
  2061. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2062. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2063. public static double3 round(double3 x) { return new double3(round(x.x), round(x.y), round(x.z)); }
  2064. /// <summary>Returns the result of rounding each component of a double4 vector value to the nearest integral value.</summary>
  2065. /// <param name="x">Input value.</param>
  2066. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2067. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2068. public static double4 round(double4 x) { return new double4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  2069. /// <summary>Returns the result of truncating a float value to an integral float value.</summary>
  2070. /// <param name="x">Input value.</param>
  2071. /// <returns>The truncation of the input.</returns>
  2072. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2073. public static float trunc(float x) { return (float)System.Math.Truncate((float)x); }
  2074. /// <summary>Returns the result of a componentwise truncation of a float2 value to an integral float2 value.</summary>
  2075. /// <param name="x">Input value.</param>
  2076. /// <returns>The componentwise truncation of the input.</returns>
  2077. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2078. public static float2 trunc(float2 x) { return new float2(trunc(x.x), trunc(x.y)); }
  2079. /// <summary>Returns the result of a componentwise truncation of a float3 value to an integral float3 value.</summary>
  2080. /// <param name="x">Input value.</param>
  2081. /// <returns>The componentwise truncation of the input.</returns>
  2082. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2083. public static float3 trunc(float3 x) { return new float3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  2084. /// <summary>Returns the result of a componentwise truncation of a float4 value to an integral float4 value.</summary>
  2085. /// <param name="x">Input value.</param>
  2086. /// <returns>The componentwise truncation of the input.</returns>
  2087. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2088. public static float4 trunc(float4 x) { return new float4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  2089. /// <summary>Returns the result of truncating a double value to an integral double value.</summary>
  2090. /// <param name="x">Input value.</param>
  2091. /// <returns>The truncation of the input.</returns>
  2092. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2093. public static double trunc(double x) { return System.Math.Truncate(x); }
  2094. /// <summary>Returns the result of a componentwise truncation of a double2 value to an integral double2 value.</summary>
  2095. /// <param name="x">Input value.</param>
  2096. /// <returns>The componentwise truncation of the input.</returns>
  2097. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2098. public static double2 trunc(double2 x) { return new double2(trunc(x.x), trunc(x.y)); }
  2099. /// <summary>Returns the result of a componentwise truncation of a double3 value to an integral double3 value.</summary>
  2100. /// <param name="x">Input value.</param>
  2101. /// <returns>The componentwise truncation of the input.</returns>
  2102. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2103. public static double3 trunc(double3 x) { return new double3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  2104. /// <summary>Returns the result of a componentwise truncation of a double4 value to an integral double4 value.</summary>
  2105. /// <param name="x">Input value.</param>
  2106. /// <returns>The componentwise truncation of the input.</returns>
  2107. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2108. public static double4 trunc(double4 x) { return new double4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  2109. /// <summary>Returns the fractional part of a float value.</summary>
  2110. /// <param name="x">Input value.</param>
  2111. /// <returns>The fractional part of the input.</returns>
  2112. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2113. public static float frac(float x) { return x - floor(x); }
  2114. /// <summary>Returns the componentwise fractional parts of a float2 vector.</summary>
  2115. /// <param name="x">Input value.</param>
  2116. /// <returns>The componentwise fractional part of the input.</returns>
  2117. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2118. public static float2 frac(float2 x) { return x - floor(x); }
  2119. /// <summary>Returns the componentwise fractional parts of a float3 vector.</summary>
  2120. /// <param name="x">Input value.</param>
  2121. /// <returns>The componentwise fractional part of the input.</returns>
  2122. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2123. public static float3 frac(float3 x) { return x - floor(x); }
  2124. /// <summary>Returns the componentwise fractional parts of a float4 vector.</summary>
  2125. /// <param name="x">Input value.</param>
  2126. /// <returns>The componentwise fractional part of the input.</returns>
  2127. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2128. public static float4 frac(float4 x) { return x - floor(x); }
  2129. /// <summary>Returns the fractional part of a double value.</summary>
  2130. /// <param name="x">Input value.</param>
  2131. /// <returns>The fractional part of the input.</returns>
  2132. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2133. public static double frac(double x) { return x - floor(x); }
  2134. /// <summary>Returns the componentwise fractional parts of a double2 vector.</summary>
  2135. /// <param name="x">Input value.</param>
  2136. /// <returns>The componentwise fractional part of the input.</returns>
  2137. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2138. public static double2 frac(double2 x) { return x - floor(x); }
  2139. /// <summary>Returns the componentwise fractional parts of a double3 vector.</summary>
  2140. /// <param name="x">Input value.</param>
  2141. /// <returns>The componentwise fractional part of the input.</returns>
  2142. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2143. public static double3 frac(double3 x) { return x - floor(x); }
  2144. /// <summary>Returns the componentwise fractional parts of a double4 vector.</summary>
  2145. /// <param name="x">Input value.</param>
  2146. /// <returns>The componentwise fractional part of the input.</returns>
  2147. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2148. public static double4 frac(double4 x) { return x - floor(x); }
  2149. /// <summary>Returns the reciprocal a float value.</summary>
  2150. /// <param name="x">Input value.</param>
  2151. /// <returns>The reciprocal of the input.</returns>
  2152. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2153. public static float rcp(float x) { return 1.0f / x; }
  2154. /// <summary>Returns the componentwise reciprocal a float2 vector.</summary>
  2155. /// <param name="x">Input value.</param>
  2156. /// <returns>The componentwise reciprocal of the input.</returns>
  2157. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2158. public static float2 rcp(float2 x) { return 1.0f / x; }
  2159. /// <summary>Returns the componentwise reciprocal a float3 vector.</summary>
  2160. /// <param name="x">Input value.</param>
  2161. /// <returns>The componentwise reciprocal of the input.</returns>
  2162. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2163. public static float3 rcp(float3 x) { return 1.0f / x; }
  2164. /// <summary>Returns the componentwise reciprocal a float4 vector.</summary>
  2165. /// <param name="x">Input value.</param>
  2166. /// <returns>The componentwise reciprocal of the input.</returns>
  2167. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2168. public static float4 rcp(float4 x) { return 1.0f / x; }
  2169. /// <summary>Returns the reciprocal a double value.</summary>
  2170. /// <param name="x">Input value.</param>
  2171. /// <returns>The reciprocal of the input.</returns>
  2172. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2173. public static double rcp(double x) { return 1.0 / x; }
  2174. /// <summary>Returns the componentwise reciprocal a double2 vector.</summary>
  2175. /// <param name="x">Input value.</param>
  2176. /// <returns>The componentwise reciprocal of the input.</returns>
  2177. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2178. public static double2 rcp(double2 x) { return 1.0 / x; }
  2179. /// <summary>Returns the componentwise reciprocal a double3 vector.</summary>
  2180. /// <param name="x">Input value.</param>
  2181. /// <returns>The componentwise reciprocal of the input.</returns>
  2182. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2183. public static double3 rcp(double3 x) { return 1.0 / x; }
  2184. /// <summary>Returns the componentwise reciprocal a double4 vector.</summary>
  2185. /// <param name="x">Input value.</param>
  2186. /// <returns>The componentwise reciprocal of the input.</returns>
  2187. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2188. public static double4 rcp(double4 x) { return 1.0 / x; }
  2189. /// <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>
  2190. /// <param name="x">Input value.</param>
  2191. /// <returns>The sign of the input.</returns>
  2192. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2193. public static float sign(float x) { return (x > 0.0f ? 1.0f : 0.0f) - (x < 0.0f ? 1.0f : 0.0f); }
  2194. /// <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>
  2195. /// <param name="x">Input value.</param>
  2196. /// <returns>The componentwise sign of the input.</returns>
  2197. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2198. public static float2 sign(float2 x) { return new float2(sign(x.x), sign(x.y)); }
  2199. /// <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>
  2200. /// <param name="x">Input value.</param>
  2201. /// <returns>The componentwise sign of the input.</returns>
  2202. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2203. public static float3 sign(float3 x) { return new float3(sign(x.x), sign(x.y), sign(x.z)); }
  2204. /// <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>
  2205. /// <param name="x">Input value.</param>
  2206. /// <returns>The componentwise sign of the input.</returns>
  2207. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2208. public static float4 sign(float4 x) { return new float4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  2209. /// <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>
  2210. /// <param name="x">Input value.</param>
  2211. /// <returns>The sign of the input.</returns>
  2212. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2213. public static double sign(double x) { return x == 0 ? 0 : (x > 0.0 ? 1.0 : 0.0) - (x < 0.0 ? 1.0 : 0.0); }
  2214. /// <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>
  2215. /// <param name="x">Input value.</param>
  2216. /// <returns>The componentwise sign of the input.</returns>
  2217. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2218. public static double2 sign(double2 x) { return new double2(sign(x.x), sign(x.y)); }
  2219. /// <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>
  2220. /// <param name="x">Input value.</param>
  2221. /// <returns>The componentwise sign of the input.</returns>
  2222. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2223. public static double3 sign(double3 x) { return new double3(sign(x.x), sign(x.y), sign(x.z)); }
  2224. /// <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>
  2225. /// <param name="x">Input value.</param>
  2226. /// <returns>The componentwise sign of the input.</returns>
  2227. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2228. public static double4 sign(double4 x) { return new double4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  2229. /// <summary>Returns x raised to the power y.</summary>
  2230. /// <param name="x">The exponent base.</param>
  2231. /// <param name="y">The exponent power.</param>
  2232. /// <returns>The result of raising x to the power y.</returns>
  2233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2234. public static float pow(float x, float y) { return (float)System.Math.Pow((float)x, (float)y); }
  2235. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2236. /// <param name="x">The exponent base.</param>
  2237. /// <param name="y">The exponent power.</param>
  2238. /// <returns>The componentwise result of raising x to the power y.</returns>
  2239. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2240. public static float2 pow(float2 x, float2 y) { return new float2(pow(x.x, y.x), pow(x.y, y.y)); }
  2241. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2242. /// <param name="x">The exponent base.</param>
  2243. /// <param name="y">The exponent power.</param>
  2244. /// <returns>The componentwise result of raising x to the power y.</returns>
  2245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2246. 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)); }
  2247. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2248. /// <param name="x">The exponent base.</param>
  2249. /// <param name="y">The exponent power.</param>
  2250. /// <returns>The componentwise result of raising x to the power y.</returns>
  2251. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2252. 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)); }
  2253. /// <summary>Returns x raised to the power y.</summary>
  2254. /// <param name="x">The exponent base.</param>
  2255. /// <param name="y">The exponent power.</param>
  2256. /// <returns>The result of raising x to the power y.</returns>
  2257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2258. public static double pow(double x, double y) { return System.Math.Pow(x, y); }
  2259. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2260. /// <param name="x">The exponent base.</param>
  2261. /// <param name="y">The exponent power.</param>
  2262. /// <returns>The componentwise result of raising x to the power y.</returns>
  2263. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2264. public static double2 pow(double2 x, double2 y) { return new double2(pow(x.x, y.x), pow(x.y, y.y)); }
  2265. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2266. /// <param name="x">The exponent base.</param>
  2267. /// <param name="y">The exponent power.</param>
  2268. /// <returns>The componentwise result of raising x to the power y.</returns>
  2269. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2270. 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)); }
  2271. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2272. /// <param name="x">The exponent base.</param>
  2273. /// <param name="y">The exponent power.</param>
  2274. /// <returns>The componentwise result of raising x to the power y.</returns>
  2275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2276. 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)); }
  2277. /// <summary>Returns the base-e exponential of x.</summary>
  2278. /// <param name="x">Input value.</param>
  2279. /// <returns>The base-e exponential of the input.</returns>
  2280. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2281. public static float exp(float x) { return (float)System.Math.Exp((float)x); }
  2282. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2283. /// <param name="x">Input value.</param>
  2284. /// <returns>The componentwise base-e exponential of the input.</returns>
  2285. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2286. public static float2 exp(float2 x) { return new float2(exp(x.x), exp(x.y)); }
  2287. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2288. /// <param name="x">Input value.</param>
  2289. /// <returns>The componentwise base-e exponential of the input.</returns>
  2290. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2291. public static float3 exp(float3 x) { return new float3(exp(x.x), exp(x.y), exp(x.z)); }
  2292. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2293. /// <param name="x">Input value.</param>
  2294. /// <returns>The componentwise base-e exponential of the input.</returns>
  2295. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2296. public static float4 exp(float4 x) { return new float4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  2297. /// <summary>Returns the base-e exponential of x.</summary>
  2298. /// <param name="x">Input value.</param>
  2299. /// <returns>The base-e exponential of the input.</returns>
  2300. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2301. public static double exp(double x) { return System.Math.Exp(x); }
  2302. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2303. /// <param name="x">Input value.</param>
  2304. /// <returns>The componentwise base-e exponential of the input.</returns>
  2305. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2306. public static double2 exp(double2 x) { return new double2(exp(x.x), exp(x.y)); }
  2307. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2308. /// <param name="x">Input value.</param>
  2309. /// <returns>The componentwise base-e exponential of the input.</returns>
  2310. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2311. public static double3 exp(double3 x) { return new double3(exp(x.x), exp(x.y), exp(x.z)); }
  2312. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2313. /// <param name="x">Input value.</param>
  2314. /// <returns>The componentwise base-e exponential of the input.</returns>
  2315. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2316. public static double4 exp(double4 x) { return new double4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  2317. /// <summary>Returns the base-2 exponential of x.</summary>
  2318. /// <param name="x">Input value.</param>
  2319. /// <returns>The base-2 exponential of the input.</returns>
  2320. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2321. public static float exp2(float x) { return (float)System.Math.Exp((float)x * 0.69314718f); }
  2322. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2323. /// <param name="x">Input value.</param>
  2324. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2325. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2326. public static float2 exp2(float2 x) { return new float2(exp2(x.x), exp2(x.y)); }
  2327. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2328. /// <param name="x">Input value.</param>
  2329. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2330. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2331. public static float3 exp2(float3 x) { return new float3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  2332. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2333. /// <param name="x">Input value.</param>
  2334. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2335. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2336. public static float4 exp2(float4 x) { return new float4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  2337. /// <summary>Returns the base-2 exponential of x.</summary>
  2338. /// <param name="x">Input value.</param>
  2339. /// <returns>The base-2 exponential of the input.</returns>
  2340. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2341. public static double exp2(double x) { return System.Math.Exp(x * 0.693147180559945309); }
  2342. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2343. /// <param name="x">Input value.</param>
  2344. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2345. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2346. public static double2 exp2(double2 x) { return new double2(exp2(x.x), exp2(x.y)); }
  2347. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2348. /// <param name="x">Input value.</param>
  2349. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2350. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2351. public static double3 exp2(double3 x) { return new double3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  2352. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2353. /// <param name="x">Input value.</param>
  2354. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2355. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2356. public static double4 exp2(double4 x) { return new double4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  2357. /// <summary>Returns the base-10 exponential of x.</summary>
  2358. /// <param name="x">Input value.</param>
  2359. /// <returns>The base-10 exponential of the input.</returns>
  2360. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2361. public static float exp10(float x) { return (float)System.Math.Exp((float)x * 2.30258509f); }
  2362. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2363. /// <param name="x">Input value.</param>
  2364. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2365. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2366. public static float2 exp10(float2 x) { return new float2(exp10(x.x), exp10(x.y)); }
  2367. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2368. /// <param name="x">Input value.</param>
  2369. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2370. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2371. public static float3 exp10(float3 x) { return new float3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  2372. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2373. /// <param name="x">Input value.</param>
  2374. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2375. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2376. public static float4 exp10(float4 x) { return new float4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  2377. /// <summary>Returns the base-10 exponential of x.</summary>
  2378. /// <param name="x">Input value.</param>
  2379. /// <returns>The base-10 exponential of the input.</returns>
  2380. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2381. public static double exp10(double x) { return System.Math.Exp(x * 2.302585092994045684); }
  2382. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2383. /// <param name="x">Input value.</param>
  2384. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2385. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2386. public static double2 exp10(double2 x) { return new double2(exp10(x.x), exp10(x.y)); }
  2387. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2388. /// <param name="x">Input value.</param>
  2389. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2390. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2391. public static double3 exp10(double3 x) { return new double3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  2392. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2393. /// <param name="x">Input value.</param>
  2394. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2395. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2396. public static double4 exp10(double4 x) { return new double4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  2397. /// <summary>Returns the natural logarithm of a float value.</summary>
  2398. /// <param name="x">Input value.</param>
  2399. /// <returns>The natural logarithm of the input.</returns>
  2400. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2401. public static float log(float x) { return (float)System.Math.Log((float)x); }
  2402. /// <summary>Returns the componentwise natural logarithm of a float2 vector.</summary>
  2403. /// <param name="x">Input value.</param>
  2404. /// <returns>The componentwise natural logarithm of the input.</returns>
  2405. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2406. public static float2 log(float2 x) { return new float2(log(x.x), log(x.y)); }
  2407. /// <summary>Returns the componentwise natural logarithm of a float3 vector.</summary>
  2408. /// <param name="x">Input value.</param>
  2409. /// <returns>The componentwise natural logarithm of the input.</returns>
  2410. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2411. public static float3 log(float3 x) { return new float3(log(x.x), log(x.y), log(x.z)); }
  2412. /// <summary>Returns the componentwise natural logarithm of a float4 vector.</summary>
  2413. /// <param name="x">Input value.</param>
  2414. /// <returns>The componentwise natural logarithm of the input.</returns>
  2415. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2416. public static float4 log(float4 x) { return new float4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  2417. /// <summary>Returns the natural logarithm of a double value.</summary>
  2418. /// <param name="x">Input value.</param>
  2419. /// <returns>The natural logarithm of the input.</returns>
  2420. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2421. public static double log(double x) { return System.Math.Log(x); }
  2422. /// <summary>Returns the componentwise natural logarithm of a double2 vector.</summary>
  2423. /// <param name="x">Input value.</param>
  2424. /// <returns>The componentwise natural logarithm of the input.</returns>
  2425. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2426. public static double2 log(double2 x) { return new double2(log(x.x), log(x.y)); }
  2427. /// <summary>Returns the componentwise natural logarithm of a double3 vector.</summary>
  2428. /// <param name="x">Input value.</param>
  2429. /// <returns>The componentwise natural logarithm of the input.</returns>
  2430. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2431. public static double3 log(double3 x) { return new double3(log(x.x), log(x.y), log(x.z)); }
  2432. /// <summary>Returns the componentwise natural logarithm of a double4 vector.</summary>
  2433. /// <param name="x">Input value.</param>
  2434. /// <returns>The componentwise natural logarithm of the input.</returns>
  2435. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2436. public static double4 log(double4 x) { return new double4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  2437. /// <summary>Returns the base-2 logarithm of a float value.</summary>
  2438. /// <param name="x">Input value.</param>
  2439. /// <returns>The base-2 logarithm of the input.</returns>
  2440. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2441. public static float log2(float x) { return (float)System.Math.Log((float)x, 2.0f); }
  2442. /// <summary>Returns the componentwise base-2 logarithm of a float2 vector.</summary>
  2443. /// <param name="x">Input value.</param>
  2444. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2445. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2446. public static float2 log2(float2 x) { return new float2(log2(x.x), log2(x.y)); }
  2447. /// <summary>Returns the componentwise base-2 logarithm of a float3 vector.</summary>
  2448. /// <param name="x">Input value.</param>
  2449. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2450. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2451. public static float3 log2(float3 x) { return new float3(log2(x.x), log2(x.y), log2(x.z)); }
  2452. /// <summary>Returns the componentwise base-2 logarithm of a float4 vector.</summary>
  2453. /// <param name="x">Input value.</param>
  2454. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2455. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2456. public static float4 log2(float4 x) { return new float4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  2457. /// <summary>Returns the base-2 logarithm of a double value.</summary>
  2458. /// <param name="x">Input value.</param>
  2459. /// <returns>The base-2 logarithm of the input.</returns>
  2460. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2461. public static double log2(double x) { return System.Math.Log(x, 2.0); }
  2462. /// <summary>Returns the componentwise base-2 logarithm of a double2 vector.</summary>
  2463. /// <param name="x">Input value.</param>
  2464. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2465. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2466. public static double2 log2(double2 x) { return new double2(log2(x.x), log2(x.y)); }
  2467. /// <summary>Returns the componentwise base-2 logarithm of a double3 vector.</summary>
  2468. /// <param name="x">Input value.</param>
  2469. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2470. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2471. public static double3 log2(double3 x) { return new double3(log2(x.x), log2(x.y), log2(x.z)); }
  2472. /// <summary>Returns the componentwise base-2 logarithm of a double4 vector.</summary>
  2473. /// <param name="x">Input value.</param>
  2474. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2475. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2476. public static double4 log2(double4 x) { return new double4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  2477. /// <summary>Returns the base-10 logarithm of a float value.</summary>
  2478. /// <param name="x">Input value.</param>
  2479. /// <returns>The base-10 logarithm of the input.</returns>
  2480. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2481. public static float log10(float x) { return (float)System.Math.Log10((float)x); }
  2482. /// <summary>Returns the componentwise base-10 logarithm of a float2 vector.</summary>
  2483. /// <param name="x">Input value.</param>
  2484. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2485. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2486. public static float2 log10(float2 x) { return new float2(log10(x.x), log10(x.y)); }
  2487. /// <summary>Returns the componentwise base-10 logarithm of a float3 vector.</summary>
  2488. /// <param name="x">Input value.</param>
  2489. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2490. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2491. public static float3 log10(float3 x) { return new float3(log10(x.x), log10(x.y), log10(x.z)); }
  2492. /// <summary>Returns the componentwise base-10 logarithm of a float4 vector.</summary>
  2493. /// <param name="x">Input value.</param>
  2494. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2495. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2496. public static float4 log10(float4 x) { return new float4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  2497. /// <summary>Returns the base-10 logarithm of a double value.</summary>
  2498. /// <param name="x">Input value.</param>
  2499. /// <returns>The base-10 logarithm of the input.</returns>
  2500. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2501. public static double log10(double x) { return System.Math.Log10(x); }
  2502. /// <summary>Returns the componentwise base-10 logarithm of a double2 vector.</summary>
  2503. /// <param name="x">Input value.</param>
  2504. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2505. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2506. public static double2 log10(double2 x) { return new double2(log10(x.x), log10(x.y)); }
  2507. /// <summary>Returns the componentwise base-10 logarithm of a double3 vector.</summary>
  2508. /// <param name="x">Input value.</param>
  2509. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2510. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2511. public static double3 log10(double3 x) { return new double3(log10(x.x), log10(x.y), log10(x.z)); }
  2512. /// <summary>Returns the componentwise base-10 logarithm of a double4 vector.</summary>
  2513. /// <param name="x">Input value.</param>
  2514. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2515. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2516. public static double4 log10(double4 x) { return new double4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  2517. /// <summary>Returns the floating point remainder of x/y.</summary>
  2518. /// <param name="x">The dividend in x/y.</param>
  2519. /// <param name="y">The divisor in x/y.</param>
  2520. /// <returns>The remainder of x/y.</returns>
  2521. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2522. public static float fmod(float x, float y) { return x % y; }
  2523. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2524. /// <param name="x">The dividend in x/y.</param>
  2525. /// <param name="y">The divisor in x/y.</param>
  2526. /// <returns>The componentwise remainder of x/y.</returns>
  2527. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2528. public static float2 fmod(float2 x, float2 y) { return new float2(x.x % y.x, x.y % y.y); }
  2529. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2530. /// <param name="x">The dividend in x/y.</param>
  2531. /// <param name="y">The divisor in x/y.</param>
  2532. /// <returns>The componentwise remainder of x/y.</returns>
  2533. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2534. public static float3 fmod(float3 x, float3 y) { return new float3(x.x % y.x, x.y % y.y, x.z % y.z); }
  2535. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2536. /// <param name="x">The dividend in x/y.</param>
  2537. /// <param name="y">The divisor in x/y.</param>
  2538. /// <returns>The componentwise remainder of x/y.</returns>
  2539. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2540. 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); }
  2541. /// <summary>Returns the double precision floating point remainder of x/y.</summary>
  2542. /// <param name="x">The dividend in x/y.</param>
  2543. /// <param name="y">The divisor in x/y.</param>
  2544. /// <returns>The remainder of x/y.</returns>
  2545. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2546. public static double fmod(double x, double y) { return x % y; }
  2547. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2548. /// <param name="x">The dividend in x/y.</param>
  2549. /// <param name="y">The divisor in x/y.</param>
  2550. /// <returns>The componentwise remainder of x/y.</returns>
  2551. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2552. public static double2 fmod(double2 x, double2 y) { return new double2(x.x % y.x, x.y % y.y); }
  2553. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2554. /// <param name="x">The dividend in x/y.</param>
  2555. /// <param name="y">The divisor in x/y.</param>
  2556. /// <returns>The componentwise remainder of x/y.</returns>
  2557. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2558. public static double3 fmod(double3 x, double3 y) { return new double3(x.x % y.x, x.y % y.y, x.z % y.z); }
  2559. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2560. /// <param name="x">The dividend in x/y.</param>
  2561. /// <param name="y">The divisor in x/y.</param>
  2562. /// <returns>The componentwise remainder of x/y.</returns>
  2563. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2564. 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); }
  2565. /// <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>
  2566. /// <param name="x">Value to split into integral and fractional part.</param>
  2567. /// <param name="i">Output value containing integral part of x.</param>
  2568. /// <returns>The fractional part of x.</returns>
  2569. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2570. public static float modf(float x, out float i) { i = trunc(x); return x - i; }
  2571. /// <summary>
  2572. /// Performs a componentwise split of a float2 vector into an integral part i and a fractional part that gets returned.
  2573. /// Both parts take the sign of the corresponding input component.
  2574. /// </summary>
  2575. /// <param name="x">Value to split into integral and fractional part.</param>
  2576. /// <param name="i">Output value containing integral part of x.</param>
  2577. /// <returns>The componentwise fractional part of x.</returns>
  2578. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2579. public static float2 modf(float2 x, out float2 i) { i = trunc(x); return x - i; }
  2580. /// <summary>
  2581. /// Performs a componentwise split of a float3 vector into an integral part i and a fractional part that gets returned.
  2582. /// Both parts take the sign of the corresponding input component.
  2583. /// </summary>
  2584. /// <param name="x">Value to split into integral and fractional part.</param>
  2585. /// <param name="i">Output value containing integral part of x.</param>
  2586. /// <returns>The componentwise fractional part of x.</returns>
  2587. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2588. public static float3 modf(float3 x, out float3 i) { i = trunc(x); return x - i; }
  2589. /// <summary>
  2590. /// Performs a componentwise split of a float4 vector into an integral part i and a fractional part that gets returned.
  2591. /// Both parts take the sign of the corresponding input component.
  2592. /// </summary>
  2593. /// <param name="x">Value to split into integral and fractional part.</param>
  2594. /// <param name="i">Output value containing integral part of x.</param>
  2595. /// <returns>The componentwise fractional part of x.</returns>
  2596. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2597. public static float4 modf(float4 x, out float4 i) { i = trunc(x); return x - i; }
  2598. /// <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>
  2599. /// <param name="x">Value to split into integral and fractional part.</param>
  2600. /// <param name="i">Output value containing integral part of x.</param>
  2601. /// <returns>The fractional part of x.</returns>
  2602. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2603. public static double modf(double x, out double i) { i = trunc(x); return x - i; }
  2604. /// <summary>
  2605. /// Performs a componentwise split of a double2 vector into an integral part i and a fractional part that gets returned.
  2606. /// Both parts take the sign of the corresponding input component.
  2607. /// </summary>
  2608. /// <param name="x">Value to split into integral and fractional part.</param>
  2609. /// <param name="i">Output value containing integral part of x.</param>
  2610. /// <returns>The componentwise fractional part of x.</returns>
  2611. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2612. public static double2 modf(double2 x, out double2 i) { i = trunc(x); return x - i; }
  2613. /// <summary>
  2614. /// Performs a componentwise split of a double3 vector into an integral part i and a fractional part that gets returned.
  2615. /// Both parts take the sign of the corresponding input component.
  2616. /// </summary>
  2617. /// <param name="x">Value to split into integral and fractional part.</param>
  2618. /// <param name="i">Output value containing integral part of x.</param>
  2619. /// <returns>The componentwise fractional part of x.</returns>
  2620. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2621. public static double3 modf(double3 x, out double3 i) { i = trunc(x); return x - i; }
  2622. /// <summary>
  2623. /// Performs a componentwise split of a double4 vector into an integral part i and a fractional part that gets returned.
  2624. /// Both parts take the sign of the corresponding input component.
  2625. /// </summary>
  2626. /// <param name="x">Value to split into integral and fractional part.</param>
  2627. /// <param name="i">Output value containing integral part of x.</param>
  2628. /// <returns>The componentwise fractional part of x.</returns>
  2629. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2630. public static double4 modf(double4 x, out double4 i) { i = trunc(x); return x - i; }
  2631. /// <summary>Returns the square root of a float value.</summary>
  2632. /// <param name="x">Value to use when computing square root.</param>
  2633. /// <returns>The square root.</returns>
  2634. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2635. public static float sqrt(float x) { return (float)System.Math.Sqrt((float)x); }
  2636. /// <summary>Returns the componentwise square root of a float2 vector.</summary>
  2637. /// <param name="x">Value to use when computing square root.</param>
  2638. /// <returns>The componentwise square root.</returns>
  2639. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2640. public static float2 sqrt(float2 x) { return new float2(sqrt(x.x), sqrt(x.y)); }
  2641. /// <summary>Returns the componentwise square root of a float3 vector.</summary>
  2642. /// <param name="x">Value to use when computing square root.</param>
  2643. /// <returns>The componentwise square root.</returns>
  2644. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2645. public static float3 sqrt(float3 x) { return new float3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  2646. /// <summary>Returns the componentwise square root of a float4 vector.</summary>
  2647. /// <param name="x">Value to use when computing square root.</param>
  2648. /// <returns>The componentwise square root.</returns>
  2649. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2650. public static float4 sqrt(float4 x) { return new float4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  2651. /// <summary>Returns the square root of a double value.</summary>
  2652. /// <param name="x">Value to use when computing square root.</param>
  2653. /// <returns>The square root.</returns>
  2654. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2655. public static double sqrt(double x) { return System.Math.Sqrt(x); }
  2656. /// <summary>Returns the componentwise square root of a double2 vector.</summary>
  2657. /// <param name="x">Value to use when computing square root.</param>
  2658. /// <returns>The componentwise square root.</returns>
  2659. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2660. public static double2 sqrt(double2 x) { return new double2(sqrt(x.x), sqrt(x.y)); }
  2661. /// <summary>Returns the componentwise square root of a double3 vector.</summary>
  2662. /// <param name="x">Value to use when computing square root.</param>
  2663. /// <returns>The componentwise square root.</returns>
  2664. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2665. public static double3 sqrt(double3 x) { return new double3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  2666. /// <summary>Returns the componentwise square root of a double4 vector.</summary>
  2667. /// <param name="x">Value to use when computing square root.</param>
  2668. /// <returns>The componentwise square root.</returns>
  2669. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2670. public static double4 sqrt(double4 x) { return new double4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  2671. /// <summary>Returns the reciprocal square root of a float value.</summary>
  2672. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2673. /// <returns>The reciprocal square root.</returns>
  2674. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2675. public static float rsqrt(float x) { return 1.0f / sqrt(x); }
  2676. /// <summary>Returns the componentwise reciprocal square root of a float2 vector.</summary>
  2677. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2678. /// <returns>The componentwise reciprocal square root.</returns>
  2679. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2680. public static float2 rsqrt(float2 x) { return 1.0f / sqrt(x); }
  2681. /// <summary>Returns the componentwise reciprocal square root of a float3 vector.</summary>
  2682. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2683. /// <returns>The componentwise reciprocal square root.</returns>
  2684. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2685. public static float3 rsqrt(float3 x) { return 1.0f / sqrt(x); }
  2686. /// <summary>Returns the componentwise reciprocal square root of a float4 vector</summary>
  2687. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2688. /// <returns>The componentwise reciprocal square root.</returns>
  2689. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2690. public static float4 rsqrt(float4 x) { return 1.0f / sqrt(x); }
  2691. /// <summary>Returns the reciprocal square root of a double value.</summary>
  2692. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2693. /// <returns>The reciprocal square root.</returns>
  2694. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2695. public static double rsqrt(double x) { return 1.0 / sqrt(x); }
  2696. /// <summary>Returns the componentwise reciprocal square root of a double2 vector.</summary>
  2697. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2698. /// <returns>The componentwise reciprocal square root.</returns>
  2699. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2700. public static double2 rsqrt(double2 x) { return 1.0 / sqrt(x); }
  2701. /// <summary>Returns the componentwise reciprocal square root of a double3 vector.</summary>
  2702. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2703. /// <returns>The componentwise reciprocal square root.</returns>
  2704. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2705. public static double3 rsqrt(double3 x) { return 1.0 / sqrt(x); }
  2706. /// <summary>Returns the componentwise reciprocal square root of a double4 vector.</summary>
  2707. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2708. /// <returns>The componentwise reciprocal square root.</returns>
  2709. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2710. public static double4 rsqrt(double4 x) { return 1.0 / sqrt(x); }
  2711. /// <summary>Returns a normalized version of the float2 vector x by scaling it by 1 / length(x).</summary>
  2712. /// <param name="x">Vector to normalize.</param>
  2713. /// <returns>The normalized vector.</returns>
  2714. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2715. public static float2 normalize(float2 x) { return rsqrt(dot(x, x)) * x; }
  2716. /// <summary>Returns a normalized version of the float3 vector x by scaling it by 1 / length(x).</summary>
  2717. /// <param name="x">Vector to normalize.</param>
  2718. /// <returns>The normalized vector.</returns>
  2719. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2720. public static float3 normalize(float3 x) { return rsqrt(dot(x, x)) * x; }
  2721. /// <summary>Returns a normalized version of the float4 vector x by scaling it by 1 / length(x).</summary>
  2722. /// <param name="x">Vector to normalize.</param>
  2723. /// <returns>The normalized vector.</returns>
  2724. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2725. public static float4 normalize(float4 x) { return rsqrt(dot(x, x)) * x; }
  2726. /// <summary>Returns a normalized version of the double2 vector x by scaling it by 1 / length(x).</summary>
  2727. /// <param name="x">Vector to normalize.</param>
  2728. /// <returns>The normalized vector.</returns>
  2729. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2730. public static double2 normalize(double2 x) { return rsqrt(dot(x, x)) * x; }
  2731. /// <summary>Returns a normalized version of the double3 vector x by scaling it by 1 / length(x).</summary>
  2732. /// <param name="x">Vector to normalize.</param>
  2733. /// <returns>The normalized vector.</returns>
  2734. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2735. public static double3 normalize(double3 x) { return rsqrt(dot(x, x)) * x; }
  2736. /// <summary>Returns a normalized version of the double4 vector x by scaling it by 1 / length(x).</summary>
  2737. /// <param name="x">Vector to normalize.</param>
  2738. /// <returns>The normalized vector.</returns>
  2739. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2740. public static double4 normalize(double4 x) { return rsqrt(dot(x, x)) * x; }
  2741. /// <summary>
  2742. /// Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x).
  2743. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2744. /// </summary>
  2745. /// <param name="x">Vector to normalize.</param>
  2746. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2747. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2748. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2749. static public float2 normalizesafe(float2 x, float2 defaultvalue = new float2())
  2750. {
  2751. float len = math.dot(x, x);
  2752. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2753. }
  2754. /// <summary>
  2755. /// Returns a safe normalized version of the float3 vector x by scaling it by 1 / length(x).
  2756. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2757. /// </summary>
  2758. /// <param name="x">Vector to normalize.</param>
  2759. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2760. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2761. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2762. static public float3 normalizesafe(float3 x, float3 defaultvalue = new float3())
  2763. {
  2764. float len = math.dot(x, x);
  2765. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2766. }
  2767. /// <summary>
  2768. /// Returns a safe normalized version of the float4 vector x by scaling it by 1 / length(x).
  2769. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2770. /// </summary>
  2771. /// <param name="x">Vector to normalize.</param>
  2772. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2773. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2774. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2775. static public float4 normalizesafe(float4 x, float4 defaultvalue = new float4())
  2776. {
  2777. float len = math.dot(x, x);
  2778. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2779. }
  2780. /// <summary>
  2781. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  2782. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2783. /// </summary>
  2784. /// <param name="x">Vector to normalize.</param>
  2785. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2786. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2787. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2788. static public double2 normalizesafe(double2 x, double2 defaultvalue = new double2())
  2789. {
  2790. double len = math.dot(x, x);
  2791. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2792. }
  2793. /// <summary>
  2794. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  2795. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2796. /// </summary>
  2797. /// <param name="x">Vector to normalize.</param>
  2798. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2799. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2800. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2801. static public double3 normalizesafe(double3 x, double3 defaultvalue = new double3())
  2802. {
  2803. double len = math.dot(x, x);
  2804. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2805. }
  2806. /// <summary>
  2807. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  2808. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2809. /// </summary>
  2810. /// <param name="x">Vector to normalize.</param>
  2811. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2812. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2813. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2814. static public double4 normalizesafe(double4 x, double4 defaultvalue = new double4())
  2815. {
  2816. double len = math.dot(x, x);
  2817. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2818. }
  2819. /// <summary>Returns the length of a float value. Equivalent to the absolute value.</summary>
  2820. /// <param name="x">Value to use when computing length.</param>
  2821. /// <returns>Length of x.</returns>
  2822. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2823. public static float length(float x) { return abs(x); }
  2824. /// <summary>Returns the length of a float2 vector.</summary>
  2825. /// <param name="x">Vector to use when computing length.</param>
  2826. /// <returns>Length of vector x.</returns>
  2827. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2828. public static float length(float2 x) { return sqrt(dot(x, x)); }
  2829. /// <summary>Returns the length of a float3 vector.</summary>
  2830. /// <param name="x">Vector to use when computing length.</param>
  2831. /// <returns>Length of vector x.</returns>
  2832. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2833. public static float length(float3 x) { return sqrt(dot(x, x)); }
  2834. /// <summary>Returns the length of a float4 vector.</summary>
  2835. /// <param name="x">Vector to use when computing length.</param>
  2836. /// <returns>Length of vector x.</returns>
  2837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2838. public static float length(float4 x) { return sqrt(dot(x, x)); }
  2839. /// <summary>Returns the length of a double value. Equivalent to the absolute value.</summary>
  2840. /// <param name="x">Value to use when computing squared length.</param>
  2841. /// <returns>Squared length of x.</returns>
  2842. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2843. public static double length(double x) { return abs(x); }
  2844. /// <summary>Returns the length of a double2 vector.</summary>
  2845. /// <param name="x">Vector to use when computing squared length.</param>
  2846. /// <returns>Squared length of vector x.</returns>
  2847. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2848. public static double length(double2 x) { return sqrt(dot(x, x)); }
  2849. /// <summary>Returns the length of a double3 vector.</summary>
  2850. /// <param name="x">Vector to use when computing squared length.</param>
  2851. /// <returns>Squared length of vector x.</returns>
  2852. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2853. public static double length(double3 x) { return sqrt(dot(x, x)); }
  2854. /// <summary>Returns the length of a double4 vector.</summary>
  2855. /// <param name="x">Vector to use when computing squared length.</param>
  2856. /// <returns>Squared length of vector x.</returns>
  2857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2858. public static double length(double4 x) { return sqrt(dot(x, x)); }
  2859. /// <summary>Returns the squared length of a float value. Equivalent to squaring the value.</summary>
  2860. /// <param name="x">Value to use when computing squared length.</param>
  2861. /// <returns>Squared length of x.</returns>
  2862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2863. public static float lengthsq(float x) { return x*x; }
  2864. /// <summary>Returns the squared length of a float2 vector.</summary>
  2865. /// <param name="x">Vector to use when computing squared length.</param>
  2866. /// <returns>Squared length of vector x.</returns>
  2867. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2868. public static float lengthsq(float2 x) { return dot(x, x); }
  2869. /// <summary>Returns the squared length of a float3 vector.</summary>
  2870. /// <param name="x">Vector to use when computing squared length.</param>
  2871. /// <returns>Squared length of vector x.</returns>
  2872. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2873. public static float lengthsq(float3 x) { return dot(x, x); }
  2874. /// <summary>Returns the squared length of a float4 vector.</summary>
  2875. /// <param name="x">Vector to use when computing squared length.</param>
  2876. /// <returns>Squared length of vector x.</returns>
  2877. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2878. public static float lengthsq(float4 x) { return dot(x, x); }
  2879. /// <summary>Returns the squared length of a double value. Equivalent to squaring the value.</summary>
  2880. /// <param name="x">Value to use when computing squared length.</param>
  2881. /// <returns>Squared length of x.</returns>
  2882. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2883. public static double lengthsq(double x) { return x * x; }
  2884. /// <summary>Returns the squared length of a double2 vector.</summary>
  2885. /// <param name="x">Vector to use when computing squared length.</param>
  2886. /// <returns>Squared length of vector x.</returns>
  2887. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2888. public static double lengthsq(double2 x) { return dot(x, x); }
  2889. /// <summary>Returns the squared length of a double3 vector.</summary>
  2890. /// <param name="x">Vector to use when computing squared length.</param>
  2891. /// <returns>Squared length of vector x.</returns>
  2892. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2893. public static double lengthsq(double3 x) { return dot(x, x); }
  2894. /// <summary>Returns the squared length of a double4 vector.</summary>
  2895. /// <param name="x">Vector to use when computing squared length.</param>
  2896. /// <returns>Squared length of vector x.</returns>
  2897. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2898. public static double lengthsq(double4 x) { return dot(x, x); }
  2899. /// <summary>Returns the distance between two float values.</summary>
  2900. /// <param name="x">First value to use in distance computation.</param>
  2901. /// <param name="y">Second value to use in distance computation.</param>
  2902. /// <returns>The distance between x and y.</returns>
  2903. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2904. public static float distance(float x, float y) { return abs(y - x); }
  2905. /// <summary>Returns the distance between two float2 vectors.</summary>
  2906. /// <param name="x">First vector to use in distance computation.</param>
  2907. /// <param name="y">Second vector to use in distance computation.</param>
  2908. /// <returns>The distance between x and y.</returns>
  2909. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2910. public static float distance(float2 x, float2 y) { return length(y - x); }
  2911. /// <summary>Returns the distance between two float3 vectors.</summary>
  2912. /// <param name="x">First vector to use in distance computation.</param>
  2913. /// <param name="y">Second vector to use in distance computation.</param>
  2914. /// <returns>The distance between x and y.</returns>
  2915. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2916. public static float distance(float3 x, float3 y) { return length(y - x); }
  2917. /// <summary>Returns the distance between two float4 vectors.</summary>
  2918. /// <param name="x">First vector to use in distance computation.</param>
  2919. /// <param name="y">Second vector to use in distance computation.</param>
  2920. /// <returns>The distance between x and y.</returns>
  2921. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2922. public static float distance(float4 x, float4 y) { return length(y - x); }
  2923. /// <summary>Returns the distance between two double values.</summary>
  2924. /// <param name="x">First value to use in distance computation.</param>
  2925. /// <param name="y">Second value to use in distance computation.</param>
  2926. /// <returns>The distance between x and y.</returns>
  2927. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2928. public static double distance(double x, double y) { return abs(y - x); }
  2929. /// <summary>Returns the distance between two double2 vectors.</summary>
  2930. /// <param name="x">First vector to use in distance computation.</param>
  2931. /// <param name="y">Second vector to use in distance computation.</param>
  2932. /// <returns>The distance between x and y.</returns>
  2933. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2934. public static double distance(double2 x, double2 y) { return length(y - x); }
  2935. /// <summary>Returns the distance between two double3 vectors.</summary>
  2936. /// <param name="x">First vector to use in distance computation.</param>
  2937. /// <param name="y">Second vector to use in distance computation.</param>
  2938. /// <returns>The distance between x and y.</returns>
  2939. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2940. public static double distance(double3 x, double3 y) { return length(y - x); }
  2941. /// <summary>Returns the distance between two double4 vectors.</summary>
  2942. /// <param name="x">First vector to use in distance computation.</param>
  2943. /// <param name="y">Second vector to use in distance computation.</param>
  2944. /// <returns>The distance between x and y.</returns>
  2945. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2946. public static double distance(double4 x, double4 y) { return length(y - x); }
  2947. /// <summary>Returns the squared distance between two float values.</summary>
  2948. /// <param name="x">First value to use in distance computation.</param>
  2949. /// <param name="y">Second value to use in distance computation.</param>
  2950. /// <returns>The squared distance between x and y.</returns>
  2951. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2952. public static float distancesq(float x, float y) { return (y - x) * (y - x); }
  2953. /// <summary>Returns the squared distance between two float2 vectors.</summary>
  2954. /// <param name="x">First vector to use in distance computation.</param>
  2955. /// <param name="y">Second vector to use in distance computation.</param>
  2956. /// <returns>The squared distance between x and y.</returns>
  2957. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2958. public static float distancesq(float2 x, float2 y) { return lengthsq(y - x); }
  2959. /// <summary>Returns the squared distance between two float3 vectors.</summary>
  2960. /// <param name="x">First vector to use in distance computation.</param>
  2961. /// <param name="y">Second vector to use in distance computation.</param>
  2962. /// <returns>The squared distance between x and y.</returns>
  2963. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2964. public static float distancesq(float3 x, float3 y) { return lengthsq(y - x); }
  2965. /// <summary>Returns the squared distance between two float4 vectors.</summary>
  2966. /// <param name="x">First vector to use in distance computation.</param>
  2967. /// <param name="y">Second vector to use in distance computation.</param>
  2968. /// <returns>The squared distance between x and y.</returns>
  2969. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2970. public static float distancesq(float4 x, float4 y) { return lengthsq(y - x); }
  2971. /// <summary>Returns the squared distance between two double values.</summary>
  2972. /// <param name="x">First value to use in distance computation.</param>
  2973. /// <param name="y">Second value to use in distance computation.</param>
  2974. /// <returns>The squared distance between x and y.</returns>
  2975. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2976. public static double distancesq(double x, double y) { return (y - x) * (y - x); }
  2977. /// <summary>Returns the squared distance between two double2 vectors.</summary>
  2978. /// <param name="x">First vector to use in distance computation.</param>
  2979. /// <param name="y">Second vector to use in distance computation.</param>
  2980. /// <returns>The squared distance between x and y.</returns>
  2981. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2982. public static double distancesq(double2 x, double2 y) { return lengthsq(y - x); }
  2983. /// <summary>Returns the squared distance between two double3 vectors.</summary>
  2984. /// <param name="x">First vector to use in distance computation.</param>
  2985. /// <param name="y">Second vector to use in distance computation.</param>
  2986. /// <returns>The squared distance between x and y.</returns>
  2987. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2988. public static double distancesq(double3 x, double3 y) { return lengthsq(y - x); }
  2989. /// <summary>Returns the squared distance between two double4 vectors.</summary>
  2990. /// <param name="x">First vector to use in distance computation.</param>
  2991. /// <param name="y">Second vector to use in distance computation.</param>
  2992. /// <returns>The squared distance between x and y.</returns>
  2993. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2994. public static double distancesq(double4 x, double4 y) { return lengthsq(y - x); }
  2995. /// <summary>Returns the cross product of two float3 vectors.</summary>
  2996. /// <param name="x">First vector to use in cross product.</param>
  2997. /// <param name="y">Second vector to use in cross product.</param>
  2998. /// <returns>The cross product of x and y.</returns>
  2999. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3000. public static float3 cross(float3 x, float3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  3001. /// <summary>Returns the cross product of two double3 vectors.</summary>
  3002. /// <param name="x">First vector to use in cross product.</param>
  3003. /// <param name="y">Second vector to use in cross product.</param>
  3004. /// <returns>The cross product of x and y.</returns>
  3005. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3006. public static double3 cross(double3 x, double3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  3007. /// <summary>Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  3008. /// <param name="a">The minimum range of the x parameter.</param>
  3009. /// <param name="b">The maximum range of the x parameter.</param>
  3010. /// <param name="x">The value to be interpolated.</param>
  3011. /// <returns>Returns a value camped to the range [0, 1].</returns>
  3012. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3013. public static float smoothstep(float a, float b, float x)
  3014. {
  3015. var t = saturate((x - a) / (b - a));
  3016. return t * t * (3.0f - (2.0f * t));
  3017. }
  3018. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  3019. /// <param name="a">The minimum range of the x parameter.</param>
  3020. /// <param name="b">The maximum range of the x parameter.</param>
  3021. /// <param name="x">The value to be interpolated.</param>
  3022. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3023. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3024. public static float2 smoothstep(float2 a, float2 b, float2 x)
  3025. {
  3026. var t = saturate((x - a) / (b - a));
  3027. return t * t * (3.0f - (2.0f * t));
  3028. }
  3029. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  3030. /// <param name="a">The minimum range of the x parameter.</param>
  3031. /// <param name="b">The maximum range of the x parameter.</param>
  3032. /// <param name="x">The value to be interpolated.</param>
  3033. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3034. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3035. public static float3 smoothstep(float3 a, float3 b, float3 x)
  3036. {
  3037. var t = saturate((x - a) / (b - a));
  3038. return t * t * (3.0f - (2.0f * t));
  3039. }
  3040. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b].</summary>
  3041. /// <param name="a">The minimum range of the x parameter.</param>
  3042. /// <param name="b">The maximum range of the x parameter.</param>
  3043. /// <param name="x">The value to be interpolated.</param>
  3044. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3045. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3046. public static float4 smoothstep(float4 a, float4 b, float4 x)
  3047. {
  3048. var t = saturate((x - a) / (b - a));
  3049. return t * t * (3.0f - (2.0f * t));
  3050. }
  3051. /// <summary>Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  3052. /// <param name="a">The minimum range of the x parameter.</param>
  3053. /// <param name="b">The maximum range of the x parameter.</param>
  3054. /// <param name="x">The value to be interpolated.</param>
  3055. /// <returns>Returns a value camped to the range [0, 1].</returns>
  3056. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3057. public static double smoothstep(double a, double b, double x)
  3058. {
  3059. var t = saturate((x - a) / (b - a));
  3060. return t * t * (3.0 - (2.0 * t));
  3061. }
  3062. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  3063. /// <param name="a">The minimum range of the x parameter.</param>
  3064. /// <param name="b">The maximum range of the x parameter.</param>
  3065. /// <param name="x">The value to be interpolated.</param>
  3066. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3067. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3068. public static double2 smoothstep(double2 a, double2 b, double2 x)
  3069. {
  3070. var t = saturate((x - a) / (b - a));
  3071. return t * t * (3.0 - (2.0 * t));
  3072. }
  3073. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  3074. /// <param name="a">The minimum range of the x parameter.</param>
  3075. /// <param name="b">The maximum range of the x parameter.</param>
  3076. /// <param name="x">The value to be interpolated.</param>
  3077. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3078. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3079. public static double3 smoothstep(double3 a, double3 b, double3 x)
  3080. {
  3081. var t = saturate((x - a) / (b - a));
  3082. return t * t * (3.0 - (2.0 * t));
  3083. }
  3084. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b].</summary>
  3085. /// <param name="a">The minimum range of the x parameter.</param>
  3086. /// <param name="b">The maximum range of the x parameter.</param>
  3087. /// <param name="x">The value to be interpolated.</param>
  3088. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3089. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3090. public static double4 smoothstep(double4 a, double4 b, double4 x)
  3091. {
  3092. var t = saturate((x - a) / (b - a));
  3093. return t * t * (3.0 - (2.0 * t));
  3094. }
  3095. /// <summary>Returns true if any component of the input bool2 vector is true, false otherwise.</summary>
  3096. /// <param name="x">Vector of values to compare.</param>
  3097. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3098. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3099. public static bool any(bool2 x) { return x.x || x.y; }
  3100. /// <summary>Returns true if any component of the input bool3 vector is true, false otherwise.</summary>
  3101. /// <param name="x">Vector of values to compare.</param>
  3102. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3103. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3104. public static bool any(bool3 x) { return x.x || x.y || x.z; }
  3105. /// <summary>Returns true if any components of the input bool4 vector is true, false otherwise.</summary>
  3106. /// <param name="x">Vector of values to compare.</param>
  3107. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3108. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3109. public static bool any(bool4 x) { return x.x || x.y || x.z || x.w; }
  3110. /// <summary>Returns true if any component of the input int2 vector is non-zero, false otherwise.</summary>
  3111. /// <param name="x">Vector of values to compare.</param>
  3112. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3113. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3114. public static bool any(int2 x) { return x.x != 0 || x.y != 0; }
  3115. /// <summary>Returns true if any component of the input int3 vector is non-zero, false otherwise.</summary>
  3116. /// <param name="x">Vector of values to compare.</param>
  3117. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3118. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3119. public static bool any(int3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  3120. /// <summary>Returns true if any components of the input int4 vector is non-zero, false otherwise.</summary>
  3121. /// <param name="x">Vector of values to compare.</param>
  3122. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3123. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3124. public static bool any(int4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  3125. /// <summary>Returns true if any component of the input uint2 vector is non-zero, false otherwise.</summary>
  3126. /// <param name="x">Vector of values to compare.</param>
  3127. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3128. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3129. public static bool any(uint2 x) { return x.x != 0 || x.y != 0; }
  3130. /// <summary>Returns true if any component of the input uint3 vector is non-zero, false otherwise.</summary>
  3131. /// <param name="x">Vector of values to compare.</param>
  3132. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3133. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3134. public static bool any(uint3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  3135. /// <summary>Returns true if any components of the input uint4 vector is non-zero, false otherwise.</summary>
  3136. /// <param name="x">Vector of values to compare.</param>
  3137. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3138. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3139. public static bool any(uint4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  3140. /// <summary>Returns true if any component of the input float2 vector is non-zero, false otherwise.</summary>
  3141. /// <param name="x">Vector of values to compare.</param>
  3142. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3143. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3144. public static bool any(float2 x) { return x.x != 0.0f || x.y != 0.0f; }
  3145. /// <summary>Returns true if any component of the input float3 vector is non-zero, false otherwise.</summary>
  3146. /// <param name="x">Vector of values to compare.</param>
  3147. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3148. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3149. public static bool any(float3 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f; }
  3150. /// <summary>Returns true if any component of the input float4 vector is non-zero, false otherwise.</summary>
  3151. /// <param name="x">Vector of values to compare.</param>
  3152. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3153. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3154. public static bool any(float4 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f || x.w != 0.0f; }
  3155. /// <summary>Returns true if any component of the input double2 vector is non-zero, false otherwise.</summary>
  3156. /// <param name="x">Vector of values to compare.</param>
  3157. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3158. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3159. public static bool any(double2 x) { return x.x != 0.0 || x.y != 0.0; }
  3160. /// <summary>Returns true if any component of the input double3 vector is non-zero, false otherwise.</summary>
  3161. /// <param name="x">Vector of values to compare.</param>
  3162. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3163. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3164. public static bool any(double3 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0; }
  3165. /// <summary>Returns true if any component of the input double4 vector is non-zero, false otherwise.</summary>
  3166. /// <param name="x">Vector of values to compare.</param>
  3167. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3168. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3169. public static bool any(double4 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0 || x.w != 0.0; }
  3170. /// <summary>Returns true if all components of the input bool2 vector are true, false otherwise.</summary>
  3171. /// <param name="x">Vector of values to compare.</param>
  3172. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3173. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3174. public static bool all(bool2 x) { return x.x && x.y; }
  3175. /// <summary>Returns true if all components of the input bool3 vector are true, false otherwise.</summary>
  3176. /// <param name="x">Vector of values to compare.</param>
  3177. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3178. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3179. public static bool all(bool3 x) { return x.x && x.y && x.z; }
  3180. /// <summary>Returns true if all components of the input bool4 vector are true, false otherwise.</summary>
  3181. /// <param name="x">Vector of values to compare.</param>
  3182. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3183. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3184. public static bool all(bool4 x) { return x.x && x.y && x.z && x.w; }
  3185. /// <summary>Returns true if all components of the input int2 vector are non-zero, false otherwise.</summary>
  3186. /// <param name="x">Vector of values to compare.</param>
  3187. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3188. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3189. public static bool all(int2 x) { return x.x != 0 && x.y != 0; }
  3190. /// <summary>Returns true if all components of the input int3 vector are non-zero, false otherwise.</summary>
  3191. /// <param name="x">Vector of values to compare.</param>
  3192. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3193. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3194. public static bool all(int3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  3195. /// <summary>Returns true if all components of the input int4 vector are non-zero, false otherwise.</summary>
  3196. /// <param name="x">Vector of values to compare.</param>
  3197. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3198. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3199. public static bool all(int4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  3200. /// <summary>Returns true if all components of the input uint2 vector are non-zero, false otherwise.</summary>
  3201. /// <param name="x">Vector of values to compare.</param>
  3202. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3203. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3204. public static bool all(uint2 x) { return x.x != 0 && x.y != 0; }
  3205. /// <summary>Returns true if all components of the input uint3 vector are non-zero, false otherwise.</summary>
  3206. /// <param name="x">Vector of values to compare.</param>
  3207. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3208. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3209. public static bool all(uint3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  3210. /// <summary>Returns true if all components of the input uint4 vector are non-zero, false otherwise.</summary>
  3211. /// <param name="x">Vector of values to compare.</param>
  3212. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3213. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3214. public static bool all(uint4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  3215. /// <summary>Returns true if all components of the input float2 vector are non-zero, false otherwise.</summary>
  3216. /// <param name="x">Vector of values to compare.</param>
  3217. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3218. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3219. public static bool all(float2 x) { return x.x != 0.0f && x.y != 0.0f; }
  3220. /// <summary>Returns true if all components of the input float3 vector are non-zero, false otherwise.</summary>
  3221. /// <param name="x">Vector of values to compare.</param>
  3222. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3223. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3224. public static bool all(float3 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f; }
  3225. /// <summary>Returns true if all components of the input float4 vector are non-zero, false otherwise.</summary>
  3226. /// <param name="x">Vector of values to compare.</param>
  3227. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3228. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3229. public static bool all(float4 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f && x.w != 0.0f; }
  3230. /// <summary>Returns true if all components of the input double2 vector are non-zero, false otherwise.</summary>
  3231. /// <param name="x">Vector of values to compare.</param>
  3232. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3233. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3234. public static bool all(double2 x) { return x.x != 0.0 && x.y != 0.0; }
  3235. /// <summary>Returns true if all components of the input double3 vector are non-zero, false otherwise.</summary>
  3236. /// <param name="x">Vector of values to compare.</param>
  3237. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3238. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3239. public static bool all(double3 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0; }
  3240. /// <summary>Returns true if all components of the input double4 vector are non-zero, false otherwise.</summary>
  3241. /// <param name="x">Vector of values to compare.</param>
  3242. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3243. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3244. public static bool all(double4 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0 && x.w != 0.0; }
  3245. /// <summary>Returns b if c is true, a otherwise.</summary>
  3246. /// <param name="a">Value to use if c is false.</param>
  3247. /// <param name="b">Value to use if c is true.</param>
  3248. /// <param name="c">Bool value to choose between a and b.</param>
  3249. /// <returns>The selection between a and b according to bool c.</returns>
  3250. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3251. public static int select(int a, int b, bool c) { return c ? b : a; }
  3252. /// <summary>Returns b if c is true, a otherwise.</summary>
  3253. /// <param name="a">Value to use if c is false.</param>
  3254. /// <param name="b">Value to use if c is true.</param>
  3255. /// <param name="c">Bool value to choose between a and b.</param>
  3256. /// <returns>The selection between a and b according to bool c.</returns>
  3257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3258. public static int2 select(int2 a, int2 b, bool c) { return c ? b : a; }
  3259. /// <summary>Returns b if c is true, a otherwise.</summary>
  3260. /// <param name="a">Value to use if c is false.</param>
  3261. /// <param name="b">Value to use if c is true.</param>
  3262. /// <param name="c">Bool value to choose between a and b.</param>
  3263. /// <returns>The selection between a and b according to bool c.</returns>
  3264. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3265. public static int3 select(int3 a, int3 b, bool c) { return c ? b : a; }
  3266. /// <summary>Returns b if c is true, a otherwise.</summary>
  3267. /// <param name="a">Value to use if c is false.</param>
  3268. /// <param name="b">Value to use if c is true.</param>
  3269. /// <param name="c">Bool value to choose between a and b.</param>
  3270. /// <returns>The selection between a and b according to bool c.</returns>
  3271. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3272. public static int4 select(int4 a, int4 b, bool c) { return c ? b : a; }
  3273. /// <summary>
  3274. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3275. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3276. /// </summary>
  3277. /// <param name="a">Values to use if c is false.</param>
  3278. /// <param name="b">Values to use if c is true.</param>
  3279. /// <param name="c">Selection mask to choose between a and b.</param>
  3280. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3281. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3282. 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); }
  3283. /// <summary>
  3284. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3285. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3286. /// </summary>
  3287. /// <param name="a">Values to use if c is false.</param>
  3288. /// <param name="b">Values to use if c is true.</param>
  3289. /// <param name="c">Selection mask to choose between a and b.</param>
  3290. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3291. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3292. 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); }
  3293. /// <summary>
  3294. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3295. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3296. /// </summary>
  3297. /// <param name="a">Values to use if c is false.</param>
  3298. /// <param name="b">Values to use if c is true.</param>
  3299. /// <param name="c">Selection mask to choose between a and b.</param>
  3300. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3301. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3302. 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); }
  3303. /// <summary>Returns b if c is true, a otherwise.</summary>
  3304. /// <param name="a">Value to use if c is false.</param>
  3305. /// <param name="b">Value to use if c is true.</param>
  3306. /// <param name="c">Bool value to choose between a and b.</param>
  3307. /// <returns>The selection between a and b according to bool c.</returns>
  3308. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3309. public static uint select(uint a, uint b, bool c) { return c ? b : a; }
  3310. /// <summary>Returns b if c is true, a otherwise.</summary>
  3311. /// <param name="a">Value to use if c is false.</param>
  3312. /// <param name="b">Value to use if c is true.</param>
  3313. /// <param name="c">Bool value to choose between a and b.</param>
  3314. /// <returns>The selection between a and b according to bool c.</returns>
  3315. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3316. public static uint2 select(uint2 a, uint2 b, bool c) { return c ? b : a; }
  3317. /// <summary>Returns b if c is true, a otherwise.</summary>
  3318. /// <param name="a">Value to use if c is false.</param>
  3319. /// <param name="b">Value to use if c is true.</param>
  3320. /// <param name="c">Bool value to choose between a and b.</param>
  3321. /// <returns>The selection between a and b according to bool c.</returns>
  3322. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3323. public static uint3 select(uint3 a, uint3 b, bool c) { return c ? b : a; }
  3324. /// <summary>Returns b if c is true, a otherwise.</summary>
  3325. /// <param name="a">Value to use if c is false.</param>
  3326. /// <param name="b">Value to use if c is true.</param>
  3327. /// <param name="c">Bool value to choose between a and b.</param>
  3328. /// <returns>The selection between a and b according to bool c.</returns>
  3329. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3330. public static uint4 select(uint4 a, uint4 b, bool c) { return c ? b : a; }
  3331. /// <summary>
  3332. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3333. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3334. /// </summary>
  3335. /// <param name="a">Values to use if c is false.</param>
  3336. /// <param name="b">Values to use if c is true.</param>
  3337. /// <param name="c">Selection mask to choose between a and b.</param>
  3338. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3339. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3340. 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); }
  3341. /// <summary>
  3342. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3343. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3344. /// </summary>
  3345. /// <param name="a">Values to use if c is false.</param>
  3346. /// <param name="b">Values to use if c is true.</param>
  3347. /// <param name="c">Selection mask to choose between a and b.</param>
  3348. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3349. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3350. 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); }
  3351. /// <summary>
  3352. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3353. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3354. /// </summary>
  3355. /// <param name="a">Values to use if c is false.</param>
  3356. /// <param name="b">Values to use if c is true.</param>
  3357. /// <param name="c">Selection mask to choose between a and b.</param>
  3358. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3359. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3360. 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); }
  3361. /// <summary>Returns b if c is true, a otherwise.</summary>
  3362. /// <param name="a">Value to use if c is false.</param>
  3363. /// <param name="b">Value to use if c is true.</param>
  3364. /// <param name="c">Bool value to choose between a and b.</param>
  3365. /// <returns>The selection between a and b according to bool c.</returns>
  3366. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3367. public static long select(long a, long b, bool c) { return c ? b : a; }
  3368. /// <summary>Returns b if c is true, a otherwise.</summary>
  3369. /// <param name="a">Value to use if c is false.</param>
  3370. /// <param name="b">Value to use if c is true.</param>
  3371. /// <param name="c">Bool value to choose between a and b.</param>
  3372. /// <returns>The selection between a and b according to bool c.</returns>
  3373. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3374. public static ulong select(ulong a, ulong b, bool c) { return c ? b : a; }
  3375. /// <summary>Returns b if c is true, a otherwise.</summary>
  3376. /// <param name="a">Value to use if c is false.</param>
  3377. /// <param name="b">Value to use if c is true.</param>
  3378. /// <param name="c">Bool value to choose between a and b.</param>
  3379. /// <returns>The selection between a and b according to bool c.</returns>
  3380. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3381. public static float select(float a, float b, bool c) { return c ? b : a; }
  3382. /// <summary>Returns b if c is true, a otherwise.</summary>
  3383. /// <param name="a">Value to use if c is false.</param>
  3384. /// <param name="b">Value to use if c is true.</param>
  3385. /// <param name="c">Bool value to choose between a and b.</param>
  3386. /// <returns>The selection between a and b according to bool c.</returns>
  3387. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3388. public static float2 select(float2 a, float2 b, bool c) { return c ? b : a; }
  3389. /// <summary>Returns b if c is true, a otherwise.</summary>
  3390. /// <param name="a">Value to use if c is false.</param>
  3391. /// <param name="b">Value to use if c is true.</param>
  3392. /// <param name="c">Bool value to choose between a and b.</param>
  3393. /// <returns>The selection between a and b according to bool c.</returns>
  3394. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3395. public static float3 select(float3 a, float3 b, bool c) { return c ? b : a; }
  3396. /// <summary>Returns b if c is true, a otherwise.</summary>
  3397. /// <param name="a">Value to use if c is false.</param>
  3398. /// <param name="b">Value to use if c is true.</param>
  3399. /// <param name="c">Bool value to choose between a and b.</param>
  3400. /// <returns>The selection between a and b according to bool c.</returns>
  3401. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3402. public static float4 select(float4 a, float4 b, bool c) { return c ? b : a; }
  3403. /// <summary>
  3404. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3405. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3406. /// </summary>
  3407. /// <param name="a">Values to use if c is false.</param>
  3408. /// <param name="b">Values to use if c is true.</param>
  3409. /// <param name="c">Selection mask to choose between a and b.</param>
  3410. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3411. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3412. 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); }
  3413. /// <summary>
  3414. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3415. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3416. /// </summary>
  3417. /// <param name="a">Values to use if c is false.</param>
  3418. /// <param name="b">Values to use if c is true.</param>
  3419. /// <param name="c">Selection mask to choose between a and b.</param>
  3420. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3421. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3422. 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); }
  3423. /// <summary>
  3424. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3425. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3426. /// </summary>
  3427. /// <param name="a">Values to use if c is false.</param>
  3428. /// <param name="b">Values to use if c is true.</param>
  3429. /// <param name="c">Selection mask to choose between a and b.</param>
  3430. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3431. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3432. 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); }
  3433. /// <summary>Returns b if c is true, a otherwise.</summary>
  3434. /// <param name="a">Value to use if c is false.</param>
  3435. /// <param name="b">Value to use if c is true.</param>
  3436. /// <param name="c">Bool value to choose between a and b.</param>
  3437. /// <returns>The selection between a and b according to bool c.</returns>
  3438. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3439. public static double select(double a, double b, bool c) { return c ? b : a; }
  3440. /// <summary>Returns b if c is true, a otherwise.</summary>
  3441. /// <param name="a">Value to use if c is false.</param>
  3442. /// <param name="b">Value to use if c is true.</param>
  3443. /// <param name="c">Bool value to choose between a and b.</param>
  3444. /// <returns>The selection between a and b according to bool c.</returns>
  3445. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3446. public static double2 select(double2 a, double2 b, bool c) { return c ? b : a; }
  3447. /// <summary>Returns b if c is true, a otherwise.</summary>
  3448. /// <param name="a">Value to use if c is false.</param>
  3449. /// <param name="b">Value to use if c is true.</param>
  3450. /// <param name="c">Bool value to choose between a and b.</param>
  3451. /// <returns>The selection between a and b according to bool c.</returns>
  3452. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3453. public static double3 select(double3 a, double3 b, bool c) { return c ? b : a; }
  3454. /// <summary>Returns b if c is true, a otherwise.</summary>
  3455. /// <param name="a">Value to use if c is false.</param>
  3456. /// <param name="b">Value to use if c is true.</param>
  3457. /// <param name="c">Bool value to choose between a and b.</param>
  3458. /// <returns>The selection between a and b according to bool c.</returns>
  3459. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3460. public static double4 select(double4 a, double4 b, bool c) { return c ? b : a; }
  3461. /// <summary>
  3462. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3463. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3464. /// </summary>
  3465. /// <param name="a">Values to use if c is false.</param>
  3466. /// <param name="b">Values to use if c is true.</param>
  3467. /// <param name="c">Selection mask to choose between a and b.</param>
  3468. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3469. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3470. 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); }
  3471. /// <summary>
  3472. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3473. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3474. /// </summary>
  3475. /// <param name="a">Values to use if c is false.</param>
  3476. /// <param name="b">Values to use if c is true.</param>
  3477. /// <param name="c">Selection mask to choose between a and b.</param>
  3478. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3479. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3480. 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); }
  3481. /// <summary>
  3482. /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c.
  3483. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected.
  3484. /// </summary>
  3485. /// <param name="a">Values to use if c is false.</param>
  3486. /// <param name="b">Values to use if c is true.</param>
  3487. /// <param name="c">Selection mask to choose between a and b.</param>
  3488. /// <returns>The componentwise selection between a and b according to selection mask c.</returns>
  3489. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3490. 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); }
  3491. /// <summary>Returns the result of a step function where the result is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3492. /// <param name="y">Value to be used as a threshold for returning 1.</param>
  3493. /// <param name="x">Value to compare against threshold y.</param>
  3494. /// <returns>1 if the comparison x &gt;= y is true, otherwise 0.</returns>
  3495. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3496. public static float step(float y, float x) { return select(0.0f, 1.0f, x >= y); }
  3497. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3498. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3499. /// <param name="x">Vector of values to compare against threshold y.</param>
  3500. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3501. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3502. public static float2 step(float2 y, float2 x) { return select(float2(0.0f), float2(1.0f), x >= y); }
  3503. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3504. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3505. /// <param name="x">Vector of values to compare against threshold y.</param>
  3506. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3507. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3508. public static float3 step(float3 y, float3 x) { return select(float3(0.0f), float3(1.0f), x >= y); }
  3509. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3510. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3511. /// <param name="x">Vector of values to compare against threshold y.</param>
  3512. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3513. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3514. public static float4 step(float4 y, float4 x) { return select(float4(0.0f), float4(1.0f), x >= y); }
  3515. /// <summary>Returns the result of a step function where the result is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3516. /// <param name="y">Values to be used as a threshold for returning 1.</param>
  3517. /// <param name="x">Values to compare against threshold y.</param>
  3518. /// <returns>1 if the comparison x &gt;= y is true, otherwise 0.</returns>
  3519. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3520. public static double step(double y, double x) { return select(0.0, 1.0, x >= y); }
  3521. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3522. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3523. /// <param name="x">Vector of values to compare against threshold y.</param>
  3524. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3525. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3526. public static double2 step(double2 y, double2 x) { return select(double2(0.0), double2(1.0), x >= y); }
  3527. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3528. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3529. /// <param name="x">Vector of values to compare against threshold y.</param>
  3530. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3531. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3532. public static double3 step(double3 y, double3 x) { return select(double3(0.0), double3(1.0), x >= y); }
  3533. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= y and 0.0f otherwise.</summary>
  3534. /// <param name="y">Vector of values to be used as a threshold for returning 1.</param>
  3535. /// <param name="x">Vector of values to compare against threshold y.</param>
  3536. /// <returns>1 if the componentwise comparison x &gt;= y is true, otherwise 0.</returns>
  3537. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3538. public static double4 step(double4 y, double4 x) { return select(double4(0.0), double4(1.0), x >= y); }
  3539. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3540. /// <param name="i">Incident vector.</param>
  3541. /// <param name="n">Normal vector.</param>
  3542. /// <returns>Reflection vector.</returns>
  3543. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3544. public static float2 reflect(float2 i, float2 n) { return i - 2f * n * dot(i, n); }
  3545. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3546. /// <param name="i">Incident vector.</param>
  3547. /// <param name="n">Normal vector.</param>
  3548. /// <returns>Reflection vector.</returns>
  3549. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3550. public static float3 reflect(float3 i, float3 n) { return i - 2f * n * dot(i, n); }
  3551. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3552. /// <param name="i">Incident vector.</param>
  3553. /// <param name="n">Normal vector.</param>
  3554. /// <returns>Reflection vector.</returns>
  3555. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3556. public static float4 reflect(float4 i, float4 n) { return i - 2f * n * dot(i, n); }
  3557. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3558. /// <param name="i">Incident vector.</param>
  3559. /// <param name="n">Normal vector.</param>
  3560. /// <returns>Reflection vector.</returns>
  3561. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3562. public static double2 reflect(double2 i, double2 n) { return i - 2 * n * dot(i, n); }
  3563. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3564. /// <param name="i">Incident vector.</param>
  3565. /// <param name="n">Normal vector.</param>
  3566. /// <returns>Reflection vector.</returns>
  3567. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3568. public static double3 reflect(double3 i, double3 n) { return i - 2 * n * dot(i, n); }
  3569. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3570. /// <param name="i">Incident vector.</param>
  3571. /// <param name="n">Normal vector.</param>
  3572. /// <returns>Reflection vector.</returns>
  3573. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3574. public static double4 reflect(double4 i, double4 n) { return i - 2 * n * dot(i, n); }
  3575. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3576. /// <param name="i">Incident vector.</param>
  3577. /// <param name="n">Normal vector.</param>
  3578. /// <param name="eta">Index of refraction.</param>
  3579. /// <returns>Refraction vector.</returns>
  3580. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3581. public static float2 refract(float2 i, float2 n, float eta)
  3582. {
  3583. float ni = dot(n, i);
  3584. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  3585. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3586. }
  3587. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3588. /// <param name="i">Incident vector.</param>
  3589. /// <param name="n">Normal vector.</param>
  3590. /// <param name="eta">Index of refraction.</param>
  3591. /// <returns>Refraction vector.</returns>
  3592. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3593. public static float3 refract(float3 i, float3 n, float eta)
  3594. {
  3595. float ni = dot(n, i);
  3596. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  3597. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3598. }
  3599. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3600. /// <param name="i">Incident vector.</param>
  3601. /// <param name="n">Normal vector.</param>
  3602. /// <param name="eta">Index of refraction.</param>
  3603. /// <returns>Refraction vector.</returns>
  3604. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3605. public static float4 refract(float4 i, float4 n, float eta)
  3606. {
  3607. float ni = dot(n, i);
  3608. float k = 1.0f - eta * eta * (1.0f - ni * ni);
  3609. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3610. }
  3611. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3612. /// <param name="i">Incident vector.</param>
  3613. /// <param name="n">Normal vector.</param>
  3614. /// <param name="eta">Index of refraction.</param>
  3615. /// <returns>Refraction vector.</returns>
  3616. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3617. public static double2 refract(double2 i, double2 n, double eta)
  3618. {
  3619. double ni = dot(n, i);
  3620. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  3621. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3622. }
  3623. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3624. /// <param name="i">Incident vector.</param>
  3625. /// <param name="n">Normal vector.</param>
  3626. /// <param name="eta">Index of refraction.</param>
  3627. /// <returns>Refraction vector.</returns>
  3628. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3629. public static double3 refract(double3 i, double3 n, double eta)
  3630. {
  3631. double ni = dot(n, i);
  3632. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  3633. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3634. }
  3635. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta.</summary>
  3636. /// <param name="i">Incident vector.</param>
  3637. /// <param name="n">Normal vector.</param>
  3638. /// <param name="eta">Index of refraction.</param>
  3639. /// <returns>Refraction vector.</returns>
  3640. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3641. public static double4 refract(double4 i, double4 n, double eta)
  3642. {
  3643. double ni = dot(n, i);
  3644. double k = 1.0 - eta * eta * (1.0 - ni * ni);
  3645. return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0);
  3646. }
  3647. /// <summary>
  3648. /// Compute vector projection of a onto b.
  3649. /// </summary>
  3650. /// <remarks>
  3651. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3652. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3653. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float2,Unity.Mathematics.float2,Unity.Mathematics.float2)"/>
  3654. /// which will use a given default value if the result is not finite.
  3655. /// </remarks>
  3656. /// <param name="a">Vector to project.</param>
  3657. /// <param name="b">Non-zero vector to project onto.</param>
  3658. /// <returns>Vector projection of a onto b.</returns>
  3659. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3660. public static float2 project(float2 a, float2 b)
  3661. {
  3662. return (dot(a, b) / dot(b, b)) * b;
  3663. }
  3664. /// <summary>
  3665. /// Compute vector projection of a onto b.
  3666. /// </summary>
  3667. /// <remarks>
  3668. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3669. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3670. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float3,Unity.Mathematics.float3,Unity.Mathematics.float3)"/>
  3671. /// which will use a given default value if the result is not finite.
  3672. /// </remarks>
  3673. /// <param name="a">Vector to project.</param>
  3674. /// <param name="b">Non-zero vector to project onto.</param>
  3675. /// <returns>Vector projection of a onto b.</returns>
  3676. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3677. public static float3 project(float3 a, float3 b)
  3678. {
  3679. return (dot(a, b) / dot(b, b)) * b;
  3680. }
  3681. /// <summary>
  3682. /// Compute vector projection of a onto b.
  3683. /// </summary>
  3684. /// <remarks>
  3685. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3686. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3687. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float4,Unity.Mathematics.float4,Unity.Mathematics.float4)"/>
  3688. /// which will use a given default value if the result is not finite.
  3689. /// </remarks>
  3690. /// <param name="a">Vector to project.</param>
  3691. /// <param name="b">Non-zero vector to project onto.</param>
  3692. /// <returns>Vector projection of a onto b.</returns>
  3693. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3694. public static float4 project(float4 a, float4 b)
  3695. {
  3696. return (dot(a, b) / dot(b, b)) * b;
  3697. }
  3698. /// <summary>
  3699. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3700. /// </summary>
  3701. /// <remarks>
  3702. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3703. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3704. /// <see cref="project(Unity.Mathematics.float2,Unity.Mathematics.float2)"/> instead which is faster than this
  3705. /// function.
  3706. /// </remarks>
  3707. /// <param name="a">Vector to project.</param>
  3708. /// <param name="b">Non-zero vector to project onto.</param>
  3709. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3710. /// <returns>Vector projection of a onto b or the default value.</returns>
  3711. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3712. public static float2 projectsafe(float2 a, float2 b, float2 defaultValue = new float2())
  3713. {
  3714. var proj = project(a, b);
  3715. return select(defaultValue, proj, all(isfinite(proj)));
  3716. }
  3717. /// <summary>
  3718. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3719. /// </summary>
  3720. /// <remarks>
  3721. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3722. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3723. /// <see cref="project(Unity.Mathematics.float3,Unity.Mathematics.float3)"/> instead which is faster than this
  3724. /// function.
  3725. /// </remarks>
  3726. /// <param name="a">Vector to project.</param>
  3727. /// <param name="b">Non-zero vector to project onto.</param>
  3728. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3729. /// <returns>Vector projection of a onto b or the default value.</returns>
  3730. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3731. public static float3 projectsafe(float3 a, float3 b, float3 defaultValue = new float3())
  3732. {
  3733. var proj = project(a, b);
  3734. return select(defaultValue, proj, all(isfinite(proj)));
  3735. }
  3736. /// <summary>
  3737. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3738. /// </summary>
  3739. /// <remarks>
  3740. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3741. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3742. /// <see cref="project(Unity.Mathematics.float4,Unity.Mathematics.float4)"/> instead which is faster than this
  3743. /// function.
  3744. /// </remarks>
  3745. /// <param name="a">Vector to project.</param>
  3746. /// <param name="b">Non-zero vector to project onto.</param>
  3747. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3748. /// <returns>Vector projection of a onto b or the default value.</returns>
  3749. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3750. public static float4 projectsafe(float4 a, float4 b, float4 defaultValue = new float4())
  3751. {
  3752. var proj = project(a, b);
  3753. return select(defaultValue, proj, all(isfinite(proj)));
  3754. }
  3755. /// <summary>
  3756. /// Compute vector projection of a onto b.
  3757. /// </summary>
  3758. /// <remarks>
  3759. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3760. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3761. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double2,Unity.Mathematics.double2,Unity.Mathematics.double2)"/>
  3762. /// which will use a given default value if the result is not finite.
  3763. /// </remarks>
  3764. /// <param name="a">Vector to project.</param>
  3765. /// <param name="b">Non-zero vector to project onto.</param>
  3766. /// <returns>Vector projection of a onto b.</returns>
  3767. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3768. public static double2 project(double2 a, double2 b)
  3769. {
  3770. return (dot(a, b) / dot(b, b)) * b;
  3771. }
  3772. /// <summary>
  3773. /// Compute vector projection of a onto b.
  3774. /// </summary>
  3775. /// <remarks>
  3776. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3777. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3778. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double3,Unity.Mathematics.double3,Unity.Mathematics.double3)"/>
  3779. /// which will use a given default value if the result is not finite.
  3780. /// </remarks>
  3781. /// <param name="a">Vector to project.</param>
  3782. /// <param name="b">Non-zero vector to project onto.</param>
  3783. /// <returns>Vector projection of a onto b.</returns>
  3784. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3785. public static double3 project(double3 a, double3 b)
  3786. {
  3787. return (dot(a, b) / dot(b, b)) * b;
  3788. }
  3789. /// <summary>
  3790. /// Compute vector projection of a onto b.
  3791. /// </summary>
  3792. /// <remarks>
  3793. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3794. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3795. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double4,Unity.Mathematics.double4,Unity.Mathematics.double4)"/>
  3796. /// which will use a given default value if the result is not finite.
  3797. /// </remarks>
  3798. /// <param name="a">Vector to project.</param>
  3799. /// <param name="b">Non-zero vector to project onto.</param>
  3800. /// <returns>Vector projection of a onto b.</returns>
  3801. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3802. public static double4 project(double4 a, double4 b)
  3803. {
  3804. return (dot(a, b) / dot(b, b)) * b;
  3805. }
  3806. /// <summary>
  3807. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3808. /// </summary>
  3809. /// <remarks>
  3810. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3811. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3812. /// <see cref="project(Unity.Mathematics.double2,Unity.Mathematics.double2)"/> instead which is faster than this
  3813. /// function.
  3814. /// </remarks>
  3815. /// <param name="a">Vector to project.</param>
  3816. /// <param name="b">Non-zero vector to project onto.</param>
  3817. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3818. /// <returns>Vector projection of a onto b or the default value.</returns>
  3819. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3820. public static double2 projectsafe(double2 a, double2 b, double2 defaultValue = new double2())
  3821. {
  3822. var proj = project(a, b);
  3823. return select(defaultValue, proj, all(isfinite(proj)));
  3824. }
  3825. /// <summary>
  3826. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3827. /// </summary>
  3828. /// <remarks>
  3829. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3830. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3831. /// <see cref="project(Unity.Mathematics.double3,Unity.Mathematics.double3)"/> instead which is faster than this
  3832. /// function.
  3833. /// </remarks>
  3834. /// <param name="a">Vector to project.</param>
  3835. /// <param name="b">Non-zero vector to project onto.</param>
  3836. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3837. /// <returns>Vector projection of a onto b or the default value.</returns>
  3838. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3839. public static double3 projectsafe(double3 a, double3 b, double3 defaultValue = new double3())
  3840. {
  3841. var proj = project(a, b);
  3842. return select(defaultValue, proj, all(isfinite(proj)));
  3843. }
  3844. /// <summary>
  3845. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3846. /// </summary>
  3847. /// <remarks>
  3848. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3849. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3850. /// <see cref="project(Unity.Mathematics.double4,Unity.Mathematics.double4)"/> instead which is faster than this
  3851. /// function.
  3852. /// </remarks>
  3853. /// <param name="a">Vector to project.</param>
  3854. /// <param name="b">Non-zero vector to project onto.</param>
  3855. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3856. /// <returns>Vector projection of a onto b or the default value.</returns>
  3857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3858. public static double4 projectsafe(double4 a, double4 b, double4 defaultValue = new double4())
  3859. {
  3860. var proj = project(a, b);
  3861. return select(defaultValue, proj, all(isfinite(proj)));
  3862. }
  3863. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3864. /// <param name="n">Vector to conditionally flip.</param>
  3865. /// <param name="i">First vector in direction comparison.</param>
  3866. /// <param name="ng">Second vector in direction comparison.</param>
  3867. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3868. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3869. public static float2 faceforward(float2 n, float2 i, float2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3870. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3871. /// <param name="n">Vector to conditionally flip.</param>
  3872. /// <param name="i">First vector in direction comparison.</param>
  3873. /// <param name="ng">Second vector in direction comparison.</param>
  3874. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3875. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3876. public static float3 faceforward(float3 n, float3 i, float3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3877. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3878. /// <param name="n">Vector to conditionally flip.</param>
  3879. /// <param name="i">First vector in direction comparison.</param>
  3880. /// <param name="ng">Second vector in direction comparison.</param>
  3881. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3882. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3883. public static float4 faceforward(float4 n, float4 i, float4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3884. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3885. /// <param name="n">Vector to conditionally flip.</param>
  3886. /// <param name="i">First vector in direction comparison.</param>
  3887. /// <param name="ng">Second vector in direction comparison.</param>
  3888. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3889. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3890. public static double2 faceforward(double2 n, double2 i, double2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3891. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3892. /// <param name="n">Vector to conditionally flip.</param>
  3893. /// <param name="i">First vector in direction comparison.</param>
  3894. /// <param name="ng">Second vector in direction comparison.</param>
  3895. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3896. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3897. public static double3 faceforward(double3 n, double3 i, double3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3898. /// <summary>Conditionally flips a vector n if two vectors i and ng are pointing in the same direction. Returns n if dot(i, ng) &lt; 0, -n otherwise.</summary>
  3899. /// <param name="n">Vector to conditionally flip.</param>
  3900. /// <param name="i">First vector in direction comparison.</param>
  3901. /// <param name="ng">Second vector in direction comparison.</param>
  3902. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  3903. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3904. public static double4 faceforward(double4 n, double4 i, double4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  3905. /// <summary>Returns the sine and cosine of the input float value x through the out parameters s and c.</summary>
  3906. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3907. /// <param name="x">Input angle in radians.</param>
  3908. /// <param name="s">Output sine of the input.</param>
  3909. /// <param name="c">Output cosine of the input.</param>
  3910. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3911. public static void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); }
  3912. /// <summary>Returns the componentwise sine and cosine of the input float2 vector x through the out parameters s and c.</summary>
  3913. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3914. /// <param name="x">Input vector containing angles in radians.</param>
  3915. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3916. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3917. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3918. public static void sincos(float2 x, out float2 s, out float2 c) { s = sin(x); c = cos(x); }
  3919. /// <summary>Returns the componentwise sine and cosine of the input float3 vector x through the out parameters s and c.</summary>
  3920. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3921. /// <param name="x">Input vector containing angles in radians.</param>
  3922. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3923. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3924. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3925. public static void sincos(float3 x, out float3 s, out float3 c) { s = sin(x); c = cos(x); }
  3926. /// <summary>Returns the componentwise sine and cosine of the input float4 vector x through the out parameters s and c.</summary>
  3927. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3928. /// <param name="x">Input vector containing angles in radians.</param>
  3929. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3930. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3931. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3932. public static void sincos(float4 x, out float4 s, out float4 c) { s = sin(x); c = cos(x); }
  3933. /// <summary>Returns the sine and cosine of the input double value x through the out parameters s and c.</summary>
  3934. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3935. /// <param name="x">Input angle in radians.</param>
  3936. /// <param name="s">Output sine of the input.</param>
  3937. /// <param name="c">Output cosine of the input.</param>
  3938. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3939. public static void sincos(double x, out double s, out double c) { s = sin(x); c = cos(x); }
  3940. /// <summary>Returns the componentwise sine and cosine of the input double2 vector x through the out parameters s and c.</summary>
  3941. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3942. /// <param name="x">Input vector containing angles in radians.</param>
  3943. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3944. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3945. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3946. public static void sincos(double2 x, out double2 s, out double2 c) { s = sin(x); c = cos(x); }
  3947. /// <summary>Returns the componentwise sine and cosine of the input double3 vector x through the out parameters s and c.</summary>
  3948. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3949. /// <param name="x">Input vector containing angles in radians.</param>
  3950. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3951. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3952. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3953. public static void sincos(double3 x, out double3 s, out double3 c) { s = sin(x); c = cos(x); }
  3954. /// <summary>Returns the componentwise sine and cosine of the input double4 vector x through the out parameters s and c.</summary>
  3955. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  3956. /// <param name="x">Input vector containing angles in radians.</param>
  3957. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  3958. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  3959. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3960. public static void sincos(double4 x, out double4 s, out double4 c) { s = sin(x); c = cos(x); }
  3961. /// <summary>Returns number of 1-bits in the binary representation of an int value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3962. /// <param name="x">int value in which to count bits set to 1.</param>
  3963. /// <returns>Number of bits set to 1 within x.</returns>
  3964. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3965. public static int countbits(int x) { return countbits((uint)x); }
  3966. /// <summary>Returns component-wise number of 1-bits in the binary representation of an int2 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3967. /// <param name="x">int2 value in which to count bits for each component.</param>
  3968. /// <returns>int2 containing number of bits set to 1 within each component of x.</returns>
  3969. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3970. public static int2 countbits(int2 x) { return countbits((uint2)x); }
  3971. /// <summary>Returns component-wise number of 1-bits in the binary representation of an int3 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3972. /// <param name="x">Number in which to count bits.</param>
  3973. /// <returns>int3 containing number of bits set to 1 within each component of x.</returns>
  3974. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3975. public static int3 countbits(int3 x) { return countbits((uint3)x); }
  3976. /// <summary>Returns component-wise number of 1-bits in the binary representation of an int4 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3977. /// <param name="x">Number in which to count bits.</param>
  3978. /// <returns>int4 containing number of bits set to 1 within each component of x.</returns>
  3979. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3980. public static int4 countbits(int4 x) { return countbits((uint4)x); }
  3981. /// <summary>Returns number of 1-bits in the binary representation of a uint value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3982. /// <param name="x">Number in which to count bits.</param>
  3983. /// <returns>Number of bits set to 1 within x.</returns>
  3984. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3985. public static int countbits(uint x)
  3986. {
  3987. x = x - ((x >> 1) & 0x55555555);
  3988. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  3989. return (int)((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  3990. }
  3991. /// <summary>Returns component-wise number of 1-bits in the binary representation of a uint2 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  3992. /// <param name="x">Number in which to count bits.</param>
  3993. /// <returns>int2 containing number of bits set to 1 within each component of x.</returns>
  3994. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3995. public static int2 countbits(uint2 x)
  3996. {
  3997. x = x - ((x >> 1) & 0x55555555);
  3998. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  3999. return int2((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4000. }
  4001. /// <summary>Returns component-wise number of 1-bits in the binary representation of a uint3 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  4002. /// <param name="x">Number in which to count bits.</param>
  4003. /// <returns>int3 containing number of bits set to 1 within each component of x.</returns>
  4004. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4005. public static int3 countbits(uint3 x)
  4006. {
  4007. x = x - ((x >> 1) & 0x55555555);
  4008. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4009. return int3((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4010. }
  4011. /// <summary>Returns component-wise number of 1-bits in the binary representation of a uint4 vector. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  4012. /// <param name="x">Number in which to count bits.</param>
  4013. /// <returns>int4 containing number of bits set to 1 within each component of x.</returns>
  4014. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4015. public static int4 countbits(uint4 x)
  4016. {
  4017. x = x - ((x >> 1) & 0x55555555);
  4018. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4019. return int4((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4020. }
  4021. /// <summary>Returns number of 1-bits in the binary representation of a ulong value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  4022. /// <param name="x">Number in which to count bits.</param>
  4023. /// <returns>Number of bits set to 1 within x.</returns>
  4024. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4025. public static int countbits(ulong x)
  4026. {
  4027. x = x - ((x >> 1) & 0x5555555555555555);
  4028. x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
  4029. return (int)((((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56);
  4030. }
  4031. /// <summary>Returns number of 1-bits in the binary representation of a long value. Also known as the Hamming weight, popcnt on x86, and vcnt on ARM.</summary>
  4032. /// <param name="x">Number in which to count bits.</param>
  4033. /// <returns>Number of bits set to 1 within x.</returns>
  4034. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4035. public static int countbits(long x) { return countbits((ulong)x); }
  4036. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int vector.</summary>
  4037. /// <param name="x">Input value.</param>
  4038. /// <returns>The number of leading zeros of the input.</returns>
  4039. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4040. public static int lzcnt(int x) { return lzcnt((uint)x); }
  4041. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int2 vector.</summary>
  4042. /// <param name="x">Input value.</param>
  4043. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4044. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4045. public static int2 lzcnt(int2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  4046. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int3 vector.</summary>
  4047. /// <param name="x">Input value.</param>
  4048. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4049. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4050. public static int3 lzcnt(int3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  4051. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int4 vector.</summary>
  4052. /// <param name="x">Input value.</param>
  4053. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4054. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4055. public static int4 lzcnt(int4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  4056. /// <summary>Returns number of leading zeros in the binary representations of a uint value.</summary>
  4057. /// <param name="x">Input value.</param>
  4058. /// <returns>The number of leading zeros of the input.</returns>
  4059. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4060. public static int lzcnt(uint x)
  4061. {
  4062. if (x == 0)
  4063. return 32;
  4064. LongDoubleUnion u;
  4065. u.doubleValue = 0.0;
  4066. u.longValue = 0x4330000000000000L + x;
  4067. u.doubleValue -= 4503599627370496.0;
  4068. return 0x41E - (int)(u.longValue >> 52);
  4069. }
  4070. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint2 vector.</summary>
  4071. /// <param name="x">Input value.</param>
  4072. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4073. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4074. public static int2 lzcnt(uint2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  4075. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint3 vector.</summary>
  4076. /// <param name="x">Input value.</param>
  4077. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4078. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4079. public static int3 lzcnt(uint3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  4080. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint4 vector.</summary>
  4081. /// <param name="x">Input value.</param>
  4082. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4083. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4084. public static int4 lzcnt(uint4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  4085. /// <summary>Returns number of leading zeros in the binary representations of a long value.</summary>
  4086. /// <param name="x">Input value.</param>
  4087. /// <returns>The number of leading zeros of the input.</returns>
  4088. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4089. public static int lzcnt(long x) { return lzcnt((ulong)x); }
  4090. /// <summary>Returns number of leading zeros in the binary representations of a ulong value.</summary>
  4091. /// <param name="x">Input value.</param>
  4092. /// <returns>The number of leading zeros of the input.</returns>
  4093. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4094. public static int lzcnt(ulong x)
  4095. {
  4096. if (x == 0)
  4097. return 64;
  4098. uint xh = (uint)(x >> 32);
  4099. uint bits = xh != 0 ? xh : (uint)x;
  4100. int offset = xh != 0 ? 0x41E : 0x43E;
  4101. LongDoubleUnion u;
  4102. u.doubleValue = 0.0;
  4103. u.longValue = 0x4330000000000000L + bits;
  4104. u.doubleValue -= 4503599627370496.0;
  4105. return offset - (int)(u.longValue >> 52);
  4106. }
  4107. /// <summary>
  4108. /// Computes the trailing zero count in the binary representation of the input value.
  4109. /// </summary>
  4110. /// <remarks>
  4111. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4112. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4113. /// trailing zero count is zero.
  4114. /// </remarks>
  4115. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4116. /// <returns>Returns the trailing zero count of the input.</returns>
  4117. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4118. public static int tzcnt(int x) { return tzcnt((uint)x); }
  4119. /// <summary>
  4120. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4121. /// </summary>
  4122. /// <remarks>
  4123. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4124. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4125. /// trailing zero count is zero.
  4126. /// </remarks>
  4127. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4128. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4129. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4130. public static int2 tzcnt(int2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  4131. /// <summary>
  4132. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4133. /// </summary>
  4134. /// <remarks>
  4135. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4136. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4137. /// trailing zero count is zero.
  4138. /// </remarks>
  4139. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4140. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4141. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4142. public static int3 tzcnt(int3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); }
  4143. /// <summary>
  4144. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4145. /// </summary>
  4146. /// <remarks>
  4147. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4148. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4149. /// trailing zero count is zero.
  4150. /// </remarks>
  4151. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4152. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4153. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4154. public static int4 tzcnt(int4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); }
  4155. /// <summary>
  4156. /// Computes the trailing zero count in the binary representation of the input value.
  4157. /// </summary>
  4158. /// <remarks>
  4159. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4160. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4161. /// trailing zero count is zero.
  4162. /// </remarks>
  4163. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4164. /// <returns>Returns the trailing zero count of the input.</returns>
  4165. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4166. public static int tzcnt(uint x)
  4167. {
  4168. if (x == 0)
  4169. return 32;
  4170. x &= (uint)-x;
  4171. LongDoubleUnion u;
  4172. u.doubleValue = 0.0;
  4173. u.longValue = 0x4330000000000000L + x;
  4174. u.doubleValue -= 4503599627370496.0;
  4175. return (int)(u.longValue >> 52) - 0x3FF;
  4176. }
  4177. /// <summary>
  4178. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4179. /// </summary>
  4180. /// <remarks>
  4181. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4182. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4183. /// trailing zero count is zero.
  4184. /// </remarks>
  4185. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4186. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4187. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4188. public static int2 tzcnt(uint2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  4189. /// <summary>
  4190. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4191. /// </summary>
  4192. /// <remarks>
  4193. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4194. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4195. /// trailing zero count is zero.
  4196. /// </remarks>
  4197. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4198. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4199. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4200. public static int3 tzcnt(uint3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); }
  4201. /// <summary>
  4202. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4203. /// </summary>
  4204. /// <remarks>
  4205. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4206. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4207. /// trailing zero count is zero.
  4208. /// </remarks>
  4209. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4210. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4211. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4212. public static int4 tzcnt(uint4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); }
  4213. /// <summary>
  4214. /// Computes the trailing zero count in the binary representation of the input value.
  4215. /// </summary>
  4216. /// <remarks>
  4217. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4218. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4219. /// trailing zero count is zero.
  4220. /// </remarks>
  4221. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4222. /// <returns>Returns the trailing zero count of the input.</returns>
  4223. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4224. public static int tzcnt(long x) { return tzcnt((ulong)x); }
  4225. /// <summary>
  4226. /// Computes the trailing zero count in the binary representation of the input value.
  4227. /// </summary>
  4228. /// <remarks>
  4229. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4230. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4231. /// trailing zero count is zero.
  4232. /// </remarks>
  4233. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4234. /// <returns>Returns the trailing zero count of the input.</returns>
  4235. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4236. public static int tzcnt(ulong x)
  4237. {
  4238. if (x == 0)
  4239. return 64;
  4240. x = x & (ulong)-(long)x;
  4241. uint xl = (uint)x;
  4242. uint bits = xl != 0 ? xl : (uint)(x >> 32);
  4243. int offset = xl != 0 ? 0x3FF : 0x3DF;
  4244. LongDoubleUnion u;
  4245. u.doubleValue = 0.0;
  4246. u.longValue = 0x4330000000000000L + bits;
  4247. u.doubleValue -= 4503599627370496.0;
  4248. return (int)(u.longValue >> 52) - offset;
  4249. }
  4250. /// <summary>Returns the result of performing a reversal of the bit pattern of an int value.</summary>
  4251. /// <param name="x">Value to reverse.</param>
  4252. /// <returns>Value with reversed bits.</returns>
  4253. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4254. public static int reversebits(int x) { return (int)reversebits((uint)x); }
  4255. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int2 vector.</summary>
  4256. /// <param name="x">Value to reverse.</param>
  4257. /// <returns>Value with componentwise reversed bits.</returns>
  4258. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4259. public static int2 reversebits(int2 x) { return (int2)reversebits((uint2)x); }
  4260. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int3 vector.</summary>
  4261. /// <param name="x">Value to reverse.</param>
  4262. /// <returns>Value with componentwise reversed bits.</returns>
  4263. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4264. public static int3 reversebits(int3 x) { return (int3)reversebits((uint3)x); }
  4265. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int4 vector.</summary>
  4266. /// <param name="x">Value to reverse.</param>
  4267. /// <returns>Value with componentwise reversed bits.</returns>
  4268. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4269. public static int4 reversebits(int4 x) { return (int4)reversebits((uint4)x); }
  4270. /// <summary>Returns the result of performing a reversal of the bit pattern of a uint value.</summary>
  4271. /// <param name="x">Value to reverse.</param>
  4272. /// <returns>Value with reversed bits.</returns>
  4273. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4274. public static uint reversebits(uint x) {
  4275. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4276. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4277. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4278. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4279. return (x >> 16) | (x << 16);
  4280. }
  4281. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint2 vector.</summary>
  4282. /// <param name="x">Value to reverse.</param>
  4283. /// <returns>Value with componentwise reversed bits.</returns>
  4284. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4285. public static uint2 reversebits(uint2 x)
  4286. {
  4287. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4288. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4289. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4290. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4291. return (x >> 16) | (x << 16);
  4292. }
  4293. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint3 vector.</summary>
  4294. /// <param name="x">Value to reverse.</param>
  4295. /// <returns>Value with componentwise reversed bits.</returns>
  4296. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4297. public static uint3 reversebits(uint3 x)
  4298. {
  4299. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4300. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4301. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4302. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4303. return (x >> 16) | (x << 16);
  4304. }
  4305. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint4 vector.</summary>
  4306. /// <param name="x">Value to reverse.</param>
  4307. /// <returns>Value with componentwise reversed bits.</returns>
  4308. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4309. public static uint4 reversebits(uint4 x)
  4310. {
  4311. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4312. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4313. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4314. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4315. return (x >> 16) | (x << 16);
  4316. }
  4317. /// <summary>Returns the result of performing a reversal of the bit pattern of a long value.</summary>
  4318. /// <param name="x">Value to reverse.</param>
  4319. /// <returns>Value with reversed bits.</returns>
  4320. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4321. public static long reversebits(long x) { return (long)reversebits((ulong)x); }
  4322. /// <summary>Returns the result of performing a reversal of the bit pattern of a ulong value.</summary>
  4323. /// <param name="x">Value to reverse.</param>
  4324. /// <returns>Value with reversed bits.</returns>
  4325. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4326. public static ulong reversebits(ulong x)
  4327. {
  4328. x = ((x >> 1) & 0x5555555555555555ul) | ((x & 0x5555555555555555ul) << 1);
  4329. x = ((x >> 2) & 0x3333333333333333ul) | ((x & 0x3333333333333333ul) << 2);
  4330. x = ((x >> 4) & 0x0F0F0F0F0F0F0F0Ful) | ((x & 0x0F0F0F0F0F0F0F0Ful) << 4);
  4331. x = ((x >> 8) & 0x00FF00FF00FF00FFul) | ((x & 0x00FF00FF00FF00FFul) << 8);
  4332. x = ((x >> 16) & 0x0000FFFF0000FFFFul) | ((x & 0x0000FFFF0000FFFFul) << 16);
  4333. return (x >> 32) | (x << 32);
  4334. }
  4335. /// <summary>Returns the result of rotating the bits of an int left by bits n.</summary>
  4336. /// <param name="x">Value to rotate.</param>
  4337. /// <param name="n">Number of bits to rotate.</param>
  4338. /// <returns>The rotated value.</returns>
  4339. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4340. public static int rol(int x, int n) { return (int)rol((uint)x, n); }
  4341. /// <summary>Returns the componentwise result of rotating the bits of an int2 left by bits n.</summary>
  4342. /// <param name="x">Value to rotate.</param>
  4343. /// <param name="n">Number of bits to rotate.</param>
  4344. /// <returns>The componentwise rotated value.</returns>
  4345. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4346. public static int2 rol(int2 x, int n) { return (int2)rol((uint2)x, n); }
  4347. /// <summary>Returns the componentwise result of rotating the bits of an int3 left by bits n.</summary>
  4348. /// <param name="x">Value to rotate.</param>
  4349. /// <param name="n">Number of bits to rotate.</param>
  4350. /// <returns>The componentwise rotated value.</returns>
  4351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4352. public static int3 rol(int3 x, int n) { return (int3)rol((uint3)x, n); }
  4353. /// <summary>Returns the componentwise result of rotating the bits of an int4 left by bits n.</summary>
  4354. /// <param name="x">Value to rotate.</param>
  4355. /// <param name="n">Number of bits to rotate.</param>
  4356. /// <returns>The componentwise rotated value.</returns>
  4357. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4358. public static int4 rol(int4 x, int n) { return (int4)rol((uint4)x, n); }
  4359. /// <summary>Returns the result of rotating the bits of a uint left by bits n.</summary>
  4360. /// <param name="x">Value to rotate.</param>
  4361. /// <param name="n">Number of bits to rotate.</param>
  4362. /// <returns>The rotated value.</returns>
  4363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4364. public static uint rol(uint x, int n) { return (x << n) | (x >> (32 - n)); }
  4365. /// <summary>Returns the componentwise result of rotating the bits of a uint2 left by bits n.</summary>
  4366. /// <param name="x">Value to rotate.</param>
  4367. /// <param name="n">Number of bits to rotate.</param>
  4368. /// <returns>The componentwise rotated value.</returns>
  4369. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4370. public static uint2 rol(uint2 x, int n) { return (x << n) | (x >> (32 - n)); }
  4371. /// <summary>Returns the componentwise result of rotating the bits of a uint3 left by bits n.</summary>
  4372. /// <param name="x">Value to rotate.</param>
  4373. /// <param name="n">Number of bits to rotate.</param>
  4374. /// <returns>The componentwise rotated value.</returns>
  4375. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4376. public static uint3 rol(uint3 x, int n) { return (x << n) | (x >> (32 - n)); }
  4377. /// <summary>Returns the componentwise result of rotating the bits of a uint4 left by bits n.</summary>
  4378. /// <param name="x">Value to rotate.</param>
  4379. /// <param name="n">Number of bits to rotate.</param>
  4380. /// <returns>The componentwise rotated value.</returns>
  4381. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4382. public static uint4 rol(uint4 x, int n) { return (x << n) | (x >> (32 - n)); }
  4383. /// <summary>Returns the result of rotating the bits of a long left by bits n.</summary>
  4384. /// <param name="x">Value to rotate.</param>
  4385. /// <param name="n">Number of bits to rotate.</param>
  4386. /// <returns>The rotated value.</returns>
  4387. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4388. public static long rol(long x, int n) { return (long)rol((ulong)x, n); }
  4389. /// <summary>Returns the result of rotating the bits of a ulong left by bits n.</summary>
  4390. /// <param name="x">Value to rotate.</param>
  4391. /// <param name="n">Number of bits to rotate.</param>
  4392. /// <returns>The rotated value.</returns>
  4393. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4394. public static ulong rol(ulong x, int n) { return (x << n) | (x >> (64 - n)); }
  4395. /// <summary>Returns the result of rotating the bits of an int right by bits n.</summary>
  4396. /// <param name="x">Value to rotate.</param>
  4397. /// <param name="n">Number of bits to rotate.</param>
  4398. /// <returns>The rotated value.</returns>
  4399. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4400. public static int ror(int x, int n) { return (int)ror((uint)x, n); }
  4401. /// <summary>Returns the componentwise result of rotating the bits of an int2 right by bits n.</summary>
  4402. /// <param name="x">Value to rotate.</param>
  4403. /// <param name="n">Number of bits to rotate.</param>
  4404. /// <returns>The componentwise rotated value.</returns>
  4405. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4406. public static int2 ror(int2 x, int n) { return (int2)ror((uint2)x, n); }
  4407. /// <summary>Returns the componentwise result of rotating the bits of an int3 right by bits n.</summary>
  4408. /// <param name="x">Value to rotate.</param>
  4409. /// <param name="n">Number of bits to rotate.</param>
  4410. /// <returns>The componentwise rotated value.</returns>
  4411. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4412. public static int3 ror(int3 x, int n) { return (int3)ror((uint3)x, n); }
  4413. /// <summary>Returns the componentwise result of rotating the bits of an int4 right by bits n.</summary>
  4414. /// <param name="x">Value to rotate.</param>
  4415. /// <param name="n">Number of bits to rotate.</param>
  4416. /// <returns>The componentwise rotated value.</returns>
  4417. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4418. public static int4 ror(int4 x, int n) { return (int4)ror((uint4)x, n); }
  4419. /// <summary>Returns the result of rotating the bits of a uint right by bits n.</summary>
  4420. /// <param name="x">Value to rotate.</param>
  4421. /// <param name="n">Number of bits to rotate.</param>
  4422. /// <returns>The rotated value.</returns>
  4423. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4424. public static uint ror(uint x, int n) { return (x >> n) | (x << (32 - n)); }
  4425. /// <summary>Returns the componentwise result of rotating the bits of a uint2 right by bits n.</summary>
  4426. /// <param name="x">Value to rotate.</param>
  4427. /// <param name="n">Number of bits to rotate.</param>
  4428. /// <returns>The componentwise rotated value.</returns>
  4429. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4430. public static uint2 ror(uint2 x, int n) { return (x >> n) | (x << (32 - n)); }
  4431. /// <summary>Returns the componentwise result of rotating the bits of a uint3 right by bits n.</summary>
  4432. /// <param name="x">Value to rotate.</param>
  4433. /// <param name="n">Number of bits to rotate.</param>
  4434. /// <returns>The componentwise rotated value.</returns>
  4435. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4436. public static uint3 ror(uint3 x, int n) { return (x >> n) | (x << (32 - n)); }
  4437. /// <summary>Returns the componentwise result of rotating the bits of a uint4 right by bits n.</summary>
  4438. /// <param name="x">Value to rotate.</param>
  4439. /// <param name="n">Number of bits to rotate.</param>
  4440. /// <returns>The componentwise rotated value.</returns>
  4441. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4442. public static uint4 ror(uint4 x, int n) { return (x >> n) | (x << (32 - n)); }
  4443. /// <summary>Returns the result of rotating the bits of a long right by bits n.</summary>
  4444. /// <param name="x">Value to rotate.</param>
  4445. /// <param name="n">Number of bits to rotate.</param>
  4446. /// <returns>The rotated value.</returns>
  4447. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4448. public static long ror(long x, int n) { return (long)ror((ulong)x, n); }
  4449. /// <summary>Returns the result of rotating the bits of a ulong right by bits n.</summary>
  4450. /// <param name="x">Value to rotate.</param>
  4451. /// <param name="n">Number of bits to rotate.</param>
  4452. /// <returns>The rotated value.</returns>
  4453. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4454. public static ulong ror(ulong x, int n) { return (x >> n) | (x << (64 - n)); }
  4455. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4456. /// <param name="x">Input value.</param>
  4457. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4458. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4459. public static int ceilpow2(int x)
  4460. {
  4461. x -= 1;
  4462. x |= x >> 1;
  4463. x |= x >> 2;
  4464. x |= x >> 4;
  4465. x |= x >> 8;
  4466. x |= x >> 16;
  4467. return x + 1;
  4468. }
  4469. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4470. /// <param name="x">Input value.</param>
  4471. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4472. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4473. public static int2 ceilpow2(int2 x)
  4474. {
  4475. x -= 1;
  4476. x |= x >> 1;
  4477. x |= x >> 2;
  4478. x |= x >> 4;
  4479. x |= x >> 8;
  4480. x |= x >> 16;
  4481. return x + 1;
  4482. }
  4483. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4484. /// <param name="x">Input value.</param>
  4485. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4486. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4487. public static int3 ceilpow2(int3 x)
  4488. {
  4489. x -= 1;
  4490. x |= x >> 1;
  4491. x |= x >> 2;
  4492. x |= x >> 4;
  4493. x |= x >> 8;
  4494. x |= x >> 16;
  4495. return x + 1;
  4496. }
  4497. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4498. /// <param name="x">Input value.</param>
  4499. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4500. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4501. public static int4 ceilpow2(int4 x)
  4502. {
  4503. x -= 1;
  4504. x |= x >> 1;
  4505. x |= x >> 2;
  4506. x |= x >> 4;
  4507. x |= x >> 8;
  4508. x |= x >> 16;
  4509. return x + 1;
  4510. }
  4511. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4512. /// <param name="x">Input value.</param>
  4513. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4514. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4515. public static uint ceilpow2(uint x)
  4516. {
  4517. x -= 1;
  4518. x |= x >> 1;
  4519. x |= x >> 2;
  4520. x |= x >> 4;
  4521. x |= x >> 8;
  4522. x |= x >> 16;
  4523. return x + 1;
  4524. }
  4525. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4526. /// <param name="x">Input value.</param>
  4527. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4528. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4529. public static uint2 ceilpow2(uint2 x)
  4530. {
  4531. x -= 1;
  4532. x |= x >> 1;
  4533. x |= x >> 2;
  4534. x |= x >> 4;
  4535. x |= x >> 8;
  4536. x |= x >> 16;
  4537. return x + 1;
  4538. }
  4539. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4540. /// <param name="x">Input value.</param>
  4541. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4542. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4543. public static uint3 ceilpow2(uint3 x)
  4544. {
  4545. x -= 1;
  4546. x |= x >> 1;
  4547. x |= x >> 2;
  4548. x |= x >> 4;
  4549. x |= x >> 8;
  4550. x |= x >> 16;
  4551. return x + 1;
  4552. }
  4553. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4554. /// <param name="x">Input value.</param>
  4555. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4556. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4557. public static uint4 ceilpow2(uint4 x)
  4558. {
  4559. x -= 1;
  4560. x |= x >> 1;
  4561. x |= x >> 2;
  4562. x |= x >> 4;
  4563. x |= x >> 8;
  4564. x |= x >> 16;
  4565. return x + 1;
  4566. }
  4567. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4568. /// <param name="x">Input value.</param>
  4569. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4570. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4571. public static long ceilpow2(long x)
  4572. {
  4573. x -= 1;
  4574. x |= x >> 1;
  4575. x |= x >> 2;
  4576. x |= x >> 4;
  4577. x |= x >> 8;
  4578. x |= x >> 16;
  4579. x |= x >> 32;
  4580. return x + 1;
  4581. }
  4582. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4583. /// <param name="x">Input value.</param>
  4584. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4585. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4586. public static ulong ceilpow2(ulong x)
  4587. {
  4588. x -= 1;
  4589. x |= x >> 1;
  4590. x |= x >> 2;
  4591. x |= x >> 4;
  4592. x |= x >> 8;
  4593. x |= x >> 16;
  4594. x |= x >> 32;
  4595. return x + 1;
  4596. }
  4597. /// <summary>
  4598. /// Computes the ceiling of the base-2 logarithm of x.
  4599. /// </summary>
  4600. /// <remarks>
  4601. /// x must be greater than 0, otherwise the result is undefined.
  4602. /// </remarks>
  4603. /// <param name="x">Integer to be used as input.</param>
  4604. /// <returns>Ceiling of the base-2 logarithm of x, as an integer.</returns>
  4605. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4606. public static int ceillog2(int x)
  4607. {
  4608. return 32 - lzcnt((uint)x - 1);
  4609. }
  4610. /// <summary>
  4611. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4612. /// </summary>
  4613. /// <remarks>
  4614. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4615. /// </remarks>
  4616. /// <param name="x">int2 to be used as input.</param>
  4617. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4618. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4619. public static int2 ceillog2(int2 x)
  4620. {
  4621. return new int2(ceillog2(x.x), ceillog2(x.y));
  4622. }
  4623. /// <summary>
  4624. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4625. /// </summary>
  4626. /// <remarks>
  4627. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4628. /// </remarks>
  4629. /// <param name="x">int3 to be used as input.</param>
  4630. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4631. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4632. public static int3 ceillog2(int3 x)
  4633. {
  4634. return new int3(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z));
  4635. }
  4636. /// <summary>
  4637. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4638. /// </summary>
  4639. /// <remarks>
  4640. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4641. /// </remarks>
  4642. /// <param name="x">int4 to be used as input.</param>
  4643. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4644. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4645. public static int4 ceillog2(int4 x)
  4646. {
  4647. return new int4(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z), ceillog2(x.w));
  4648. }
  4649. /// <summary>
  4650. /// Computes the ceiling of the base-2 logarithm of x.
  4651. /// </summary>
  4652. /// <remarks>
  4653. /// x must be greater than 0, otherwise the result is undefined.
  4654. /// </remarks>
  4655. /// <param name="x">Unsigned integer to be used as input.</param>
  4656. /// <returns>Ceiling of the base-2 logarithm of x, as an integer.</returns>
  4657. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4658. public static int ceillog2(uint x)
  4659. {
  4660. return 32 - lzcnt(x - 1);
  4661. }
  4662. /// <summary>
  4663. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4664. /// </summary>
  4665. /// <remarks>
  4666. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4667. /// </remarks>
  4668. /// <param name="x">uint2 to be used as input.</param>
  4669. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4670. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4671. public static int2 ceillog2(uint2 x)
  4672. {
  4673. return new int2(ceillog2(x.x), ceillog2(x.y));
  4674. }
  4675. /// <summary>
  4676. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4677. /// </summary>
  4678. /// <remarks>
  4679. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4680. /// </remarks>
  4681. /// <param name="x">uint3 to be used as input.</param>
  4682. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4683. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4684. public static int3 ceillog2(uint3 x)
  4685. {
  4686. return new int3(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z));
  4687. }
  4688. /// <summary>
  4689. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4690. /// </summary>
  4691. /// <remarks>
  4692. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4693. /// </remarks>
  4694. /// <param name="x">uint4 to be used as input.</param>
  4695. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4696. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4697. public static int4 ceillog2(uint4 x)
  4698. {
  4699. return new int4(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z), ceillog2(x.w));
  4700. }
  4701. /// <summary>
  4702. /// Computes the floor of the base-2 logarithm of x.
  4703. /// </summary>
  4704. /// <remarks>x must be greater than zero, otherwise the result is undefined.</remarks>
  4705. /// <param name="x">Integer to be used as input.</param>
  4706. /// <returns>Floor of base-2 logarithm of x.</returns>
  4707. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4708. public static int floorlog2(int x)
  4709. {
  4710. return 31 - lzcnt((uint)x);
  4711. }
  4712. /// <summary>
  4713. /// Computes the componentwise floor of the base-2 logarithm of x.
  4714. /// </summary>
  4715. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4716. /// <param name="x">int2 to be used as input.</param>
  4717. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4718. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4719. public static int2 floorlog2(int2 x)
  4720. {
  4721. return new int2(floorlog2(x.x), floorlog2(x.y));
  4722. }
  4723. /// <summary>
  4724. /// Computes the componentwise floor of the base-2 logarithm of x.
  4725. /// </summary>
  4726. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4727. /// <param name="x">int3 to be used as input.</param>
  4728. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4729. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4730. public static int3 floorlog2(int3 x)
  4731. {
  4732. return new int3(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z));
  4733. }
  4734. /// <summary>
  4735. /// Computes the componentwise floor of the base-2 logarithm of x.
  4736. /// </summary>
  4737. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4738. /// <param name="x">int4 to be used as input.</param>
  4739. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4740. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4741. public static int4 floorlog2(int4 x)
  4742. {
  4743. return new int4(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z), floorlog2(x.w));
  4744. }
  4745. /// <summary>
  4746. /// Computes the floor of the base-2 logarithm of x.
  4747. /// </summary>
  4748. /// <remarks>x must be greater than zero, otherwise the result is undefined.</remarks>
  4749. /// <param name="x">Unsigned integer to be used as input.</param>
  4750. /// <returns>Floor of base-2 logarithm of x.</returns>
  4751. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4752. public static int floorlog2(uint x)
  4753. {
  4754. return 31 - lzcnt(x);
  4755. }
  4756. /// <summary>
  4757. /// Computes the componentwise floor of the base-2 logarithm of x.
  4758. /// </summary>
  4759. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4760. /// <param name="x">uint2 to be used as input.</param>
  4761. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4762. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4763. public static int2 floorlog2(uint2 x)
  4764. {
  4765. return new int2(floorlog2(x.x), floorlog2(x.y));
  4766. }
  4767. /// <summary>
  4768. /// Computes the componentwise floor of the base-2 logarithm of x.
  4769. /// </summary>
  4770. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4771. /// <param name="x">uint3 to be used as input.</param>
  4772. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4773. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4774. public static int3 floorlog2(uint3 x)
  4775. {
  4776. return new int3(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z));
  4777. }
  4778. /// <summary>
  4779. /// Computes the componentwise floor of the base-2 logarithm of x.
  4780. /// </summary>
  4781. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4782. /// <param name="x">uint4 to be used as input.</param>
  4783. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4784. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4785. public static int4 floorlog2(uint4 x)
  4786. {
  4787. return new int4(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z), floorlog2(x.w));
  4788. }
  4789. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  4790. /// <param name="x">Angle in degrees.</param>
  4791. /// <returns>Angle converted to radians.</returns>
  4792. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4793. public static float radians(float x) { return x * 0.0174532925f; }
  4794. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  4795. /// <param name="x">Vector containing angles in degrees.</param>
  4796. /// <returns>Vector containing angles converted to radians.</returns>
  4797. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4798. public static float2 radians(float2 x) { return x * 0.0174532925f; }
  4799. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  4800. /// <param name="x">Vector containing angles in degrees.</param>
  4801. /// <returns>Vector containing angles converted to radians.</returns>
  4802. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4803. public static float3 radians(float3 x) { return x * 0.0174532925f; }
  4804. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  4805. /// <param name="x">Vector containing angles in degrees.</param>
  4806. /// <returns>Vector containing angles converted to radians.</returns>
  4807. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4808. public static float4 radians(float4 x) { return x * 0.0174532925f; }
  4809. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  4810. /// <param name="x">Angle in degrees.</param>
  4811. /// <returns>Angle converted to radians.</returns>
  4812. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4813. public static double radians(double x) { return x * 0.017453292519943296; }
  4814. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  4815. /// <param name="x">Vector containing angles in degrees.</param>
  4816. /// <returns>Vector containing angles converted to radians.</returns>
  4817. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4818. public static double2 radians(double2 x) { return x * 0.017453292519943296; }
  4819. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  4820. /// <param name="x">Vector containing angles in degrees.</param>
  4821. /// <returns>Vector containing angles converted to radians.</returns>
  4822. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4823. public static double3 radians(double3 x) { return x * 0.017453292519943296; }
  4824. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  4825. /// <param name="x">Vector containing angles in degrees.</param>
  4826. /// <returns>Vector containing angles converted to radians.</returns>
  4827. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4828. public static double4 radians(double4 x) { return x * 0.017453292519943296; }
  4829. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  4830. /// <param name="x">Angle in radians.</param>
  4831. /// <returns>Angle converted to degrees.</returns>
  4832. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4833. public static float degrees(float x) { return x * 57.295779513f; }
  4834. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  4835. /// <param name="x">Vector containing angles in radians.</param>
  4836. /// <returns>Vector containing angles converted to degrees.</returns>
  4837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4838. public static float2 degrees(float2 x) { return x * 57.295779513f; }
  4839. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  4840. /// <param name="x">Vector containing angles in radians.</param>
  4841. /// <returns>Vector containing angles converted to degrees.</returns>
  4842. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4843. public static float3 degrees(float3 x) { return x * 57.295779513f; }
  4844. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  4845. /// <param name="x">Vector containing angles in radians.</param>
  4846. /// <returns>Vector containing angles converted to degrees.</returns>
  4847. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4848. public static float4 degrees(float4 x) { return x * 57.295779513f; }
  4849. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  4850. /// <param name="x">Angle in radians.</param>
  4851. /// <returns>Angle converted to degrees.</returns>
  4852. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4853. public static double degrees(double x) { return x * 57.29577951308232; }
  4854. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  4855. /// <param name="x">Vector containing angles in radians.</param>
  4856. /// <returns>Vector containing angles converted to degrees.</returns>
  4857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4858. public static double2 degrees(double2 x) { return x * 57.29577951308232; }
  4859. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  4860. /// <param name="x">Vector containing angles in radians.</param>
  4861. /// <returns>Vector containing values converted to degrees.</returns>
  4862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4863. public static double3 degrees(double3 x) { return x * 57.29577951308232; }
  4864. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  4865. /// <param name="x">Vector containing angles in radians.</param>
  4866. /// <returns>Vector containing angles converted to degrees.</returns>
  4867. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4868. public static double4 degrees(double4 x) { return x * 57.29577951308232; }
  4869. /// <summary>Returns the minimum component of an int2 vector.</summary>
  4870. /// <param name="x">The vector to use when computing the minimum component.</param>
  4871. /// <returns>The value of the minimum component of the vector.</returns>
  4872. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4873. public static int cmin(int2 x) { return min(x.x, x.y); }
  4874. /// <summary>Returns the minimum component of an int3 vector.</summary>
  4875. /// <param name="x">The vector to use when computing the minimum component.</param>
  4876. /// <returns>The value of the minimum component of the vector.</returns>
  4877. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4878. public static int cmin(int3 x) { return min(min(x.x, x.y), x.z); }
  4879. /// <summary>Returns the minimum component of an int4 vector.</summary>
  4880. /// <param name="x">The vector to use when computing the minimum component.</param>
  4881. /// <returns>The value of the minimum component of the vector.</returns>
  4882. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4883. public static int cmin(int4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  4884. /// <summary>Returns the minimum component of a uint2 vector.</summary>
  4885. /// <param name="x">The vector to use when computing the minimum component.</param>
  4886. /// <returns>The value of the minimum component of the vector.</returns>
  4887. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4888. public static uint cmin(uint2 x) { return min(x.x, x.y); }
  4889. /// <summary>Returns the minimum component of a uint3 vector.</summary>
  4890. /// <param name="x">The vector to use when computing the minimum component.</param>
  4891. /// <returns>The value of the minimum component of the vector.</returns>
  4892. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4893. public static uint cmin(uint3 x) { return min(min(x.x, x.y), x.z); }
  4894. /// <summary>Returns the minimum component of a uint4 vector.</summary>
  4895. /// <param name="x">The vector to use when computing the minimum component.</param>
  4896. /// <returns>The value of the minimum component of the vector.</returns>
  4897. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4898. public static uint cmin(uint4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  4899. /// <summary>Returns the minimum component of a float2 vector.</summary>
  4900. /// <param name="x">The vector to use when computing the minimum component.</param>
  4901. /// <returns>The value of the minimum component of the vector.</returns>
  4902. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4903. public static float cmin(float2 x) { return min(x.x, x.y); }
  4904. /// <summary>Returns the minimum component of a float3 vector.</summary>
  4905. /// <param name="x">The vector to use when computing the minimum component.</param>
  4906. /// <returns>The value of the minimum component of the vector.</returns>
  4907. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4908. public static float cmin(float3 x) { return min(min(x.x, x.y), x.z); }
  4909. /// <summary>Returns the minimum component of a float4 vector.</summary>
  4910. /// <param name="x">The vector to use when computing the minimum component.</param>
  4911. /// <returns>The value of the minimum component of the vector.</returns>
  4912. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4913. public static float cmin(float4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  4914. /// <summary>Returns the minimum component of a double2 vector.</summary>
  4915. /// <param name="x">The vector to use when computing the minimum component.</param>
  4916. /// <returns>The value of the minimum component of the vector.</returns>
  4917. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4918. public static double cmin(double2 x) { return min(x.x, x.y); }
  4919. /// <summary>Returns the minimum component of a double3 vector.</summary>
  4920. /// <param name="x">The vector to use when computing the minimum component.</param>
  4921. /// <returns>The value of the minimum component of the vector.</returns>
  4922. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4923. public static double cmin(double3 x) { return min(min(x.x, x.y), x.z); }
  4924. /// <summary>Returns the minimum component of a double4 vector.</summary>
  4925. /// <param name="x">The vector to use when computing the minimum component.</param>
  4926. /// <returns>The value of the minimum component of the vector.</returns>
  4927. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4928. public static double cmin(double4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  4929. /// <summary>Returns the maximum component of an int2 vector.</summary>
  4930. /// <param name="x">The vector to use when computing the maximum component.</param>
  4931. /// <returns>The value of the maximum component of the vector.</returns>
  4932. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4933. public static int cmax(int2 x) { return max(x.x, x.y); }
  4934. /// <summary>Returns the maximum component of an int3 vector.</summary>
  4935. /// <param name="x">The vector to use when computing the maximum component.</param>
  4936. /// <returns>The value of the maximum component of the vector.</returns>
  4937. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4938. public static int cmax(int3 x) { return max(max(x.x, x.y), x.z); }
  4939. /// <summary>Returns the maximum component of an int4 vector.</summary>
  4940. /// <param name="x">The vector to use when computing the maximum component.</param>
  4941. /// <returns>The value of the maximum component of the vector.</returns>
  4942. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4943. public static int cmax(int4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  4944. /// <summary>Returns the maximum component of a uint2 vector.</summary>
  4945. /// <param name="x">The vector to use when computing the maximum component.</param>
  4946. /// <returns>The value of the maximum component of the vector.</returns>
  4947. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4948. public static uint cmax(uint2 x) { return max(x.x, x.y); }
  4949. /// <summary>Returns the maximum component of a uint3 vector.</summary>
  4950. /// <param name="x">The vector to use when computing the maximum component.</param>
  4951. /// <returns>The value of the maximum component of the vector.</returns>
  4952. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4953. public static uint cmax(uint3 x) { return max(max(x.x, x.y), x.z); }
  4954. /// <summary>Returns the maximum component of a uint4 vector.</summary>
  4955. /// <param name="x">The vector to use when computing the maximum component.</param>
  4956. /// <returns>The value of the maximum component of the vector.</returns>
  4957. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4958. public static uint cmax(uint4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  4959. /// <summary>Returns the maximum component of a float2 vector.</summary>
  4960. /// <param name="x">The vector to use when computing the maximum component.</param>
  4961. /// <returns>The value of the maximum component of the vector.</returns>
  4962. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4963. public static float cmax(float2 x) { return max(x.x, x.y); }
  4964. /// <summary>Returns the maximum component of a float3 vector.</summary>
  4965. /// <param name="x">The vector to use when computing the maximum component.</param>
  4966. /// <returns>The value of the maximum component of the vector.</returns>
  4967. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4968. public static float cmax(float3 x) { return max(max(x.x, x.y), x.z); }
  4969. /// <summary>Returns the maximum component of a float4 vector.</summary>
  4970. /// <param name="x">The vector to use when computing the maximum component.</param>
  4971. /// <returns>The value of the maximum component of the vector.</returns>
  4972. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4973. public static float cmax(float4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  4974. /// <summary>Returns the maximum component of a double2 vector.</summary>
  4975. /// <param name="x">The vector to use when computing the maximum component.</param>
  4976. /// <returns>The value of the maximum component of the vector.</returns>
  4977. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4978. public static double cmax(double2 x) { return max(x.x, x.y); }
  4979. /// <summary>Returns the maximum component of a double3 vector.</summary>
  4980. /// <param name="x">The vector to use when computing the maximum component.</param>
  4981. /// <returns>The value of the maximum component of the vector.</returns>
  4982. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4983. public static double cmax(double3 x) { return max(max(x.x, x.y), x.z); }
  4984. /// <summary>Returns the maximum component of a double4 vector.</summary>
  4985. /// <param name="x">The vector to use when computing the maximum component.</param>
  4986. /// <returns>The value of the maximum component of the vector.</returns>
  4987. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4988. public static double cmax(double4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  4989. /// <summary>Returns the horizontal sum of components of an int2 vector.</summary>
  4990. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  4991. /// <returns>The horizontal sum of of components of the vector.</returns>
  4992. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4993. public static int csum(int2 x) { return x.x + x.y; }
  4994. /// <summary>Returns the horizontal sum of components of an int3 vector.</summary>
  4995. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  4996. /// <returns>The horizontal sum of of components of the vector.</returns>
  4997. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4998. public static int csum(int3 x) { return x.x + x.y + x.z; }
  4999. /// <summary>Returns the horizontal sum of components of an int4 vector.</summary>
  5000. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5001. /// <returns>The horizontal sum of of components of the vector.</returns>
  5002. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5003. public static int csum(int4 x) { return x.x + x.y + x.z + x.w; }
  5004. /// <summary>Returns the horizontal sum of components of a uint2 vector.</summary>
  5005. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5006. /// <returns>The horizontal sum of of components of the vector.</returns>
  5007. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5008. public static uint csum(uint2 x) { return x.x + x.y; }
  5009. /// <summary>Returns the horizontal sum of components of a uint3 vector.</summary>
  5010. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5011. /// <returns>The horizontal sum of of components of the vector.</returns>
  5012. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5013. public static uint csum(uint3 x) { return x.x + x.y + x.z; }
  5014. /// <summary>Returns the horizontal sum of components of a uint4 vector.</summary>
  5015. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5016. /// <returns>The horizontal sum of of components of the vector.</returns>
  5017. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5018. public static uint csum(uint4 x) { return x.x + x.y + x.z + x.w; }
  5019. /// <summary>Returns the horizontal sum of components of a float2 vector.</summary>
  5020. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5021. /// <returns>The horizontal sum of of components of the vector.</returns>
  5022. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5023. public static float csum(float2 x) { return x.x + x.y; }
  5024. /// <summary>Returns the horizontal sum of components of a float3 vector.</summary>
  5025. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5026. /// <returns>The horizontal sum of of components of the vector.</returns>
  5027. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5028. public static float csum(float3 x) { return x.x + x.y + x.z; }
  5029. /// <summary>Returns the horizontal sum of components of a float4 vector.</summary>
  5030. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5031. /// <returns>The horizontal sum of of components of the vector.</returns>
  5032. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5033. public static float csum(float4 x) { return (x.x + x.y) + (x.z + x.w); }
  5034. /// <summary>Returns the horizontal sum of components of a double2 vector.</summary>
  5035. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5036. /// <returns>The horizontal sum of of components of the vector.</returns>
  5037. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5038. public static double csum(double2 x) { return x.x + x.y; }
  5039. /// <summary>Returns the horizontal sum of components of a double3 vector.</summary>
  5040. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5041. /// <returns>The horizontal sum of of components of the vector.</returns>
  5042. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5043. public static double csum(double3 x) { return x.x + x.y + x.z; }
  5044. /// <summary>Returns the horizontal sum of components of a double4 vector.</summary>
  5045. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5046. /// <returns>The horizontal sum of of components of the vector.</returns>
  5047. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5048. public static double csum(double4 x) { return (x.x + x.y) + (x.z + x.w); }
  5049. /// <summary>
  5050. /// Packs components with an enabled mask to the left.
  5051. /// </summary>
  5052. /// <remarks>
  5053. /// This function is also known as left packing. The effect of this function is to filter out components that
  5054. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5055. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5056. /// produce an output array of the things that intersected.
  5057. /// </remarks>
  5058. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5059. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5060. /// <param name="val">The value to to compress.</param>
  5061. /// <param name="mask">Mask indicating which components are enabled.</param>
  5062. /// <returns>Index to element after the last one stored.</returns>
  5063. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5064. public static unsafe int compress(int* output, int index, int4 val, bool4 mask)
  5065. {
  5066. if (mask.x)
  5067. output[index++] = val.x;
  5068. if (mask.y)
  5069. output[index++] = val.y;
  5070. if (mask.z)
  5071. output[index++] = val.z;
  5072. if (mask.w)
  5073. output[index++] = val.w;
  5074. return index;
  5075. }
  5076. /// <summary>
  5077. /// Packs components with an enabled mask to the left.
  5078. /// </summary>
  5079. /// <remarks>
  5080. /// This function is also known as left packing. The effect of this function is to filter out components that
  5081. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5082. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5083. /// produce an output array of the things that intersected.
  5084. /// </remarks>
  5085. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5086. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5087. /// <param name="val">The value to to compress.</param>
  5088. /// <param name="mask">Mask indicating which components are enabled.</param>
  5089. /// <returns>Index to element after the last one stored.</returns>
  5090. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5091. public static unsafe int compress(uint* output, int index, uint4 val, bool4 mask)
  5092. {
  5093. return compress((int*)output, index, *(int4*)&val, mask);
  5094. }
  5095. /// <summary>
  5096. /// Packs components with an enabled mask to the left.
  5097. /// </summary>
  5098. /// <remarks>
  5099. /// This function is also known as left packing. The effect of this function is to filter out components that
  5100. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5101. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5102. /// produce an output array of the things that intersected.
  5103. /// </remarks>
  5104. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5105. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5106. /// <param name="val">The value to to compress.</param>
  5107. /// <param name="mask">Mask indicating which components are enabled.</param>
  5108. /// <returns>Index to element after the last one stored.</returns>
  5109. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5110. public static unsafe int compress(float* output, int index, float4 val, bool4 mask)
  5111. {
  5112. return compress((int*)output, index, *(int4*)&val, mask);
  5113. }
  5114. /// <summary>Returns the floating point representation of a half-precision floating point value.</summary>
  5115. /// <param name="x">The half precision float.</param>
  5116. /// <returns>The single precision float representation of the half precision float.</returns>
  5117. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5118. public static float f16tof32(uint x)
  5119. {
  5120. const uint shifted_exp = (0x7c00 << 13);
  5121. uint uf = (x & 0x7fff) << 13;
  5122. uint e = uf & shifted_exp;
  5123. uf += (127 - 15) << 23;
  5124. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5125. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5126. uf |= (x & 0x8000) << 16;
  5127. return asfloat(uf);
  5128. }
  5129. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5130. /// <param name="x">The half precision float vector.</param>
  5131. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5132. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5133. public static float2 f16tof32(uint2 x)
  5134. {
  5135. const uint shifted_exp = (0x7c00 << 13);
  5136. uint2 uf = (x & 0x7fff) << 13;
  5137. uint2 e = uf & shifted_exp;
  5138. uf += (127 - 15) << 23;
  5139. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5140. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5141. uf |= (x & 0x8000) << 16;
  5142. return asfloat(uf);
  5143. }
  5144. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5145. /// <param name="x">The half precision float vector.</param>
  5146. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5147. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5148. public static float3 f16tof32(uint3 x)
  5149. {
  5150. const uint shifted_exp = (0x7c00 << 13);
  5151. uint3 uf = (x & 0x7fff) << 13;
  5152. uint3 e = uf & shifted_exp;
  5153. uf += (127 - 15) << 23;
  5154. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5155. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5156. uf |= (x & 0x8000) << 16;
  5157. return asfloat(uf);
  5158. }
  5159. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5160. /// <param name="x">The half precision float vector.</param>
  5161. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5162. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5163. public static float4 f16tof32(uint4 x)
  5164. {
  5165. const uint shifted_exp = (0x7c00 << 13);
  5166. uint4 uf = (x & 0x7fff) << 13;
  5167. uint4 e = uf & shifted_exp;
  5168. uf += (127 - 15) << 23;
  5169. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5170. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5171. uf |= (x & 0x8000) << 16;
  5172. return asfloat(uf);
  5173. }
  5174. /// <summary>Returns the result converting a float value to its nearest half-precision floating point representation.</summary>
  5175. /// <param name="x">The single precision float.</param>
  5176. /// <returns>The half precision float representation of the single precision float.</returns>
  5177. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5178. public static uint f32tof16(float x)
  5179. {
  5180. const int infinity_32 = 255 << 23;
  5181. const uint msk = 0x7FFFF000u;
  5182. uint ux = asuint(x);
  5183. uint uux = ux & msk;
  5184. uint h = (uint)(asuint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5185. h = select(h, select(0x7c00u, 0x7e00u, (int)uux > infinity_32), (int)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5186. return h | (ux & ~msk) >> 16;
  5187. }
  5188. /// <summary>Returns the result of a componentwise conversion of a float2 vector to its nearest half-precision floating point representation.</summary>
  5189. /// <param name="x">The single precision float vector.</param>
  5190. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5191. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5192. public static uint2 f32tof16(float2 x)
  5193. {
  5194. const int infinity_32 = 255 << 23;
  5195. const uint msk = 0x7FFFF000u;
  5196. uint2 ux = asuint(x);
  5197. uint2 uux = ux & msk;
  5198. uint2 h = (uint2)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5199. h = select(h, select(0x7c00u, 0x7e00u, (int2)uux > infinity_32), (int2)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5200. return h | (ux & ~msk) >> 16;
  5201. }
  5202. /// <summary>Returns the result of a componentwise conversion of a float3 vector to its nearest half-precision floating point representation.</summary>
  5203. /// <param name="x">The single precision float vector.</param>
  5204. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5205. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5206. public static uint3 f32tof16(float3 x)
  5207. {
  5208. const int infinity_32 = 255 << 23;
  5209. const uint msk = 0x7FFFF000u;
  5210. uint3 ux = asuint(x);
  5211. uint3 uux = ux & msk;
  5212. uint3 h = (uint3)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5213. h = select(h, select(0x7c00u, 0x7e00u, (int3)uux > infinity_32), (int3)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5214. return h | (ux & ~msk) >> 16;
  5215. }
  5216. /// <summary>Returns the result of a componentwise conversion of a float4 vector to its nearest half-precision floating point representation.</summary>
  5217. /// <param name="x">The single precision float vector.</param>
  5218. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5219. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5220. public static uint4 f32tof16(float4 x)
  5221. {
  5222. const int infinity_32 = 255 << 23;
  5223. const uint msk = 0x7FFFF000u;
  5224. uint4 ux = asuint(x);
  5225. uint4 uux = ux & msk;
  5226. uint4 h = (uint4)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5227. h = select(h, select(0x7c00u, 0x7e00u, (int4)uux > infinity_32), (int4)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5228. return h | (ux & ~msk) >> 16;
  5229. }
  5230. /// <summary>Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context.</summary>
  5231. /// <param name="pBuffer">A pointer to the beginning of the data.</param>
  5232. /// <param name="numBytes">Number of bytes to hash.</param>
  5233. /// <param name="seed">Starting seed value.</param>
  5234. /// <returns>The 32 bit hash of the input data buffer.</returns>
  5235. public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0)
  5236. {
  5237. unchecked
  5238. {
  5239. const uint Prime1 = 2654435761;
  5240. const uint Prime2 = 2246822519;
  5241. const uint Prime3 = 3266489917;
  5242. const uint Prime4 = 668265263;
  5243. const uint Prime5 = 374761393;
  5244. uint4* p = (uint4*)pBuffer;
  5245. uint hash = seed + Prime5;
  5246. if (numBytes >= 16)
  5247. {
  5248. uint4 state = new uint4(Prime1 + Prime2, Prime2, 0, (uint)-Prime1) + seed;
  5249. int count = numBytes >> 4;
  5250. for (int i = 0; i < count; ++i)
  5251. {
  5252. state += *p++ * Prime2;
  5253. state = (state << 13) | (state >> 19);
  5254. state *= Prime1;
  5255. }
  5256. hash = rol(state.x, 1) + rol(state.y, 7) + rol(state.z, 12) + rol(state.w, 18);
  5257. }
  5258. hash += (uint)numBytes;
  5259. uint* puint = (uint*)p;
  5260. for (int i = 0; i < ((numBytes >> 2) & 3); ++i)
  5261. {
  5262. hash += *puint++ * Prime3;
  5263. hash = rol(hash, 17) * Prime4;
  5264. }
  5265. byte* pbyte = (byte*)puint;
  5266. for (int i = 0; i < ((numBytes) & 3); ++i)
  5267. {
  5268. hash += (*pbyte++) * Prime5;
  5269. hash = rol(hash, 11) * Prime1;
  5270. }
  5271. hash ^= hash >> 15;
  5272. hash *= Prime2;
  5273. hash ^= hash >> 13;
  5274. hash *= Prime3;
  5275. hash ^= hash >> 16;
  5276. return hash;
  5277. }
  5278. }
  5279. /// <summary>
  5280. /// Unity's up axis (0, 1, 0).
  5281. /// </summary>
  5282. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-up.html](https://docs.unity3d.com/ScriptReference/Vector3-up.html)</remarks>
  5283. /// <returns>The up axis.</returns>
  5284. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5285. public static float3 up() { return new float3(0.0f, 1.0f, 0.0f); } // for compatibility
  5286. /// <summary>
  5287. /// Unity's down axis (0, -1, 0).
  5288. /// </summary>
  5289. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-down.html](https://docs.unity3d.com/ScriptReference/Vector3-down.html)</remarks>
  5290. /// <returns>The down axis.</returns>
  5291. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5292. public static float3 down() { return new float3(0.0f, -1.0f, 0.0f); }
  5293. /// <summary>
  5294. /// Unity's forward axis (0, 0, 1).
  5295. /// </summary>
  5296. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-forward.html](https://docs.unity3d.com/ScriptReference/Vector3-forward.html)</remarks>
  5297. /// <returns>The forward axis.</returns>
  5298. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5299. public static float3 forward() { return new float3(0.0f, 0.0f, 1.0f); }
  5300. /// <summary>
  5301. /// Unity's back axis (0, 0, -1).
  5302. /// </summary>
  5303. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-back.html](https://docs.unity3d.com/ScriptReference/Vector3-back.html)</remarks>
  5304. /// <returns>The back axis.</returns>
  5305. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5306. public static float3 back() { return new float3(0.0f, 0.0f, -1.0f); }
  5307. /// <summary>
  5308. /// Unity's left axis (-1, 0, 0).
  5309. /// </summary>
  5310. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-left.html](https://docs.unity3d.com/ScriptReference/Vector3-left.html)</remarks>
  5311. /// <returns>The left axis.</returns>
  5312. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5313. public static float3 left() { return new float3(-1.0f, 0.0f, 0.0f); }
  5314. /// <summary>
  5315. /// Unity's right axis (1, 0, 0).
  5316. /// </summary>
  5317. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-right.html](https://docs.unity3d.com/ScriptReference/Vector3-right.html)</remarks>
  5318. /// <returns>The right axis.</returns>
  5319. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5320. public static float3 right() { return new float3(1.0f, 0.0f, 0.0f); }
  5321. // Internal
  5322. // SSE shuffles
  5323. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5324. internal static float4 unpacklo(float4 a, float4 b)
  5325. {
  5326. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  5327. }
  5328. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5329. internal static double4 unpacklo(double4 a, double4 b)
  5330. {
  5331. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  5332. }
  5333. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5334. internal static float4 unpackhi(float4 a, float4 b)
  5335. {
  5336. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  5337. }
  5338. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5339. internal static double4 unpackhi(double4 a, double4 b)
  5340. {
  5341. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  5342. }
  5343. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5344. internal static float4 movelh(float4 a, float4 b)
  5345. {
  5346. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  5347. }
  5348. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5349. internal static double4 movelh(double4 a, double4 b)
  5350. {
  5351. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  5352. }
  5353. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5354. internal static float4 movehl(float4 a, float4 b)
  5355. {
  5356. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  5357. }
  5358. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5359. internal static double4 movehl(double4 a, double4 b)
  5360. {
  5361. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  5362. }
  5363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5364. internal static uint fold_to_uint(double x) // utility for double hashing
  5365. {
  5366. LongDoubleUnion u;
  5367. u.longValue = 0;
  5368. u.doubleValue = x;
  5369. return (uint)(u.longValue >> 32) ^ (uint)u.longValue;
  5370. }
  5371. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5372. internal static uint2 fold_to_uint(double2 x) { return uint2(fold_to_uint(x.x), fold_to_uint(x.y)); }
  5373. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5374. 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)); }
  5375. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5376. 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)); }
  5377. [StructLayout(LayoutKind.Explicit)]
  5378. internal struct IntFloatUnion
  5379. {
  5380. [FieldOffset(0)]
  5381. public int intValue;
  5382. [FieldOffset(0)]
  5383. public float floatValue;
  5384. }
  5385. [StructLayout(LayoutKind.Explicit)]
  5386. internal struct LongDoubleUnion
  5387. {
  5388. [FieldOffset(0)]
  5389. public long longValue;
  5390. [FieldOffset(0)]
  5391. public double doubleValue;
  5392. }
  5393. }
  5394. }