Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186
  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>
  64. /// The mathematical constant (2 * pi). Approximately 6.28. This is a f64/double precision constant. Also known as <see cref="TAU_DBL"/>.
  65. /// </summary>
  66. public const double PI2_DBL = PI_DBL * 2.0;
  67. /// <summary>
  68. /// The mathematical constant (pi / 2). Approximately 1.57. This is a f64/double precision constant.
  69. /// </summary>
  70. public const double PIHALF_DBL = PI_DBL * 0.5;
  71. /// <summary>
  72. /// The mathematical constant tau. Approximately 6.28. This is a f64/double precision constant. Also known as <see cref="PI2_DBL"/>.
  73. /// </summary>
  74. public const double TAU_DBL = PI2_DBL;
  75. /// <summary>
  76. /// The conversion constant used to convert radians to degrees. Multiply the radian value by this constant to get degrees.
  77. /// </summary>
  78. /// <remarks>Multiplying by this constant is equivalent to using <see cref="math.degrees(double)"/>.</remarks>
  79. public const double TODEGREES_DBL = 57.29577951308232;
  80. /// <summary>
  81. /// The conversion constant used to convert degrees to radians. Multiply the degree value by this constant to get radians.
  82. /// </summary>
  83. /// <remarks>Multiplying by this constant is equivalent to using <see cref="math.radians(double)"/>.</remarks>
  84. public const double TORADIANS_DBL = 0.017453292519943296;
  85. /// <summary>The square root 2. Approximately 1.41. This is a f64/double precision constant.</summary>
  86. public const double SQRT2_DBL = 1.41421356237309504880;
  87. /// <summary>
  88. /// The difference between 1.0 and the next representable f64/double precision number.
  89. ///
  90. /// Beware:
  91. /// This value is different from System.Double.Epsilon, which is the smallest, positive, denormalized f64/double.
  92. /// </summary>
  93. public const double EPSILON_DBL = 2.22044604925031308085e-16;
  94. /// <summary>
  95. /// Double precision constant for positive infinity.
  96. /// </summary>
  97. public const double INFINITY_DBL = Double.PositiveInfinity;
  98. /// <summary>
  99. /// Double precision constant for Not a Number.
  100. ///
  101. /// NAN_DBL is considered unordered, which means all comparisons involving it are false except for not equal (operator !=).
  102. /// As a consequence, NAN_DBL == NAN_DBL is false but NAN_DBL != NAN_DBL is true.
  103. ///
  104. /// Additionally, there are multiple bit representations for Not a Number, so if you must test if your value
  105. /// is NAN_DBL, use isnan().
  106. /// </summary>
  107. public const double NAN_DBL = Double.NaN;
  108. /// <summary>The smallest positive normal number representable in a float.</summary>
  109. public const float FLT_MIN_NORMAL = 1.175494351e-38F;
  110. /// <summary>The smallest positive normal number representable in a double. This is a f64/double precision constant.</summary>
  111. public const double DBL_MIN_NORMAL = 2.2250738585072014e-308;
  112. /// <summary>The mathematical constant e also known as Euler's number. Approximately 2.72.</summary>
  113. public const float E = (float)E_DBL;
  114. /// <summary>The base 2 logarithm of e. Approximately 1.44.</summary>
  115. public const float LOG2E = (float)LOG2E_DBL;
  116. /// <summary>The base 10 logarithm of e. Approximately 0.43.</summary>
  117. public const float LOG10E = (float)LOG10E_DBL;
  118. /// <summary>The natural logarithm of 2. Approximately 0.69.</summary>
  119. public const float LN2 = (float)LN2_DBL;
  120. /// <summary>The natural logarithm of 10. Approximately 2.30.</summary>
  121. public const float LN10 = (float)LN10_DBL;
  122. /// <summary>The mathematical constant pi. Approximately 3.14.</summary>
  123. public const float PI = (float)PI_DBL;
  124. /// <summary>
  125. /// The mathematical constant (2 * pi). Approximately 6.28. Also known as <see cref="TAU"/>.
  126. /// </summary>
  127. public const float PI2 = (float)PI2_DBL;
  128. /// <summary>
  129. /// The mathematical constant (pi / 2). Approximately 1.57.
  130. /// </summary>
  131. public const float PIHALF = (float)PIHALF_DBL;
  132. /// <summary>
  133. /// The mathematical constant tau. Approximately 6.28. Also known as <see cref="PI2"/>.
  134. /// </summary>
  135. public const float TAU = (float)PI2_DBL;
  136. /// <summary>
  137. /// The conversion constant used to convert radians to degrees. Multiply the radian value by this constant to get degrees.
  138. /// </summary>
  139. /// <remarks>Multiplying by this constant is equivalent to using <see cref="math.degrees(float)"/>.</remarks>
  140. public const float TODEGREES = (float)TODEGREES_DBL;
  141. /// <summary>
  142. /// The conversion constant used to convert degrees to radians. Multiply the degree value by this constant to get radians.
  143. /// </summary>
  144. /// <remarks>Multiplying by this constant is equivalent to using <see cref="math.radians(float)"/>.</remarks>
  145. public const float TORADIANS = (float)TORADIANS_DBL;
  146. /// <summary>The square root 2. Approximately 1.41.</summary>
  147. public const float SQRT2 = (float)SQRT2_DBL;
  148. /// <summary>
  149. /// The difference between 1.0f and the next representable f32/single precision number.
  150. ///
  151. /// Beware:
  152. /// This value is different from System.Single.Epsilon, which is the smallest, positive, denormalized f32/single.
  153. /// </summary>
  154. public const float EPSILON = 1.1920928955078125e-7f;
  155. /// <summary>
  156. /// Single precision constant for positive infinity.
  157. /// </summary>
  158. public const float INFINITY = Single.PositiveInfinity;
  159. /// <summary>
  160. /// Single precision constant for Not a Number.
  161. ///
  162. /// NAN is considered unordered, which means all comparisons involving it are false except for not equal (operator !=).
  163. /// As a consequence, NAN == NAN is false but NAN != NAN is true.
  164. ///
  165. /// Additionally, there are multiple bit representations for Not a Number, so if you must test if your value
  166. /// is NAN, use isnan().
  167. /// </summary>
  168. public const float NAN = Single.NaN;
  169. /// <summary>Returns the bit pattern of a uint as an int.</summary>
  170. /// <param name="x">The uint bits to copy.</param>
  171. /// <returns>The int with the same bit pattern as the input.</returns>
  172. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  173. public static int asint(uint x)
  174. {
  175. unsafe
  176. {
  177. return *(int*)&x;
  178. }
  179. }
  180. /// <summary>Returns the bit pattern of a uint2 as an int2.</summary>
  181. /// <param name="x">The uint2 bits to copy.</param>
  182. /// <returns>The int2 with the same bit pattern as the input.</returns>
  183. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  184. public static int2 asint(uint2 x)
  185. {
  186. unsafe
  187. {
  188. return *(int2*)&x;
  189. }
  190. }
  191. /// <summary>Returns the bit pattern of a uint3 as an int3.</summary>
  192. /// <param name="x">The uint3 bits to copy.</param>
  193. /// <returns>The int3 with the same bit pattern as the input.</returns>
  194. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  195. public static int3 asint(uint3 x)
  196. {
  197. unsafe
  198. {
  199. return *(int3*)&x;
  200. }
  201. }
  202. /// <summary>Returns the bit pattern of a uint4 as an int4.</summary>
  203. /// <param name="x">The uint4 bits to copy.</param>
  204. /// <returns>The int4 with the same bit pattern as the input.</returns>
  205. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  206. public static int4 asint(uint4 x)
  207. {
  208. unsafe
  209. {
  210. return *(int4*)&x;
  211. }
  212. }
  213. /// <summary>Returns the bit pattern of a float as an int.</summary>
  214. /// <param name="x">The float bits to copy.</param>
  215. /// <returns>The int with the same bit pattern as the input.</returns>
  216. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  217. public static int asint(float x)
  218. {
  219. unsafe
  220. {
  221. return *(int*)&x;
  222. }
  223. }
  224. /// <summary>Returns the bit pattern of a float2 as an int2.</summary>
  225. /// <param name="x">The float2 bits to copy.</param>
  226. /// <returns>The int2 with the same bit pattern as the input.</returns>
  227. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  228. public static int2 asint(float2 x)
  229. {
  230. unsafe
  231. {
  232. return *(int2*)&x;
  233. }
  234. }
  235. /// <summary>Returns the bit pattern of a float3 as an int3.</summary>
  236. /// <param name="x">The float3 bits to copy.</param>
  237. /// <returns>The int3 with the same bit pattern as the input.</returns>
  238. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  239. public static int3 asint(float3 x)
  240. {
  241. unsafe
  242. {
  243. return *(int3*)&x;
  244. }
  245. }
  246. /// <summary>Returns the bit pattern of a float4 as an int4.</summary>
  247. /// <param name="x">The float4 bits to copy.</param>
  248. /// <returns>The int4 with the same bit pattern as the input.</returns>
  249. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  250. public static int4 asint(float4 x)
  251. {
  252. unsafe
  253. {
  254. return *(int4*)&x;
  255. }
  256. }
  257. /// <summary>Returns the bit pattern of an int as a uint.</summary>
  258. /// <param name="x">The int bits to copy.</param>
  259. /// <returns>The uint with the same bit pattern as the input.</returns>
  260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  261. public static uint asuint(int x) { return (uint)x; }
  262. /// <summary>Returns the bit pattern of an int2 as a uint2.</summary>
  263. /// <param name="x">The int2 bits to copy.</param>
  264. /// <returns>The uint2 with the same bit pattern as the input.</returns>
  265. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  266. public static uint2 asuint(int2 x)
  267. {
  268. unsafe
  269. {
  270. return *(uint2*)&x;
  271. }
  272. }
  273. /// <summary>Returns the bit pattern of an int3 as a uint3.</summary>
  274. /// <param name="x">The int3 bits to copy.</param>
  275. /// <returns>The uint3 with the same bit pattern as the input.</returns>
  276. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  277. public static uint3 asuint(int3 x)
  278. {
  279. unsafe
  280. {
  281. return *(uint3*)&x;
  282. }
  283. }
  284. /// <summary>Returns the bit pattern of an int4 as a uint4.</summary>
  285. /// <param name="x">The int4 bits to copy.</param>
  286. /// <returns>The uint4 with the same bit pattern as the input.</returns>
  287. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  288. public static uint4 asuint(int4 x)
  289. {
  290. unsafe
  291. {
  292. return *(uint4*)&x;
  293. }
  294. }
  295. /// <summary>Returns the bit pattern of a float as a uint.</summary>
  296. /// <param name="x">The float bits to copy.</param>
  297. /// <returns>The uint with the same bit pattern as the input.</returns>
  298. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  299. public static uint asuint(float x)
  300. {
  301. unsafe
  302. {
  303. return *(uint*)&x;
  304. }
  305. }
  306. /// <summary>Returns the bit pattern of a float2 as a uint2.</summary>
  307. /// <param name="x">The float2 bits to copy.</param>
  308. /// <returns>The uint2 with the same bit pattern as the input.</returns>
  309. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  310. public static uint2 asuint(float2 x)
  311. {
  312. unsafe
  313. {
  314. return *(uint2*)&x;
  315. }
  316. }
  317. /// <summary>Returns the bit pattern of a float3 as a uint3.</summary>
  318. /// <param name="x">The float3 bits to copy.</param>
  319. /// <returns>The uint3 with the same bit pattern as the input.</returns>
  320. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  321. public static uint3 asuint(float3 x)
  322. {
  323. unsafe
  324. {
  325. return *(uint3*)&x;
  326. }
  327. }
  328. /// <summary>Returns the bit pattern of a float4 as a uint4.</summary>
  329. /// <param name="x">The float4 bits to copy.</param>
  330. /// <returns>The uint4 with the same bit pattern as the input.</returns>
  331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  332. public static uint4 asuint(float4 x)
  333. {
  334. unsafe
  335. {
  336. return *(uint4*)&x;
  337. }
  338. }
  339. /// <summary>Returns the bit pattern of a ulong as a long.</summary>
  340. /// <param name="x">The ulong bits to copy.</param>
  341. /// <returns>The long with the same bit pattern as the input.</returns>
  342. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  343. public static long aslong(ulong x) { return (long)x; }
  344. /// <summary>Returns the bit pattern of a double as a long.</summary>
  345. /// <param name="x">The double bits to copy.</param>
  346. /// <returns>The long with the same bit pattern as the input.</returns>
  347. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  348. public static long aslong(double x)
  349. {
  350. unsafe
  351. {
  352. return *(long*)&x;
  353. }
  354. }
  355. /// <summary>Returns the bit pattern of a long as a ulong.</summary>
  356. /// <param name="x">The long bits to copy.</param>
  357. /// <returns>The ulong with the same bit pattern as the input.</returns>
  358. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  359. public static ulong asulong(long x) { return (ulong)x; }
  360. /// <summary>Returns the bit pattern of a double as a ulong.</summary>
  361. /// <param name="x">The double bits to copy.</param>
  362. /// <returns>The ulong with the same bit pattern as the input.</returns>
  363. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  364. public static ulong asulong(double x)
  365. {
  366. unsafe
  367. {
  368. return *(ulong*)&x;
  369. }
  370. }
  371. /// <summary>Returns the bit pattern of an int as a float.</summary>
  372. /// <param name="x">The int bits to copy.</param>
  373. /// <returns>The float with the same bit pattern as the input.</returns>
  374. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  375. public static float asfloat(int x)
  376. {
  377. unsafe
  378. {
  379. return *(float*)&x;
  380. }
  381. }
  382. /// <summary>Returns the bit pattern of an int2 as a float2.</summary>
  383. /// <param name="x">The int2 bits to copy.</param>
  384. /// <returns>The float2 with the same bit pattern as the input.</returns>
  385. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  386. public static float2 asfloat(int2 x)
  387. {
  388. unsafe
  389. {
  390. return *(float2*)&x;
  391. }
  392. }
  393. /// <summary>Returns the bit pattern of an int3 as a float3.</summary>
  394. /// <param name="x">The int3 bits to copy.</param>
  395. /// <returns>The float3 with the same bit pattern as the input.</returns>
  396. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  397. public static float3 asfloat(int3 x)
  398. {
  399. unsafe
  400. {
  401. return *(float3*)&x;
  402. }
  403. }
  404. /// <summary>Returns the bit pattern of an int4 as a float4.</summary>
  405. /// <param name="x">The int4 bits to copy.</param>
  406. /// <returns>The float4 with the same bit pattern as the input.</returns>
  407. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  408. public static float4 asfloat(int4 x)
  409. {
  410. unsafe
  411. {
  412. return *(float4*)&x;
  413. }
  414. }
  415. /// <summary>Returns the bit pattern of a uint as a float.</summary>
  416. /// <param name="x">The uint bits to copy.</param>
  417. /// <returns>The float with the same bit pattern as the input.</returns>
  418. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  419. public static float asfloat(uint x)
  420. {
  421. unsafe
  422. {
  423. return *(float*)&x;
  424. }
  425. }
  426. /// <summary>Returns the bit pattern of a uint2 as a float2.</summary>
  427. /// <param name="x">The uint2 bits to copy.</param>
  428. /// <returns>The float2 with the same bit pattern as the input.</returns>
  429. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  430. public static float2 asfloat(uint2 x)
  431. {
  432. unsafe
  433. {
  434. return *(float2*)&x;
  435. }
  436. }
  437. /// <summary>Returns the bit pattern of a uint3 as a float3.</summary>
  438. /// <param name="x">The uint3 bits to copy.</param>
  439. /// <returns>The float3 with the same bit pattern as the input.</returns>
  440. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  441. public static float3 asfloat(uint3 x)
  442. {
  443. unsafe
  444. {
  445. return *(float3*)&x;
  446. }
  447. }
  448. /// <summary>Returns the bit pattern of a uint4 as a float4.</summary>
  449. /// <param name="x">The uint4 bits to copy.</param>
  450. /// <returns>The float4 with the same bit pattern as the input.</returns>
  451. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  452. public static float4 asfloat(uint4 x)
  453. {
  454. unsafe
  455. {
  456. return *(float4*)&x;
  457. }
  458. }
  459. /// <summary>
  460. /// Returns a bitmask representation of a bool4. Storing one 1 bit per component
  461. /// in LSB order, from lower to higher bits (so 4 bits in total).
  462. /// The component x is stored at bit 0,
  463. /// The component y is stored at bit 1,
  464. /// The component z is stored at bit 2,
  465. /// The component w is stored at bit 3
  466. /// The bool4(x = true, y = true, z = false, w = true) would produce the value 1011 = 0xB
  467. /// </summary>
  468. /// <param name="value">The input bool4 to calculate the bitmask for</param>
  469. /// <returns>A bitmask representation of the bool4, in LSB order</returns>
  470. public static int bitmask(bool4 value)
  471. {
  472. int mask = 0;
  473. if (value.x) mask |= 0x01;
  474. if (value.y) mask |= 0x02;
  475. if (value.z) mask |= 0x04;
  476. if (value.w) mask |= 0x08;
  477. return mask;
  478. }
  479. /// <summary>Returns the bit pattern of a long as a double.</summary>
  480. /// <param name="x">The long bits to copy.</param>
  481. /// <returns>The double with the same bit pattern as the input.</returns>
  482. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  483. public static double asdouble(long x)
  484. {
  485. unsafe
  486. {
  487. return *(double*)&x;
  488. }
  489. }
  490. /// <summary>Returns the bit pattern of a ulong as a double.</summary>
  491. /// <param name="x">The ulong bits to copy.</param>
  492. /// <returns>The double with the same bit pattern as the input.</returns>
  493. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  494. public static double asdouble(ulong x)
  495. {
  496. unsafe
  497. {
  498. return *(double*)&x;
  499. }
  500. }
  501. /// <summary>Returns true if the input float is a finite floating point value, false otherwise.</summary>
  502. /// <param name="x">The float value to test.</param>
  503. /// <returns>True if the float is finite, false otherwise.</returns>
  504. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  505. public static bool isfinite(float x) { return abs(x) < float.PositiveInfinity; }
  506. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a finite floating point value.</summary>
  507. /// <param name="x">The float2 value to test.</param>
  508. /// <returns>A bool2 where it is true in a component if that component is finite, false otherwise.</returns>
  509. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  510. public static bool2 isfinite(float2 x) { return abs(x) < float.PositiveInfinity; }
  511. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a finite floating point value.</summary>
  512. /// <param name="x">The float3 value to test.</param>
  513. /// <returns>A bool3 where it is true in a component if that component is finite, false otherwise.</returns>
  514. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  515. public static bool3 isfinite(float3 x) { return abs(x) < float.PositiveInfinity; }
  516. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a finite floating point value.</summary>
  517. /// <param name="x">The float4 value to test.</param>
  518. /// <returns>A bool4 where it is true in a component if that component is finite, false otherwise.</returns>
  519. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  520. public static bool4 isfinite(float4 x) { return abs(x) < float.PositiveInfinity; }
  521. /// <summary>Returns true if the input double is a finite floating point value, false otherwise.</summary>
  522. /// <param name="x">The double value to test.</param>
  523. /// <returns>True if the double is finite, false otherwise.</returns>
  524. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  525. public static bool isfinite(double x) { return abs(x) < double.PositiveInfinity; }
  526. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a finite floating point value.</summary>
  527. /// <param name="x">The double2 value to test.</param>
  528. /// <returns>A bool2 where it is true in a component if that component is finite, false otherwise.</returns>
  529. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  530. public static bool2 isfinite(double2 x) { return abs(x) < double.PositiveInfinity; }
  531. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a finite floating point value.</summary>
  532. /// <param name="x">The double3 value to test.</param>
  533. /// <returns>A bool3 where it is true in a component if that component is finite, false otherwise.</returns>
  534. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  535. public static bool3 isfinite(double3 x) { return abs(x) < double.PositiveInfinity; }
  536. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a finite floating point value.</summary>
  537. /// <param name="x">The double4 value to test.</param>
  538. /// <returns>A bool4 where it is true in a component if that component is finite, false otherwise.</returns>
  539. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  540. public static bool4 isfinite(double4 x) { return abs(x) < double.PositiveInfinity; }
  541. /// <summary>Returns true if the input float is an infinite floating point value, false otherwise.</summary>
  542. /// <param name="x">Input value.</param>
  543. /// <returns>True if the input was an infinite value; false otherwise.</returns>
  544. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  545. public static bool isinf(float x) { return abs(x) == float.PositiveInfinity; }
  546. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is an infinite floating point value.</summary>
  547. /// <param name="x">Input value.</param>
  548. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  549. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  550. public static bool2 isinf(float2 x) { return abs(x) == float.PositiveInfinity; }
  551. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is an infinite floating point value.</summary>
  552. /// <param name="x">Input value.</param>
  553. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  554. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  555. public static bool3 isinf(float3 x) { return abs(x) == float.PositiveInfinity; }
  556. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is an infinite floating point value.</summary>
  557. /// <param name="x">Input value.</param>
  558. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  559. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  560. public static bool4 isinf(float4 x) { return abs(x) == float.PositiveInfinity; }
  561. /// <summary>Returns true if the input double is an infinite floating point value, false otherwise.</summary>
  562. /// <param name="x">Input value.</param>
  563. /// <returns>True if the input was an infinite value; false otherwise.</returns>
  564. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  565. public static bool isinf(double x) { return abs(x) == double.PositiveInfinity; }
  566. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is an infinite floating point value.</summary>
  567. /// <param name="x">Input value.</param>
  568. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  569. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  570. public static bool2 isinf(double2 x) { return abs(x) == double.PositiveInfinity; }
  571. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is an infinite floating point value.</summary>
  572. /// <param name="x">Input value.</param>
  573. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  574. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  575. public static bool3 isinf(double3 x) { return abs(x) == double.PositiveInfinity; }
  576. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is an infinite floating point value.</summary>
  577. /// <param name="x">Input value.</param>
  578. /// <returns>True if the component was an infinite value; false otherwise.</returns>
  579. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  580. public static bool4 isinf(double4 x) { return abs(x) == double.PositiveInfinity; }
  581. /// <summary>Returns true if the input float is a NaN (not a number) floating point value, false otherwise.</summary>
  582. /// <remarks>
  583. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  584. /// </remarks>
  585. /// <param name="x">Input value.</param>
  586. /// <returns>True if the value was NaN; false otherwise.</returns>
  587. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  588. public static bool isnan(float x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  589. /// <summary>Returns a bool2 indicating for each component of a float2 whether it is a NaN (not a number) floating point value.</summary>
  590. /// <remarks>
  591. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  592. /// </remarks>
  593. /// <param name="x">Input value.</param>
  594. /// <returns>True if the component was NaN; false otherwise.</returns>
  595. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  596. public static bool2 isnan(float2 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  597. /// <summary>Returns a bool3 indicating for each component of a float3 whether it is a NaN (not a number) floating point value.</summary>
  598. /// <remarks>
  599. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  600. /// </remarks>
  601. /// <param name="x">Input value.</param>
  602. /// <returns>True if the component was NaN; false otherwise.</returns>
  603. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  604. public static bool3 isnan(float3 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  605. /// <summary>Returns a bool4 indicating for each component of a float4 whether it is a NaN (not a number) floating point value.</summary>
  606. /// <remarks>
  607. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  608. /// </remarks>
  609. /// <param name="x">Input value.</param>
  610. /// <returns>True if the component was NaN; false otherwise.</returns>
  611. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  612. public static bool4 isnan(float4 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; }
  613. /// <summary>Returns true if the input double is a NaN (not a number) floating point value, false otherwise.</summary>
  614. /// <remarks>
  615. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  616. /// </remarks>
  617. /// <param name="x">Input value.</param>
  618. /// <returns>True if the value was NaN; false otherwise.</returns>
  619. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  620. public static bool isnan(double x) { return (asulong(x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000; }
  621. /// <summary>Returns a bool2 indicating for each component of a double2 whether it is a NaN (not a number) floating point value.</summary>
  622. /// <remarks>
  623. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  624. /// </remarks>
  625. /// <param name="x">Input value.</param>
  626. /// <returns>True if the component was NaN; false otherwise.</returns>
  627. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  628. public static bool2 isnan(double2 x) {
  629. return bool2((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  630. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  631. }
  632. /// <summary>Returns a bool3 indicating for each component of a double3 whether it is a NaN (not a number) floating point value.</summary>
  633. /// <remarks>
  634. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  635. /// </remarks>
  636. /// <param name="x">Input value.</param>
  637. /// <returns>True if the component was NaN; false otherwise.</returns>
  638. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  639. public static bool3 isnan(double3 x)
  640. {
  641. return bool3((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  642. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  643. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  644. }
  645. /// <summary>Returns a bool4 indicating for each component of a double4 whether it is a NaN (not a number) floating point value.</summary>
  646. /// <remarks>
  647. /// NaN has several representations and may vary across architectures. Use this function to check if you have a NaN.
  648. /// </remarks>
  649. /// <param name="x">Input value.</param>
  650. /// <returns>True if the component was NaN; false otherwise.</returns>
  651. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  652. public static bool4 isnan(double4 x)
  653. {
  654. return bool4((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  655. (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  656. (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000,
  657. (asulong(x.w) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
  658. }
  659. /// <summary>
  660. /// Checks if the input is a power of two.
  661. /// </summary>
  662. /// <remarks>If x is less than or equal to zero, then this function returns false.</remarks>
  663. /// <param name="x">Integer input.</param>
  664. /// <returns>bool where true indicates that input was a power of two.</returns>
  665. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  666. public static bool ispow2(int x)
  667. {
  668. return x > 0 && ((x & (x - 1)) == 0);
  669. }
  670. /// <summary>
  671. /// Checks if each component of the input is a power of two.
  672. /// </summary>
  673. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  674. /// <param name="x">int2 input</param>
  675. /// <returns>bool2 where true in a component indicates the same component in the input was a power of two.</returns>
  676. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  677. public static bool2 ispow2(int2 x)
  678. {
  679. return new bool2(ispow2(x.x), ispow2(x.y));
  680. }
  681. /// <summary>
  682. /// Checks if each component of the input is a power of two.
  683. /// </summary>
  684. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  685. /// <param name="x">int3 input</param>
  686. /// <returns>bool3 where true in a component indicates the same component in the input was a power of two.</returns>
  687. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  688. public static bool3 ispow2(int3 x)
  689. {
  690. return new bool3(ispow2(x.x), ispow2(x.y), ispow2(x.z));
  691. }
  692. /// <summary>
  693. /// Checks if each component of the input is a power of two.
  694. /// </summary>
  695. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  696. /// <param name="x">int4 input</param>
  697. /// <returns>bool4 where true in a component indicates the same component in the input was a power of two.</returns>
  698. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  699. public static bool4 ispow2(int4 x)
  700. {
  701. return new bool4(ispow2(x.x), ispow2(x.y), ispow2(x.z), ispow2(x.w));
  702. }
  703. /// <summary>
  704. /// Checks if the input is a power of two.
  705. /// </summary>
  706. /// <remarks>If x is less than or equal to zero, then this function returns false.</remarks>
  707. /// <param name="x">Unsigned integer input.</param>
  708. /// <returns>bool where true indicates that input was a power of two.</returns>
  709. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  710. public static bool ispow2(uint x)
  711. {
  712. return x > 0 && ((x & (x - 1)) == 0);
  713. }
  714. /// <summary>
  715. /// Checks if each component of the input is a power of two.
  716. /// </summary>
  717. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  718. /// <param name="x">uint2 input</param>
  719. /// <returns>bool2 where true in a component indicates the same component in the input was a power of two.</returns>
  720. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  721. public static bool2 ispow2(uint2 x)
  722. {
  723. return new bool2(ispow2(x.x), ispow2(x.y));
  724. }
  725. /// <summary>
  726. /// Checks if each component of the input is a power of two.
  727. /// </summary>
  728. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  729. /// <param name="x">uint3 input</param>
  730. /// <returns>bool3 where true in a component indicates the same component in the input was a power of two.</returns>
  731. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  732. public static bool3 ispow2(uint3 x)
  733. {
  734. return new bool3(ispow2(x.x), ispow2(x.y), ispow2(x.z));
  735. }
  736. /// <summary>
  737. /// Checks if each component of the input is a power of two.
  738. /// </summary>
  739. /// <remarks>If a component of x is less than or equal to zero, then this function returns false in that component.</remarks>
  740. /// <param name="x">uint4 input</param>
  741. /// <returns>bool4 where true in a component indicates the same component in the input was a power of two.</returns>
  742. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  743. public static bool4 ispow2(uint4 x)
  744. {
  745. return new bool4(ispow2(x.x), ispow2(x.y), ispow2(x.z), ispow2(x.w));
  746. }
  747. /// <summary>Returns the minimum of two int values.</summary>
  748. /// <param name="x">The first input value.</param>
  749. /// <param name="y">The second input value.</param>
  750. /// <returns>The minimum of the two input values.</returns>
  751. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  752. public static int min(int x, int y) { return x < y ? x : y; }
  753. /// <summary>Returns the componentwise minimum of two int2 vectors.</summary>
  754. /// <param name="x">The first input value.</param>
  755. /// <param name="y">The second input value.</param>
  756. /// <returns>The componentwise minimum of the two input values.</returns>
  757. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  758. public static int2 min(int2 x, int2 y) { return new int2(min(x.x, y.x), min(x.y, y.y)); }
  759. /// <summary>Returns the componentwise minimum of two int3 vectors.</summary>
  760. /// <param name="x">The first input value.</param>
  761. /// <param name="y">The second input value.</param>
  762. /// <returns>The componentwise minimum of the two input values.</returns>
  763. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  764. 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)); }
  765. /// <summary>Returns the componentwise minimum of two int4 vectors.</summary>
  766. /// <param name="x">The first input value.</param>
  767. /// <param name="y">The second input value.</param>
  768. /// <returns>The componentwise minimum of the two input values.</returns>
  769. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  770. 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)); }
  771. /// <summary>Returns the minimum of two uint values.</summary>
  772. /// <param name="x">The first input value.</param>
  773. /// <param name="y">The second input value.</param>
  774. /// <returns>The minimum of the two input values.</returns>
  775. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  776. public static uint min(uint x, uint y) { return x < y ? x : y; }
  777. /// <summary>Returns the componentwise minimum of two uint2 vectors.</summary>
  778. /// <param name="x">The first input value.</param>
  779. /// <param name="y">The second input value.</param>
  780. /// <returns>The componentwise minimum of the two input values.</returns>
  781. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  782. public static uint2 min(uint2 x, uint2 y) { return new uint2(min(x.x, y.x), min(x.y, y.y)); }
  783. /// <summary>Returns the componentwise minimum of two uint3 vectors.</summary>
  784. /// <param name="x">The first input value.</param>
  785. /// <param name="y">The second input value.</param>
  786. /// <returns>The componentwise minimum of the two input values.</returns>
  787. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  788. 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)); }
  789. /// <summary>Returns the componentwise minimum of two uint4 vectors.</summary>
  790. /// <param name="x">The first input value.</param>
  791. /// <param name="y">The second input value.</param>
  792. /// <returns>The componentwise minimum of the two input values.</returns>
  793. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  794. 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)); }
  795. /// <summary>Returns the minimum of two long values.</summary>
  796. /// <param name="x">The first input value.</param>
  797. /// <param name="y">The second input value.</param>
  798. /// <returns>The minimum of the two input values.</returns>
  799. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  800. public static long min(long x, long y) { return x < y ? x : y; }
  801. /// <summary>Returns the minimum of two ulong values.</summary>
  802. /// <param name="x">The first input value.</param>
  803. /// <param name="y">The second input value.</param>
  804. /// <returns>The minimum of the two input values.</returns>
  805. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  806. public static ulong min(ulong x, ulong y) { return x < y ? x : y; }
  807. /// <summary>Returns the minimum of two float values.</summary>
  808. /// <param name="x">The first input value.</param>
  809. /// <param name="y">The second input value.</param>
  810. /// <returns>The minimum of the two input values.</returns>
  811. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  812. public static float min(float x, float y) { return float.IsNaN(y) || x < y ? x : y; }
  813. /// <summary>Returns the componentwise minimum of two float2 vectors.</summary>
  814. /// <param name="x">The first input value.</param>
  815. /// <param name="y">The second input value.</param>
  816. /// <returns>The componentwise minimum of the two input values.</returns>
  817. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  818. public static float2 min(float2 x, float2 y) { return new float2(min(x.x, y.x), min(x.y, y.y)); }
  819. /// <summary>Returns the componentwise minimum of two float3 vectors.</summary>
  820. /// <param name="x">The first input value.</param>
  821. /// <param name="y">The second input value.</param>
  822. /// <returns>The componentwise minimum of the two input values.</returns>
  823. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  824. 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)); }
  825. /// <summary>Returns the componentwise minimum of two float4 vectors.</summary>
  826. /// <param name="x">The first input value.</param>
  827. /// <param name="y">The second input value.</param>
  828. /// <returns>The componentwise minimum of the two input values.</returns>
  829. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  830. 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)); }
  831. /// <summary>Returns the minimum of two double values.</summary>
  832. /// <param name="x">The first input value.</param>
  833. /// <param name="y">The second input value.</param>
  834. /// <returns>The minimum of the two input values.</returns>
  835. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  836. public static double min(double x, double y) { return double.IsNaN(y) || x < y ? x : y; }
  837. /// <summary>Returns the componentwise minimum of two double2 vectors.</summary>
  838. /// <param name="x">The first input value.</param>
  839. /// <param name="y">The second input value.</param>
  840. /// <returns>The componentwise minimum of the two input values.</returns>
  841. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  842. public static double2 min(double2 x, double2 y) { return new double2(min(x.x, y.x), min(x.y, y.y)); }
  843. /// <summary>Returns the componentwise minimum of two double3 vectors.</summary>
  844. /// <param name="x">The first input value.</param>
  845. /// <param name="y">The second input value.</param>
  846. /// <returns>The componentwise minimum of the two input values.</returns>
  847. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  848. 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)); }
  849. /// <summary>Returns the componentwise minimum of two double4 vectors.</summary>
  850. /// <param name="x">The first input value.</param>
  851. /// <param name="y">The second input value.</param>
  852. /// <returns>The componentwise minimum of the two input values.</returns>
  853. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  854. 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)); }
  855. /// <summary>Returns the maximum of two int values.</summary>
  856. /// <param name="x">The first input value.</param>
  857. /// <param name="y">The second input value.</param>
  858. /// <returns>The maximum of the two input values.</returns>
  859. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  860. public static int max(int x, int y) { return x > y ? x : y; }
  861. /// <summary>Returns the componentwise maximum of two int2 vectors.</summary>
  862. /// <param name="x">The first input value.</param>
  863. /// <param name="y">The second input value.</param>
  864. /// <returns>The componentwise maximum of the two input values.</returns>
  865. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  866. public static int2 max(int2 x, int2 y) { return new int2(max(x.x, y.x), max(x.y, y.y)); }
  867. /// <summary>Returns the componentwise maximum of two int3 vectors.</summary>
  868. /// <param name="x">The first input value.</param>
  869. /// <param name="y">The second input value.</param>
  870. /// <returns>The componentwise maximum of the two input values.</returns>
  871. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  872. 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)); }
  873. /// <summary>Returns the componentwise maximum of two int4 vectors.</summary>
  874. /// <param name="x">The first input value.</param>
  875. /// <param name="y">The second input value.</param>
  876. /// <returns>The componentwise maximum of the two input values.</returns>
  877. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  878. 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)); }
  879. /// <summary>Returns the maximum of two uint values.</summary>
  880. /// <param name="x">The first input value.</param>
  881. /// <param name="y">The second input value.</param>
  882. /// <returns>The maximum of the two input values.</returns>
  883. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  884. public static uint max(uint x, uint y) { return x > y ? x : y; }
  885. /// <summary>Returns the componentwise maximum of two uint2 vectors.</summary>
  886. /// <param name="x">The first input value.</param>
  887. /// <param name="y">The second input value.</param>
  888. /// <returns>The componentwise maximum of the two input values.</returns>
  889. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  890. public static uint2 max(uint2 x, uint2 y) { return new uint2(max(x.x, y.x), max(x.y, y.y)); }
  891. /// <summary>Returns the componentwise maximum of two uint3 vectors.</summary>
  892. /// <param name="x">The first input value.</param>
  893. /// <param name="y">The second input value.</param>
  894. /// <returns>The componentwise maximum of the two input values.</returns>
  895. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  896. 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)); }
  897. /// <summary>Returns the componentwise maximum of two uint4 vectors.</summary>
  898. /// <param name="x">The first input value.</param>
  899. /// <param name="y">The second input value.</param>
  900. /// <returns>The componentwise maximum of the two input values.</returns>
  901. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  902. 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)); }
  903. /// <summary>Returns the maximum of two long values.</summary>
  904. /// <param name="x">The first input value.</param>
  905. /// <param name="y">The second input value.</param>
  906. /// <returns>The maximum of the two input values.</returns>
  907. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  908. public static long max(long x, long y) { return x > y ? x : y; }
  909. /// <summary>Returns the maximum of two ulong values.</summary>
  910. /// <param name="x">The first input value.</param>
  911. /// <param name="y">The second input value.</param>
  912. /// <returns>The maximum of the two input values.</returns>
  913. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  914. public static ulong max(ulong x, ulong y) { return x > y ? x : y; }
  915. /// <summary>Returns the maximum of two float values.</summary>
  916. /// <param name="x">The first input value.</param>
  917. /// <param name="y">The second input value.</param>
  918. /// <returns>The maximum of the two input values.</returns>
  919. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  920. public static float max(float x, float y) { return float.IsNaN(y) || x > y ? x : y; }
  921. /// <summary>Returns the componentwise maximum of two float2 vectors.</summary>
  922. /// <param name="x">The first input value.</param>
  923. /// <param name="y">The second input value.</param>
  924. /// <returns>The componentwise maximum of the two input values.</returns>
  925. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  926. public static float2 max(float2 x, float2 y) { return new float2(max(x.x, y.x), max(x.y, y.y)); }
  927. /// <summary>Returns the componentwise maximum of two float3 vectors.</summary>
  928. /// <param name="x">The first input value.</param>
  929. /// <param name="y">The second input value.</param>
  930. /// <returns>The componentwise maximum of the two input values.</returns>
  931. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  932. 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)); }
  933. /// <summary>Returns the componentwise maximum of two float4 vectors.</summary>
  934. /// <param name="x">The first input value.</param>
  935. /// <param name="y">The second input value.</param>
  936. /// <returns>The componentwise maximum of the two input values.</returns>
  937. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  938. 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)); }
  939. /// <summary>Returns the maximum of two double values.</summary>
  940. /// <param name="x">The first input value.</param>
  941. /// <param name="y">The second input value.</param>
  942. /// <returns>The maximum of the two input values.</returns>
  943. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  944. public static double max(double x, double y) { return double.IsNaN(y) || x > y ? x : y; }
  945. /// <summary>Returns the componentwise maximum of two double2 vectors.</summary>
  946. /// <param name="x">The first input value.</param>
  947. /// <param name="y">The second input value.</param>
  948. /// <returns>The componentwise maximum of the two input values.</returns>
  949. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  950. public static double2 max(double2 x, double2 y) { return new double2(max(x.x, y.x), max(x.y, y.y)); }
  951. /// <summary>Returns the componentwise maximum of two double3 vectors.</summary>
  952. /// <param name="x">The first input value.</param>
  953. /// <param name="y">The second input value.</param>
  954. /// <returns>The componentwise maximum of the two input values.</returns>
  955. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  956. 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)); }
  957. /// <summary>Returns the componentwise maximum of two double4 vectors.</summary>
  958. /// <param name="x">The first input value.</param>
  959. /// <param name="y">The second input value.</param>
  960. /// <returns>The componentwise maximum of the two input values.</returns>
  961. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  962. 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)); }
  963. /// <summary>Returns the result of linearly interpolating from start to end using the interpolation parameter t.</summary>
  964. /// <remarks>
  965. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  966. /// </remarks>
  967. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  968. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  969. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  970. /// <returns>The interpolation from start to end.</returns>
  971. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  972. public static float lerp(float start, float end, float t) { return start + t * (end - start); }
  973. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  974. /// <remarks>
  975. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  976. /// </remarks>
  977. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  978. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  979. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  980. /// <returns>The componentwise interpolation from x to y.</returns>
  981. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  982. public static float2 lerp(float2 start, float2 end, float t) { return start + t * (end - start); }
  983. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  984. /// <remarks>
  985. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  986. /// </remarks>
  987. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  988. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  989. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  990. /// <returns>The componentwise interpolation from x to y.</returns>
  991. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  992. public static float3 lerp(float3 start, float3 end, float t) { return start + t * (end - start); }
  993. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  994. /// <remarks>
  995. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  996. /// </remarks>
  997. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  998. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  999. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1000. /// <returns>The componentwise interpolation from x to y.</returns>
  1001. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1002. public static float4 lerp(float4 start, float4 end, float t) { return start + t * (end - start); }
  1003. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1004. /// <remarks>
  1005. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1006. /// </remarks>
  1007. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1008. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1009. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1010. /// <returns>The componentwise interpolation from x to y.</returns>
  1011. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1012. public static float2 lerp(float2 start, float2 end, float2 t) { return start + t * (end - start); }
  1013. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1014. /// <remarks>
  1015. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1016. /// </remarks>
  1017. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1018. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1019. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1020. /// <returns>The componentwise interpolation from x to y.</returns>
  1021. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1022. public static float3 lerp(float3 start, float3 end, float3 t) { return start + t * (end - start); }
  1023. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1024. /// <remarks>
  1025. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1026. /// </remarks>
  1027. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1028. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1029. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1030. /// <returns>The componentwise interpolation from x to y.</returns>
  1031. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1032. public static float4 lerp(float4 start, float4 end, float4 t) { return start + t * (end - start); }
  1033. /// <summary>Returns the result of linearly interpolating from x to y using the interpolation parameter t.</summary>
  1034. /// <remarks>
  1035. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1036. /// </remarks>
  1037. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1038. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1039. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1040. /// <returns>The interpolation from x to y.</returns>
  1041. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1042. public static double lerp(double start, double end, double t) { return start + t * (end - start); }
  1043. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  1044. /// <remarks>
  1045. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1046. /// </remarks>
  1047. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1048. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1049. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1050. /// <returns>The componentwise interpolation from x to y.</returns>
  1051. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1052. public static double2 lerp(double2 start, double2 end, double t) { return start + t * (end - start); }
  1053. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  1054. /// <remarks>
  1055. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1056. /// </remarks>
  1057. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1058. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1059. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1060. /// <returns>The componentwise interpolation from x to y.</returns>
  1061. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1062. public static double3 lerp(double3 start, double3 end, double t) { return start + t * (end - start); }
  1063. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter t.</summary>
  1064. /// <remarks>
  1065. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1066. /// </remarks>
  1067. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1068. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1069. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1070. /// <returns>The componentwise interpolation from x to y.</returns>
  1071. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1072. public static double4 lerp(double4 start, double4 end, double t) { return start + t * (end - start); }
  1073. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1074. /// <remarks>
  1075. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1076. /// </remarks>
  1077. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1078. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1079. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1080. /// <returns>The componentwise interpolation from x to y.</returns>
  1081. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1082. public static double2 lerp(double2 start, double2 end, double2 t) { return start + t * (end - start); }
  1083. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1084. /// <remarks>
  1085. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1086. /// </remarks>
  1087. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1088. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1089. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1090. /// <returns>The componentwise interpolation from x to y.</returns>
  1091. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1092. public static double3 lerp(double3 start, double3 end, double3 t) { return start + t * (end - start); }
  1093. /// <summary>Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter t.</summary>
  1094. /// <remarks>
  1095. /// If the interpolation parameter is not in the range [0, 1], then this function extrapolates.
  1096. /// </remarks>
  1097. /// <param name="start">The start point, corresponding to the interpolation parameter value of 0.</param>
  1098. /// <param name="end">The end point, corresponding to the interpolation parameter value of 1.</param>
  1099. /// <param name="t">The interpolation parameter. May be a value outside the interval [0, 1].</param>
  1100. /// <returns>The componentwise interpolation from x to y.</returns>
  1101. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1102. public static double4 lerp(double4 start, double4 end, double4 t) { return start + t * (end - start); }
  1103. /// <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>
  1104. /// <param name="start">The start point of the range.</param>
  1105. /// <param name="end">The end point of the range.</param>
  1106. /// <param name="x">The value to normalize to the range.</param>
  1107. /// <returns>The interpolation parameter of x with respect to the input range [a, b].</returns>
  1108. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1109. public static float unlerp(float start, float end, float x) { return (x - start) / (end - start); }
  1110. /// <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>
  1111. /// <param name="start">The start point of the range.</param>
  1112. /// <param name="end">The end point of the range.</param>
  1113. /// <param name="x">The value to normalize to the range.</param>
  1114. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1115. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1116. public static float2 unlerp(float2 start, float2 end, float2 x) { return (x - start) / (end - start); }
  1117. /// <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>
  1118. /// <param name="start">The start point of the range.</param>
  1119. /// <param name="end">The end point of the range.</param>
  1120. /// <param name="x">The value to normalize to the range.</param>
  1121. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1122. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1123. public static float3 unlerp(float3 start, float3 end, float3 x) { return (x - start) / (end - start); }
  1124. /// <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>
  1125. /// <param name="start">The start point of the range.</param>
  1126. /// <param name="end">The end point of the range.</param>
  1127. /// <param name="x">The value to normalize to the range.</param>
  1128. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1129. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1130. public static float4 unlerp(float4 start, float4 end, float4 x) { return (x - start) / (end - start); }
  1131. /// <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>
  1132. /// <param name="start">The start point of the range.</param>
  1133. /// <param name="end">The end point of the range.</param>
  1134. /// <param name="x">The value to normalize to the range.</param>
  1135. /// <returns>The interpolation parameter of x with respect to the input range [a, b].</returns>
  1136. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1137. public static double unlerp(double start, double end, double x) { return (x - start) / (end - start); }
  1138. /// <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>
  1139. /// <param name="start">The start point of the range.</param>
  1140. /// <param name="end">The end point of the range.</param>
  1141. /// <param name="x">The value to normalize to the range.</param>
  1142. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1143. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1144. public static double2 unlerp(double2 start, double2 end, double2 x) { return (x - start) / (end - start); }
  1145. /// <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>
  1146. /// <param name="start">The start point of the range.</param>
  1147. /// <param name="end">The end point of the range.</param>
  1148. /// <param name="x">The value to normalize to the range.</param>
  1149. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1150. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1151. public static double3 unlerp(double3 start, double3 end, double3 x) { return (x - start) / (end - start); }
  1152. /// <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>
  1153. /// <param name="start">The start point of the range.</param>
  1154. /// <param name="end">The end point of the range.</param>
  1155. /// <param name="x">The value to normalize to the range.</param>
  1156. /// <returns>The componentwise interpolation parameter of x with respect to the input range [a, b].</returns>
  1157. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1158. public static double4 unlerp(double4 start, double4 end, double4 x) { return (x - start) / (end - start); }
  1159. /// <summary>Returns the result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1160. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1161. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1162. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1163. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1164. /// <param name="x">The value to remap from the source to destination range.</param>
  1165. /// <returns>The remap of input x from the source range to the destination range.</returns>
  1166. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1167. public static float remap(float srcStart, float srcEnd, float dstStart, float dstEnd, float x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1168. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1169. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1170. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1171. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1172. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1173. /// <param name="x">The value to remap from the source to destination range.</param>
  1174. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1175. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1176. public static float2 remap(float2 srcStart, float2 srcEnd, float2 dstStart, float2 dstEnd, float2 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1177. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1178. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1179. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1180. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1181. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1182. /// <param name="x">The value to remap from the source to destination range.</param>
  1183. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1184. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1185. public static float3 remap(float3 srcStart, float3 srcEnd, float3 dstStart, float3 dstEnd, float3 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1186. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1187. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1188. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1189. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1190. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1191. /// <param name="x">The value to remap from the source to destination range.</param>
  1192. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1193. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1194. public static float4 remap(float4 srcStart, float4 srcEnd, float4 dstStart, float4 dstEnd, float4 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1195. /// <summary>Returns the result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1196. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1197. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1198. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1199. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1200. /// <param name="x">The value to remap from the source to destination range.</param>
  1201. /// <returns>The remap of input x from the source range to the destination range.</returns>
  1202. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1203. public static double remap(double srcStart, double srcEnd, double dstStart, double dstEnd, double x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1204. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1205. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1206. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1207. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1208. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1209. /// <param name="x">The value to remap from the source to destination range.</param>
  1210. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1211. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1212. public static double2 remap(double2 srcStart, double2 srcEnd, double2 dstStart, double2 dstEnd, double2 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1213. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1214. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1215. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1216. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1217. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1218. /// <param name="x">The value to remap from the source to destination range.</param>
  1219. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1220. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1221. public static double3 remap(double3 srcStart, double3 srcEnd, double3 dstStart, double3 dstEnd, double3 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1222. /// <summary>Returns the componentwise result of a non-clamping linear remapping of a value x from source range [srcStart, srcEnd] to the destination range [dstStart, dstEnd].</summary>
  1223. /// <param name="srcStart">The start point of the source range [srcStart, srcEnd].</param>
  1224. /// <param name="srcEnd">The end point of the source range [srcStart, srcEnd].</param>
  1225. /// <param name="dstStart">The start point of the destination range [dstStart, dstEnd].</param>
  1226. /// <param name="dstEnd">The end point of the destination range [dstStart, dstEnd].</param>
  1227. /// <param name="x">The value to remap from the source to destination range.</param>
  1228. /// <returns>The componentwise remap of input x from the source range to the destination range.</returns>
  1229. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1230. public static double4 remap(double4 srcStart, double4 srcEnd, double4 dstStart, double4 dstEnd, double4 x) { return lerp(dstStart, dstEnd, unlerp(srcStart, srcEnd, x)); }
  1231. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 int values.</summary>
  1232. /// <param name="mulA">First value to multiply.</param>
  1233. /// <param name="mulB">Second value to multiply.</param>
  1234. /// <param name="addC">Third value to add to the product of a and b.</param>
  1235. /// <returns>The multiply-add of the inputs.</returns>
  1236. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1237. public static int mad(int mulA, int mulB, int addC) { return mulA * mulB + addC; }
  1238. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int2 vectors.</summary>
  1239. /// <param name="mulA">First value to multiply.</param>
  1240. /// <param name="mulB">Second value to multiply.</param>
  1241. /// <param name="addC">Third value to add to the product of a and b.</param>
  1242. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1243. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1244. public static int2 mad(int2 mulA, int2 mulB, int2 addC) { return mulA * mulB + addC; }
  1245. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int3 vectors.</summary>
  1246. /// <param name="mulA">First value to multiply.</param>
  1247. /// <param name="mulB">Second value to multiply.</param>
  1248. /// <param name="addC">Third value to add to the product of a and b.</param>
  1249. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1250. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1251. public static int3 mad(int3 mulA, int3 mulB, int3 addC) { return mulA * mulB + addC; }
  1252. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int4 vectors.</summary>
  1253. /// <param name="mulA">First value to multiply.</param>
  1254. /// <param name="mulB">Second value to multiply.</param>
  1255. /// <param name="addC">Third value to add to the product of a and b.</param>
  1256. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1258. public static int4 mad(int4 mulA, int4 mulB, int4 addC) { return mulA * mulB + addC; }
  1259. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 uint values.</summary>
  1260. /// <param name="mulA">First value to multiply.</param>
  1261. /// <param name="mulB">Second value to multiply.</param>
  1262. /// <param name="addC">Third value to add to the product of a and b.</param>
  1263. /// <returns>The multiply-add of the inputs.</returns>
  1264. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1265. public static uint mad(uint mulA, uint mulB, uint addC) { return mulA * mulB + addC; }
  1266. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint2 vectors.</summary>
  1267. /// <param name="mulA">First value to multiply.</param>
  1268. /// <param name="mulB">Second value to multiply.</param>
  1269. /// <param name="addC">Third value to add to the product of a and b.</param>
  1270. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1271. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1272. public static uint2 mad(uint2 mulA, uint2 mulB, uint2 addC) { return mulA * mulB + addC; }
  1273. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint3 vectors.</summary>
  1274. /// <param name="mulA">First value to multiply.</param>
  1275. /// <param name="mulB">Second value to multiply.</param>
  1276. /// <param name="addC">Third value to add to the product of a and b.</param>
  1277. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1278. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1279. public static uint3 mad(uint3 mulA, uint3 mulB, uint3 addC) { return mulA * mulB + addC; }
  1280. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint4 vectors.</summary>
  1281. /// <param name="mulA">First value to multiply.</param>
  1282. /// <param name="mulB">Second value to multiply.</param>
  1283. /// <param name="addC">Third value to add to the product of a and b.</param>
  1284. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1285. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1286. public static uint4 mad(uint4 mulA, uint4 mulB, uint4 addC) { return mulA * mulB + addC; }
  1287. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 long values.</summary>
  1288. /// <param name="mulA">First value to multiply.</param>
  1289. /// <param name="mulB">Second value to multiply.</param>
  1290. /// <param name="addC">Third value to add to the product of a and b.</param>
  1291. /// <returns>The multiply-add of the inputs.</returns>
  1292. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1293. public static long mad(long mulA, long mulB, long addC) { return mulA * mulB + addC; }
  1294. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 ulong values.</summary>
  1295. /// <param name="mulA">First value to multiply.</param>
  1296. /// <param name="mulB">Second value to multiply.</param>
  1297. /// <param name="addC">Third value to add to the product of a and b.</param>
  1298. /// <returns>The multiply-add of the inputs.</returns>
  1299. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1300. public static ulong mad(ulong mulA, ulong mulB, ulong addC) { return mulA * mulB + addC; }
  1301. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 float values.</summary>
  1302. /// <remarks>
  1303. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1304. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1305. /// this computation is not fused.
  1306. /// </remarks>
  1307. /// <param name="mulA">First value to multiply.</param>
  1308. /// <param name="mulB">Second value to multiply.</param>
  1309. /// <param name="addC">Third value to add to the product of a and b.</param>
  1310. /// <returns>The multiply-add of the inputs.</returns>
  1311. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1312. public static float mad(float mulA, float mulB, float addC) { return mulA * mulB + addC; }
  1313. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float2 vectors.</summary>
  1314. /// <remarks>
  1315. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1316. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1317. /// this computation is not fused.
  1318. /// </remarks>
  1319. /// <param name="mulA">First value to multiply.</param>
  1320. /// <param name="mulB">Second value to multiply.</param>
  1321. /// <param name="addC">Third value to add to the product of a and b.</param>
  1322. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1323. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1324. public static float2 mad(float2 mulA, float2 mulB, float2 addC) { return mulA * mulB + addC; }
  1325. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float3 vectors.</summary>
  1326. /// <remarks>
  1327. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1328. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1329. /// this computation is not fused.
  1330. /// </remarks>
  1331. /// <param name="mulA">First value to multiply.</param>
  1332. /// <param name="mulB">Second value to multiply.</param>
  1333. /// <param name="addC">Third value to add to the product of a and b.</param>
  1334. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1335. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1336. public static float3 mad(float3 mulA, float3 mulB, float3 addC) { return mulA * mulB + addC; }
  1337. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float4 vectors.</summary>
  1338. /// <remarks>
  1339. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1340. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1341. /// this computation is not fused.
  1342. /// </remarks>
  1343. /// <param name="mulA">First value to multiply.</param>
  1344. /// <param name="mulB">Second value to multiply.</param>
  1345. /// <param name="addC">Third value to add to the product of a and b.</param>
  1346. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1347. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1348. public static float4 mad(float4 mulA, float4 mulB, float4 addC) { return mulA * mulB + addC; }
  1349. /// <summary>Returns the result of a multiply-add operation (a * b + c) on 3 double values.</summary>
  1350. /// <remarks>
  1351. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1352. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1353. /// this computation is not fused.
  1354. /// </remarks>
  1355. /// <param name="mulA">First value to multiply.</param>
  1356. /// <param name="mulB">Second value to multiply.</param>
  1357. /// <param name="addC">Third value to add to the product of a and b.</param>
  1358. /// <returns>The multiply-add of the inputs.</returns>
  1359. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1360. public static double mad(double mulA, double mulB, double addC) { return mulA * mulB + addC; }
  1361. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double2 vectors.</summary>
  1362. /// <remarks>
  1363. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1364. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1365. /// this computation is not fused.
  1366. /// </remarks>
  1367. /// <param name="mulA">First value to multiply.</param>
  1368. /// <param name="mulB">Second value to multiply.</param>
  1369. /// <param name="addC">Third value to add to the product of a and b.</param>
  1370. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1371. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1372. public static double2 mad(double2 mulA, double2 mulB, double2 addC) { return mulA * mulB + addC; }
  1373. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double3 vectors.</summary>
  1374. /// <remarks>
  1375. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1376. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1377. /// this computation is not fused.
  1378. /// </remarks>
  1379. /// <param name="mulA">First value to multiply.</param>
  1380. /// <param name="mulB">Second value to multiply.</param>
  1381. /// <param name="addC">Third value to add to the product of a and b.</param>
  1382. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1383. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1384. public static double3 mad(double3 mulA, double3 mulB, double3 addC) { return mulA * mulB + addC; }
  1385. /// <summary>Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double4 vectors.</summary>
  1386. /// <remarks>
  1387. /// When Burst compiled with fast math enabled on some architectures, this could be converted to a fused multiply add (FMA).
  1388. /// FMA is more accurate due to rounding once at the end of the computation rather than twice that is required when
  1389. /// this computation is not fused.
  1390. /// </remarks>
  1391. /// <param name="mulA">First value to multiply.</param>
  1392. /// <param name="mulB">Second value to multiply.</param>
  1393. /// <param name="addC">Third value to add to the product of a and b.</param>
  1394. /// <returns>The componentwise multiply-add of the inputs.</returns>
  1395. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1396. public static double4 mad(double4 mulA, double4 mulB, double4 addC) { return mulA * mulB + addC; }
  1397. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int values.</summary>
  1398. /// <param name="valueToClamp">Input value to be clamped.</param>
  1399. /// <param name="lowerBound">Lower bound of the interval.</param>
  1400. /// <param name="upperBound">Upper bound of the interval.</param>
  1401. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1402. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1403. public static int clamp(int valueToClamp, int lowerBound, int upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1404. /// <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>
  1405. /// <param name="valueToClamp">Input value to be clamped.</param>
  1406. /// <param name="lowerBound">Lower bound of the interval.</param>
  1407. /// <param name="upperBound">Upper bound of the interval.</param>
  1408. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1409. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1410. public static int2 clamp(int2 valueToClamp, int2 lowerBound, int2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1411. /// <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>
  1412. /// <param name="valueToClamp">Input value to be clamped.</param>
  1413. /// <param name="lowerBound">Lower bound of the interval.</param>
  1414. /// <param name="upperBound">Upper bound of the interval.</param>
  1415. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1416. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1417. public static int3 clamp(int3 valueToClamp, int3 lowerBound, int3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1418. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are int4 vectors.</summary>
  1419. /// <param name="valueToClamp">Input value to be clamped.</param>
  1420. /// <param name="lowerBound">Lower bound of the interval.</param>
  1421. /// <param name="upperBound">Upper bound of the interval.</param>
  1422. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1423. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1424. public static int4 clamp(int4 valueToClamp, int4 lowerBound, int4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1425. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint values.</summary>
  1426. /// <param name="valueToClamp">Input value to be clamped.</param>
  1427. /// <param name="lowerBound">Lower bound of the interval.</param>
  1428. /// <param name="upperBound">Upper bound of the interval.</param>
  1429. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1430. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1431. public static uint clamp(uint valueToClamp, uint lowerBound, uint upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1432. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint2 vectors.</summary>
  1433. /// <param name="valueToClamp">Input value to be clamped.</param>
  1434. /// <param name="lowerBound">Lower bound of the interval.</param>
  1435. /// <param name="upperBound">Upper bound of the interval.</param>
  1436. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1437. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1438. public static uint2 clamp(uint2 valueToClamp, uint2 lowerBound, uint2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1439. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint3 vectors.</summary>
  1440. /// <param name="valueToClamp">Input value to be clamped.</param>
  1441. /// <param name="lowerBound">Lower bound of the interval.</param>
  1442. /// <param name="upperBound">Upper bound of the interval.</param>
  1443. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1444. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1445. public static uint3 clamp(uint3 valueToClamp, uint3 lowerBound, uint3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1446. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are uint4 vectors.</summary>
  1447. /// <param name="valueToClamp">Input value to be clamped.</param>
  1448. /// <param name="lowerBound">Lower bound of the interval.</param>
  1449. /// <param name="upperBound">Upper bound of the interval.</param>
  1450. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1451. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1452. public static uint4 clamp(uint4 valueToClamp, uint4 lowerBound, uint4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1453. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are long values.</summary>
  1454. /// <param name="valueToClamp">Input value to be clamped.</param>
  1455. /// <param name="lowerBound">Lower bound of the interval.</param>
  1456. /// <param name="upperBound">Upper bound of the interval.</param>
  1457. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1458. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1459. public static long clamp(long valueToClamp, long lowerBound, long upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1460. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are ulong values.</summary>
  1461. /// <param name="valueToClamp">Input value to be clamped.</param>
  1462. /// <param name="lowerBound">Lower bound of the interval.</param>
  1463. /// <param name="upperBound">Upper bound of the interval.</param>
  1464. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1465. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1466. public static ulong clamp(ulong valueToClamp, ulong lowerBound, ulong upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1467. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float values.</summary>
  1468. /// <param name="valueToClamp">Input value to be clamped.</param>
  1469. /// <param name="lowerBound">Lower bound of the interval.</param>
  1470. /// <param name="upperBound">Upper bound of the interval.</param>
  1471. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1472. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1473. public static float clamp(float valueToClamp, float lowerBound, float upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1474. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float2 vectors.</summary>
  1475. /// <param name="valueToClamp">Input value to be clamped.</param>
  1476. /// <param name="lowerBound">Lower bound of the interval.</param>
  1477. /// <param name="upperBound">Upper bound of the interval.</param>
  1478. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1479. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1480. public static float2 clamp(float2 valueToClamp, float2 lowerBound, float2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1481. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float3 vectors.</summary>
  1482. /// <param name="valueToClamp">Input value to be clamped.</param>
  1483. /// <param name="lowerBound">Lower bound of the interval.</param>
  1484. /// <param name="upperBound">Upper bound of the interval.</param>
  1485. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1486. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1487. public static float3 clamp(float3 valueToClamp, float3 lowerBound, float3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1488. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are float4 vectors.</summary>
  1489. /// <param name="valueToClamp">Input value to be clamped.</param>
  1490. /// <param name="lowerBound">Lower bound of the interval.</param>
  1491. /// <param name="upperBound">Upper bound of the interval.</param>
  1492. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1493. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1494. public static float4 clamp(float4 valueToClamp, float4 lowerBound, float4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1495. /// <summary>Returns the result of clamping the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double values.</summary>
  1496. /// <param name="valueToClamp">Input value to be clamped.</param>
  1497. /// <param name="lowerBound">Lower bound of the interval.</param>
  1498. /// <param name="upperBound">Upper bound of the interval.</param>
  1499. /// <returns>The clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1500. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1501. public static double clamp(double valueToClamp, double lowerBound, double upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1502. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double2 vectors.</summary>
  1503. /// <param name="valueToClamp">Input value to be clamped.</param>
  1504. /// <param name="lowerBound">Lower bound of the interval.</param>
  1505. /// <param name="upperBound">Upper bound of the interval.</param>
  1506. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1507. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1508. public static double2 clamp(double2 valueToClamp, double2 lowerBound, double2 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1509. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double3 vectors.</summary>
  1510. /// <param name="valueToClamp">Input value to be clamped.</param>
  1511. /// <param name="lowerBound">Lower bound of the interval.</param>
  1512. /// <param name="upperBound">Upper bound of the interval.</param>
  1513. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1514. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1515. public static double3 clamp(double3 valueToClamp, double3 lowerBound, double3 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1516. /// <summary>Returns the result of a componentwise clamping of the value valueToClamp into the interval (inclusive) [lowerBound, upperBound], where valueToClamp, lowerBound and upperBound are double4 vectors.</summary>
  1517. /// <param name="valueToClamp">Input value to be clamped.</param>
  1518. /// <param name="lowerBound">Lower bound of the interval.</param>
  1519. /// <param name="upperBound">Upper bound of the interval.</param>
  1520. /// <returns>The componentwise clamping of the input valueToClamp into the interval (inclusive) [lowerBound, upperBound].</returns>
  1521. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1522. public static double4 clamp(double4 valueToClamp, double4 lowerBound, double4 upperBound) { return max(lowerBound, min(upperBound, valueToClamp)); }
  1523. /// <summary>Returns the result of clamping the float value x into the interval [0, 1].</summary>
  1524. /// <param name="x">Input value.</param>
  1525. /// <returns>The clamping of the input into the interval [0, 1].</returns>
  1526. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1527. public static float saturate(float x) { return clamp(x, 0.0f, 1.0f); }
  1528. /// <summary>Returns the result of a componentwise clamping of the float2 vector x into the interval [0, 1].</summary>
  1529. /// <param name="x">Input value.</param>
  1530. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1531. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1532. public static float2 saturate(float2 x) { return clamp(x, new float2(0.0f), new float2(1.0f)); }
  1533. /// <summary>Returns the result of a componentwise clamping of the float3 vector x into the interval [0, 1].</summary>
  1534. /// <param name="x">Input value.</param>
  1535. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1536. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1537. public static float3 saturate(float3 x) { return clamp(x, new float3(0.0f), new float3(1.0f)); }
  1538. /// <summary>Returns the result of a componentwise clamping of the float4 vector x into the interval [0, 1].</summary>
  1539. /// <param name="x">Input value.</param>
  1540. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1541. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1542. public static float4 saturate(float4 x) { return clamp(x, new float4(0.0f), new float4(1.0f)); }
  1543. /// <summary>Returns the result of clamping the double value x into the interval [0, 1].</summary>
  1544. /// <param name="x">Input value.</param>
  1545. /// <returns>The clamping of the input into the interval [0, 1].</returns>
  1546. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1547. public static double saturate(double x) { return clamp(x, 0.0, 1.0); }
  1548. /// <summary>Returns the result of a componentwise clamping of the double2 vector x into the interval [0, 1].</summary>
  1549. /// <param name="x">Input value.</param>
  1550. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1551. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1552. public static double2 saturate(double2 x) { return clamp(x, new double2(0.0), new double2(1.0)); }
  1553. /// <summary>Returns the result of a componentwise clamping of the double3 vector x into the interval [0, 1].</summary>
  1554. /// <param name="x">Input value.</param>
  1555. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1556. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1557. public static double3 saturate(double3 x) { return clamp(x, new double3(0.0), new double3(1.0)); }
  1558. /// <summary>Returns the result of a componentwise clamping of the double4 vector x into the interval [0, 1].</summary>
  1559. /// <param name="x">Input value.</param>
  1560. /// <returns>The componentwise clamping of the input into the interval [0, 1].</returns>
  1561. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1562. public static double4 saturate(double4 x) { return clamp(x, new double4(0.0), new double4(1.0)); }
  1563. /// <summary>Returns the absolute value of a int value.</summary>
  1564. /// <param name="x">Input value.</param>
  1565. /// <returns>The absolute value of the input.</returns>
  1566. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1567. public static int abs(int x) { return max(-x, x); }
  1568. /// <summary>Returns the componentwise absolute value of a int2 vector.</summary>
  1569. /// <param name="x">Input value.</param>
  1570. /// <returns>The componentwise absolute value of the input.</returns>
  1571. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1572. public static int2 abs(int2 x) { return max(-x, x); }
  1573. /// <summary>Returns the componentwise absolute value of a int3 vector.</summary>
  1574. /// <param name="x">Input value.</param>
  1575. /// <returns>The componentwise absolute value of the input.</returns>
  1576. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1577. public static int3 abs(int3 x) { return max(-x, x); }
  1578. /// <summary>Returns the componentwise absolute value of a int4 vector.</summary>
  1579. /// <param name="x">Input value.</param>
  1580. /// <returns>The componentwise absolute value of the input.</returns>
  1581. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1582. public static int4 abs(int4 x) { return max(-x, x); }
  1583. /// <summary>Returns the absolute value of a long value.</summary>
  1584. /// <param name="x">Input value.</param>
  1585. /// <returns>The absolute value of the input.</returns>
  1586. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1587. public static long abs(long x) { return max(-x, x); }
  1588. /// <summary>Returns the absolute value of a float value.</summary>
  1589. /// <param name="x">Input value.</param>
  1590. /// <returns>The absolute value of the input.</returns>
  1591. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1592. public static float abs(float x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1593. /// <summary>Returns the componentwise absolute value of a float2 vector.</summary>
  1594. /// <param name="x">Input value.</param>
  1595. /// <returns>The componentwise absolute value of the input.</returns>
  1596. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1597. public static float2 abs(float2 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1598. /// <summary>Returns the componentwise absolute value of a float3 vector.</summary>
  1599. /// <param name="x">Input value.</param>
  1600. /// <returns>The componentwise absolute value of the input.</returns>
  1601. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1602. public static float3 abs(float3 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1603. /// <summary>Returns the componentwise absolute value of a float4 vector.</summary>
  1604. /// <param name="x">Input value.</param>
  1605. /// <returns>The componentwise absolute value of the input.</returns>
  1606. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1607. public static float4 abs(float4 x) { return asfloat(asuint(x) & 0x7FFFFFFF); }
  1608. /// <summary>Returns the absolute value of a double value.</summary>
  1609. /// <param name="x">Input value.</param>
  1610. /// <returns>The absolute value of the input.</returns>
  1611. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1612. public static double abs(double x) { return asdouble(asulong(x) & 0x7FFFFFFFFFFFFFFF); }
  1613. /// <summary>Returns the componentwise absolute value of a double2 vector.</summary>
  1614. /// <param name="x">Input value.</param>
  1615. /// <returns>The componentwise absolute value of the input.</returns>
  1616. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1617. public static double2 abs(double2 x) { return double2(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF)); }
  1618. /// <summary>Returns the componentwise absolute value of a double3 vector.</summary>
  1619. /// <param name="x">Input value.</param>
  1620. /// <returns>The componentwise absolute value of the input.</returns>
  1621. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1622. public static double3 abs(double3 x) { return double3(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.z) & 0x7FFFFFFFFFFFFFFF)); }
  1623. /// <summary>Returns the componentwise absolute value of a double4 vector.</summary>
  1624. /// <param name="x">Input value.</param>
  1625. /// <returns>The componentwise absolute value of the input.</returns>
  1626. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1627. 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)); }
  1628. /// <summary>Returns the dot product of two int values. Equivalent to multiplication.</summary>
  1629. /// <param name="x">The first value.</param>
  1630. /// <param name="y">The second value.</param>
  1631. /// <returns>The dot product of two values.</returns>
  1632. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1633. public static int dot(int x, int y) { return x * y; }
  1634. /// <summary>Returns the dot product of two int2 vectors.</summary>
  1635. /// <param name="x">The first vector.</param>
  1636. /// <param name="y">The second vector.</param>
  1637. /// <returns>The dot product of two vectors.</returns>
  1638. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1639. public static int dot(int2 x, int2 y) { return x.x * y.x + x.y * y.y; }
  1640. /// <summary>Returns the dot product of two int3 vectors.</summary>
  1641. /// <param name="x">The first vector.</param>
  1642. /// <param name="y">The second vector.</param>
  1643. /// <returns>The dot product of two vectors.</returns>
  1644. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1645. public static int dot(int3 x, int3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1646. /// <summary>Returns the dot product of two int4 vectors.</summary>
  1647. /// <param name="x">The first vector.</param>
  1648. /// <param name="y">The second vector.</param>
  1649. /// <returns>The dot product of two vectors.</returns>
  1650. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1651. 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; }
  1652. /// <summary>Returns the dot product of two uint values. Equivalent to multiplication.</summary>
  1653. /// <param name="x">The first value.</param>
  1654. /// <param name="y">The second value.</param>
  1655. /// <returns>The dot product of two values.</returns>
  1656. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1657. public static uint dot(uint x, uint y) { return x * y; }
  1658. /// <summary>Returns the dot product of two uint2 vectors.</summary>
  1659. /// <param name="x">The first vector.</param>
  1660. /// <param name="y">The second vector.</param>
  1661. /// <returns>The dot product of two vectors.</returns>
  1662. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1663. public static uint dot(uint2 x, uint2 y) { return x.x * y.x + x.y * y.y; }
  1664. /// <summary>Returns the dot product of two uint3 vectors.</summary>
  1665. /// <param name="x">The first vector.</param>
  1666. /// <param name="y">The second vector.</param>
  1667. /// <returns>The dot product of two vectors.</returns>
  1668. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1669. public static uint dot(uint3 x, uint3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1670. /// <summary>Returns the dot product of two uint4 vectors.</summary>
  1671. /// <param name="x">The first vector.</param>
  1672. /// <param name="y">The second vector.</param>
  1673. /// <returns>The dot product of two vectors.</returns>
  1674. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1675. 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; }
  1676. /// <summary>Returns the dot product of two float values. Equivalent to multiplication.</summary>
  1677. /// <param name="x">The first value.</param>
  1678. /// <param name="y">The second value.</param>
  1679. /// <returns>The dot product of two values.</returns>
  1680. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1681. public static float dot(float x, float y) { return x * y; }
  1682. /// <summary>Returns the dot product of two float2 vectors.</summary>
  1683. /// <param name="x">The first vector.</param>
  1684. /// <param name="y">The second vector.</param>
  1685. /// <returns>The dot product of two vectors.</returns>
  1686. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1687. public static float dot(float2 x, float2 y) { return x.x * y.x + x.y * y.y; }
  1688. /// <summary>Returns the dot product of two float3 vectors.</summary>
  1689. /// <param name="x">The first vector.</param>
  1690. /// <param name="y">The second vector.</param>
  1691. /// <returns>The dot product of two vectors.</returns>
  1692. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1693. public static float dot(float3 x, float3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1694. /// <summary>Returns the dot product of two float4 vectors.</summary>
  1695. /// <param name="x">The first vector.</param>
  1696. /// <param name="y">The second vector.</param>
  1697. /// <returns>The dot product of two vectors.</returns>
  1698. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1699. 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; }
  1700. /// <summary>Returns the dot product of two double values. Equivalent to multiplication.</summary>
  1701. /// <param name="x">The first value.</param>
  1702. /// <param name="y">The second value.</param>
  1703. /// <returns>The dot product of two values.</returns>
  1704. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1705. public static double dot(double x, double y) { return x * y; }
  1706. /// <summary>Returns the dot product of two double2 vectors.</summary>
  1707. /// <param name="x">The first vector.</param>
  1708. /// <param name="y">The second vector.</param>
  1709. /// <returns>The dot product of two vectors.</returns>
  1710. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1711. public static double dot(double2 x, double2 y) { return x.x * y.x + x.y * y.y; }
  1712. /// <summary>Returns the dot product of two double3 vectors.</summary>
  1713. /// <param name="x">The first vector.</param>
  1714. /// <param name="y">The second vector.</param>
  1715. /// <returns>The dot product of two vectors.</returns>
  1716. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1717. public static double dot(double3 x, double3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; }
  1718. /// <summary>Returns the dot product of two double4 vectors.</summary>
  1719. /// <param name="x">The first vector.</param>
  1720. /// <param name="y">The second vector.</param>
  1721. /// <returns>The dot product of two vectors.</returns>
  1722. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1723. 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; }
  1724. /// <summary>Returns the tangent of a float value.</summary>
  1725. /// <param name="x">Input value.</param>
  1726. /// <returns>The tangent of the input.</returns>
  1727. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1728. public static float tan(float x) { return (float)System.Math.Tan(x); }
  1729. /// <summary>Returns the componentwise tangent of a float2 vector.</summary>
  1730. /// <param name="x">Input value.</param>
  1731. /// <returns>The componentwise tangent of the input.</returns>
  1732. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1733. public static float2 tan(float2 x) { return new float2(tan(x.x), tan(x.y)); }
  1734. /// <summary>Returns the componentwise tangent of a float3 vector.</summary>
  1735. /// <param name="x">Input value.</param>
  1736. /// <returns>The componentwise tangent of the input.</returns>
  1737. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1738. public static float3 tan(float3 x) { return new float3(tan(x.x), tan(x.y), tan(x.z)); }
  1739. /// <summary>Returns the componentwise tangent of a float4 vector.</summary>
  1740. /// <param name="x">Input value.</param>
  1741. /// <returns>The componentwise tangent of the input.</returns>
  1742. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1743. public static float4 tan(float4 x) { return new float4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  1744. /// <summary>Returns the tangent of a double value.</summary>
  1745. /// <param name="x">Input value.</param>
  1746. /// <returns>The tangent of the input.</returns>
  1747. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1748. public static double tan(double x) { return System.Math.Tan(x); }
  1749. /// <summary>Returns the componentwise tangent of a double2 vector.</summary>
  1750. /// <param name="x">Input value.</param>
  1751. /// <returns>The componentwise tangent of the input.</returns>
  1752. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1753. public static double2 tan(double2 x) { return new double2(tan(x.x), tan(x.y)); }
  1754. /// <summary>Returns the componentwise tangent of a double3 vector.</summary>
  1755. /// <param name="x">Input value.</param>
  1756. /// <returns>The componentwise tangent of the input.</returns>
  1757. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1758. public static double3 tan(double3 x) { return new double3(tan(x.x), tan(x.y), tan(x.z)); }
  1759. /// <summary>Returns the componentwise tangent of a double4 vector.</summary>
  1760. /// <param name="x">Input value.</param>
  1761. /// <returns>The componentwise tangent of the input.</returns>
  1762. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1763. public static double4 tan(double4 x) { return new double4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); }
  1764. /// <summary>Returns the hyperbolic tangent of a float value.</summary>
  1765. /// <param name="x">Input value.</param>
  1766. /// <returns>The hyperbolic tangent of the input.</returns>
  1767. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1768. public static float tanh(float x) { return (float)System.Math.Tanh(x); }
  1769. /// <summary>Returns the componentwise hyperbolic tangent of a float2 vector.</summary>
  1770. /// <param name="x">Input value.</param>
  1771. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1772. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1773. public static float2 tanh(float2 x) { return new float2(tanh(x.x), tanh(x.y)); }
  1774. /// <summary>Returns the componentwise hyperbolic tangent of a float3 vector.</summary>
  1775. /// <param name="x">Input value.</param>
  1776. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1777. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1778. public static float3 tanh(float3 x) { return new float3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  1779. /// <summary>Returns the componentwise hyperbolic tangent of a float4 vector.</summary>
  1780. /// <param name="x">Input value.</param>
  1781. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1782. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1783. public static float4 tanh(float4 x) { return new float4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  1784. /// <summary>Returns the hyperbolic tangent of a double value.</summary>
  1785. /// <param name="x">Input value.</param>
  1786. /// <returns>The hyperbolic tangent of the input.</returns>
  1787. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1788. public static double tanh(double x) { return System.Math.Tanh(x); }
  1789. /// <summary>Returns the componentwise hyperbolic tangent of a double2 vector.</summary>
  1790. /// <param name="x">Input value.</param>
  1791. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1792. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1793. public static double2 tanh(double2 x) { return new double2(tanh(x.x), tanh(x.y)); }
  1794. /// <summary>Returns the componentwise hyperbolic tangent of a double3 vector.</summary>
  1795. /// <param name="x">Input value.</param>
  1796. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1797. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1798. public static double3 tanh(double3 x) { return new double3(tanh(x.x), tanh(x.y), tanh(x.z)); }
  1799. /// <summary>Returns the componentwise hyperbolic tangent of a double4 vector.</summary>
  1800. /// <param name="x">Input value.</param>
  1801. /// <returns>The componentwise hyperbolic tangent of the input.</returns>
  1802. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1803. public static double4 tanh(double4 x) { return new double4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); }
  1804. /// <summary>Returns the arctangent of a float value.</summary>
  1805. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1806. /// <returns>The arctangent of the input, in radians.</returns>
  1807. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1808. public static float atan(float x) { return (float)System.Math.Atan(x); }
  1809. /// <summary>Returns the componentwise arctangent of a float2 vector.</summary>
  1810. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1811. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1812. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1813. public static float2 atan(float2 x) { return new float2(atan(x.x), atan(x.y)); }
  1814. /// <summary>Returns the componentwise arctangent of a float3 vector.</summary>
  1815. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1816. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1817. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1818. public static float3 atan(float3 x) { return new float3(atan(x.x), atan(x.y), atan(x.z)); }
  1819. /// <summary>Returns the componentwise arctangent of a float4 vector.</summary>
  1820. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1821. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1822. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1823. public static float4 atan(float4 x) { return new float4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  1824. /// <summary>Returns the arctangent of a double value.</summary>
  1825. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1826. /// <returns>The arctangent of the input, in radians.</returns>
  1827. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1828. public static double atan(double x) { return System.Math.Atan(x); }
  1829. /// <summary>Returns the componentwise arctangent of a double2 vector.</summary>
  1830. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1831. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1832. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1833. public static double2 atan(double2 x) { return new double2(atan(x.x), atan(x.y)); }
  1834. /// <summary>Returns the componentwise arctangent of a double3 vector.</summary>
  1835. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1836. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1838. public static double3 atan(double3 x) { return new double3(atan(x.x), atan(x.y), atan(x.z)); }
  1839. /// <summary>Returns the componentwise arctangent of a double4 vector.</summary>
  1840. /// <param name="x">A tangent value, usually the ratio y/x on the unit circle.</param>
  1841. /// <returns>The componentwise arctangent of the input, in radians.</returns>
  1842. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1843. public static double4 atan(double4 x) { return new double4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); }
  1844. /// <summary>Returns the 2-argument arctangent of a pair of float values.</summary>
  1845. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1846. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1847. /// <returns>The arctangent of the ratio y/x, in radians.</returns>
  1848. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1849. public static float atan2(float y, float x) { return (float)System.Math.Atan2(y, x); }
  1850. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats2 vectors.</summary>
  1851. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1852. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1853. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1854. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1855. public static float2 atan2(float2 y, float2 x) { return new float2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  1856. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats3 vectors.</summary>
  1857. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1858. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1859. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1860. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1861. 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)); }
  1862. /// <summary>Returns the componentwise 2-argument arctangent of a pair of floats4 vectors.</summary>
  1863. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1864. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1865. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1866. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1867. 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)); }
  1868. /// <summary>Returns the 2-argument arctangent of a pair of double values.</summary>
  1869. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1870. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1871. /// <returns>The arctangent of the ratio y/x, in radians.</returns>
  1872. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1873. public static double atan2(double y, double x) { return System.Math.Atan2(y, x); }
  1874. /// <summary>Returns the 2-argument arctangent of a pair of double2 vectors.</summary>
  1875. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1876. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1877. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1878. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1879. public static double2 atan2(double2 y, double2 x) { return new double2(atan2(y.x, x.x), atan2(y.y, x.y)); }
  1880. /// <summary>Returns the 2-argument arctangent of a pair of double3 vectors.</summary>
  1881. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1882. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1883. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1884. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1885. 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)); }
  1886. /// <summary>Returns the 2-argument arctangent of a pair of double4 vectors.</summary>
  1887. /// <param name="y">Numerator of the ratio y/x, usually the y component on the unit circle.</param>
  1888. /// <param name="x">Denominator of the ratio y/x, usually the x component on the unit circle.</param>
  1889. /// <returns>The componentwise arctangent of the ratio y/x, in radians.</returns>
  1890. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1891. 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)); }
  1892. /// <summary>Returns the cosine of a float value.</summary>
  1893. /// <param name="x">Input value.</param>
  1894. /// <returns>The cosine cosine of the input.</returns>
  1895. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1896. public static float cos(float x) { return (float)System.Math.Cos(x); }
  1897. /// <summary>Returns the componentwise cosine of a float2 vector.</summary>
  1898. /// <param name="x">Input value.</param>
  1899. /// <returns>The componentwise cosine cosine of the input.</returns>
  1900. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1901. public static float2 cos(float2 x) { return new float2(cos(x.x), cos(x.y)); }
  1902. /// <summary>Returns the componentwise cosine of a float3 vector.</summary>
  1903. /// <param name="x">Input value.</param>
  1904. /// <returns>The componentwise cosine cosine of the input.</returns>
  1905. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1906. public static float3 cos(float3 x) { return new float3(cos(x.x), cos(x.y), cos(x.z)); }
  1907. /// <summary>Returns the componentwise cosine of a float4 vector.</summary>
  1908. /// <param name="x">Input value.</param>
  1909. /// <returns>The componentwise cosine cosine of the input.</returns>
  1910. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1911. public static float4 cos(float4 x) { return new float4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  1912. /// <summary>Returns the cosine of a double value.</summary>
  1913. /// <param name="x">Input value.</param>
  1914. /// <returns>The cosine cosine of the input.</returns>
  1915. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1916. public static double cos(double x) { return System.Math.Cos(x); }
  1917. /// <summary>Returns the componentwise cosine of a double2 vector.</summary>
  1918. /// <param name="x">Input value.</param>
  1919. /// <returns>The componentwise cosine cosine of the input.</returns>
  1920. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1921. public static double2 cos(double2 x) { return new double2(cos(x.x), cos(x.y)); }
  1922. /// <summary>Returns the componentwise cosine of a double3 vector.</summary>
  1923. /// <param name="x">Input value.</param>
  1924. /// <returns>The componentwise cosine cosine of the input.</returns>
  1925. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1926. public static double3 cos(double3 x) { return new double3(cos(x.x), cos(x.y), cos(x.z)); }
  1927. /// <summary>Returns the componentwise cosine of a double4 vector.</summary>
  1928. /// <param name="x">Input value.</param>
  1929. /// <returns>The componentwise cosine cosine of the input.</returns>
  1930. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1931. public static double4 cos(double4 x) { return new double4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); }
  1932. /// <summary>Returns the hyperbolic cosine of a float value.</summary>
  1933. /// <param name="x">Input value.</param>
  1934. /// <returns>The hyperbolic cosine of the input.</returns>
  1935. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1936. public static float cosh(float x) { return (float)System.Math.Cosh(x); }
  1937. /// <summary>Returns the componentwise hyperbolic cosine of a float2 vector.</summary>
  1938. /// <param name="x">Input value.</param>
  1939. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1940. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1941. public static float2 cosh(float2 x) { return new float2(cosh(x.x), cosh(x.y)); }
  1942. /// <summary>Returns the componentwise hyperbolic cosine of a float3 vector.</summary>
  1943. /// <param name="x">Input value.</param>
  1944. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1945. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1946. public static float3 cosh(float3 x) { return new float3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  1947. /// <summary>Returns the componentwise hyperbolic cosine of a float4 vector.</summary>
  1948. /// <param name="x">Input value.</param>
  1949. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1950. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1951. public static float4 cosh(float4 x) { return new float4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  1952. /// <summary>Returns the hyperbolic cosine of a double value.</summary>
  1953. /// <param name="x">Input value.</param>
  1954. /// <returns>The hyperbolic cosine of the input.</returns>
  1955. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1956. public static double cosh(double x) { return System.Math.Cosh(x); }
  1957. /// <summary>Returns the componentwise hyperbolic cosine of a double2 vector.</summary>
  1958. /// <param name="x">Input value.</param>
  1959. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1960. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1961. public static double2 cosh(double2 x) { return new double2(cosh(x.x), cosh(x.y)); }
  1962. /// <summary>Returns the componentwise hyperbolic cosine of a double3 vector.</summary>
  1963. /// <param name="x">Input value.</param>
  1964. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1965. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1966. public static double3 cosh(double3 x) { return new double3(cosh(x.x), cosh(x.y), cosh(x.z)); }
  1967. /// <summary>Returns the componentwise hyperbolic cosine of a double4 vector.</summary>
  1968. /// <param name="x">Input value.</param>
  1969. /// <returns>The componentwise hyperbolic cosine of the input.</returns>
  1970. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1971. public static double4 cosh(double4 x) { return new double4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); }
  1972. /// <summary>Returns the arccosine of a float value.</summary>
  1973. /// <param name="x">Input value.</param>
  1974. /// <returns>The arccosine of the input.</returns>
  1975. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1976. public static float acos(float x) { return (float)System.Math.Acos((float)x); }
  1977. /// <summary>Returns the componentwise arccosine of a float2 vector.</summary>
  1978. /// <param name="x">Input value.</param>
  1979. /// <returns>The componentwise arccosine of the input.</returns>
  1980. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1981. public static float2 acos(float2 x) { return new float2(acos(x.x), acos(x.y)); }
  1982. /// <summary>Returns the componentwise arccosine of a float3 vector.</summary>
  1983. /// <param name="x">Input value.</param>
  1984. /// <returns>The componentwise arccosine of the input.</returns>
  1985. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1986. public static float3 acos(float3 x) { return new float3(acos(x.x), acos(x.y), acos(x.z)); }
  1987. /// <summary>Returns the componentwise arccosine of a float4 vector.</summary>
  1988. /// <param name="x">Input value.</param>
  1989. /// <returns>The componentwise arccosine of the input.</returns>
  1990. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1991. public static float4 acos(float4 x) { return new float4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  1992. /// <summary>Returns the arccosine of a double value.</summary>
  1993. /// <param name="x">Input value.</param>
  1994. /// <returns>The arccosine of the input.</returns>
  1995. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  1996. public static double acos(double x) { return System.Math.Acos(x); }
  1997. /// <summary>Returns the componentwise arccosine of a double2 vector.</summary>
  1998. /// <param name="x">Input value.</param>
  1999. /// <returns>The componentwise arccosine of the input.</returns>
  2000. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2001. public static double2 acos(double2 x) { return new double2(acos(x.x), acos(x.y)); }
  2002. /// <summary>Returns the componentwise arccosine of a double3 vector.</summary>
  2003. /// <param name="x">Input value.</param>
  2004. /// <returns>The componentwise arccosine of the input.</returns>
  2005. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2006. public static double3 acos(double3 x) { return new double3(acos(x.x), acos(x.y), acos(x.z)); }
  2007. /// <summary>Returns the componentwise arccosine of a double4 vector.</summary>
  2008. /// <param name="x">Input value.</param>
  2009. /// <returns>The componentwise arccosine of the input.</returns>
  2010. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2011. public static double4 acos(double4 x) { return new double4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); }
  2012. /// <summary>Returns the sine of a float value.</summary>
  2013. /// <param name="x">Input value.</param>
  2014. /// <returns>The sine of the input.</returns>
  2015. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2016. public static float sin(float x) { return (float)System.Math.Sin((float)x); }
  2017. /// <summary>Returns the componentwise sine of a float2 vector.</summary>
  2018. /// <param name="x">Input value.</param>
  2019. /// <returns>The componentwise sine of the input.</returns>
  2020. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2021. public static float2 sin(float2 x) { return new float2(sin(x.x), sin(x.y)); }
  2022. /// <summary>Returns the componentwise sine of a float3 vector.</summary>
  2023. /// <param name="x">Input value.</param>
  2024. /// <returns>The componentwise sine of the input.</returns>
  2025. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2026. public static float3 sin(float3 x) { return new float3(sin(x.x), sin(x.y), sin(x.z)); }
  2027. /// <summary>Returns the componentwise sine of a float4 vector.</summary>
  2028. /// <param name="x">Input value.</param>
  2029. /// <returns>The componentwise sine of the input.</returns>
  2030. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2031. public static float4 sin(float4 x) { return new float4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  2032. /// <summary>Returns the sine of a double value.</summary>
  2033. /// <param name="x">Input value.</param>
  2034. /// <returns>The sine of the input.</returns>
  2035. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2036. public static double sin(double x) { return System.Math.Sin(x); }
  2037. /// <summary>Returns the componentwise sine of a double2 vector.</summary>
  2038. /// <param name="x">Input value.</param>
  2039. /// <returns>The componentwise sine of the input.</returns>
  2040. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2041. public static double2 sin(double2 x) { return new double2(sin(x.x), sin(x.y)); }
  2042. /// <summary>Returns the componentwise sine of a double3 vector.</summary>
  2043. /// <param name="x">Input value.</param>
  2044. /// <returns>The componentwise sine of the input.</returns>
  2045. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2046. public static double3 sin(double3 x) { return new double3(sin(x.x), sin(x.y), sin(x.z)); }
  2047. /// <summary>Returns the componentwise sine of a double4 vector.</summary>
  2048. /// <param name="x">Input value.</param>
  2049. /// <returns>The componentwise sine of the input.</returns>
  2050. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2051. public static double4 sin(double4 x) { return new double4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); }
  2052. /// <summary>Returns the hyperbolic sine of a float value.</summary>
  2053. /// <param name="x">Input value.</param>
  2054. /// <returns>The hyperbolic sine of the input.</returns>
  2055. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2056. public static float sinh(float x) { return (float)System.Math.Sinh((float)x); }
  2057. /// <summary>Returns the componentwise hyperbolic sine of a float2 vector.</summary>
  2058. /// <param name="x">Input value.</param>
  2059. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2060. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2061. public static float2 sinh(float2 x) { return new float2(sinh(x.x), sinh(x.y)); }
  2062. /// <summary>Returns the componentwise hyperbolic sine of a float3 vector.</summary>
  2063. /// <param name="x">Input value.</param>
  2064. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2065. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2066. public static float3 sinh(float3 x) { return new float3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  2067. /// <summary>Returns the componentwise hyperbolic sine of a float4 vector.</summary>
  2068. /// <param name="x">Input value.</param>
  2069. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2070. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2071. public static float4 sinh(float4 x) { return new float4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  2072. /// <summary>Returns the hyperbolic sine of a double value.</summary>
  2073. /// <param name="x">Input value.</param>
  2074. /// <returns>The hyperbolic sine of the input.</returns>
  2075. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2076. public static double sinh(double x) { return System.Math.Sinh(x); }
  2077. /// <summary>Returns the componentwise hyperbolic sine of a double2 vector.</summary>
  2078. /// <param name="x">Input value.</param>
  2079. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2080. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2081. public static double2 sinh(double2 x) { return new double2(sinh(x.x), sinh(x.y)); }
  2082. /// <summary>Returns the componentwise hyperbolic sine of a double3 vector.</summary>
  2083. /// <param name="x">Input value.</param>
  2084. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2085. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2086. public static double3 sinh(double3 x) { return new double3(sinh(x.x), sinh(x.y), sinh(x.z)); }
  2087. /// <summary>Returns the componentwise hyperbolic sine of a double4 vector.</summary>
  2088. /// <param name="x">Input value.</param>
  2089. /// <returns>The componentwise hyperbolic sine of the input.</returns>
  2090. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2091. public static double4 sinh(double4 x) { return new double4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); }
  2092. /// <summary>Returns the arcsine of a float value.</summary>
  2093. /// <param name="x">Input value.</param>
  2094. /// <returns>The arcsine of the input.</returns>
  2095. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2096. public static float asin(float x) { return (float)System.Math.Asin((float)x); }
  2097. /// <summary>Returns the componentwise arcsine of a float2 vector.</summary>
  2098. /// <param name="x">Input value.</param>
  2099. /// <returns>The componentwise arcsine of the input.</returns>
  2100. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2101. public static float2 asin(float2 x) { return new float2(asin(x.x), asin(x.y)); }
  2102. /// <summary>Returns the componentwise arcsine of a float3 vector.</summary>
  2103. /// <param name="x">Input value.</param>
  2104. /// <returns>The componentwise arcsine of the input.</returns>
  2105. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2106. public static float3 asin(float3 x) { return new float3(asin(x.x), asin(x.y), asin(x.z)); }
  2107. /// <summary>Returns the componentwise arcsine of a float4 vector.</summary>
  2108. /// <param name="x">Input value.</param>
  2109. /// <returns>The componentwise arcsine of the input.</returns>
  2110. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2111. public static float4 asin(float4 x) { return new float4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  2112. /// <summary>Returns the arcsine of a double value.</summary>
  2113. /// <param name="x">Input value.</param>
  2114. /// <returns>The arcsine of the input.</returns>
  2115. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2116. public static double asin(double x) { return System.Math.Asin(x); }
  2117. /// <summary>Returns the componentwise arcsine of a double2 vector.</summary>
  2118. /// <param name="x">Input value.</param>
  2119. /// <returns>The componentwise arcsine of the input.</returns>
  2120. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2121. public static double2 asin(double2 x) { return new double2(asin(x.x), asin(x.y)); }
  2122. /// <summary>Returns the componentwise arcsine of a double3 vector.</summary>
  2123. /// <param name="x">Input value.</param>
  2124. /// <returns>The componentwise arcsine of the input.</returns>
  2125. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2126. public static double3 asin(double3 x) { return new double3(asin(x.x), asin(x.y), asin(x.z)); }
  2127. /// <summary>Returns the componentwise arcsine of a double4 vector.</summary>
  2128. /// <param name="x">Input value.</param>
  2129. /// <returns>The componentwise arcsine of the input.</returns>
  2130. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2131. public static double4 asin(double4 x) { return new double4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); }
  2132. /// <summary>Returns the result of rounding a float value up to the nearest integral value less or equal to the original value.</summary>
  2133. /// <param name="x">Input value.</param>
  2134. /// <returns>The round down to nearest integral value of the input.</returns>
  2135. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2136. public static float floor(float x) { return (float)System.Math.Floor((float)x); }
  2137. /// <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>
  2138. /// <param name="x">Input value.</param>
  2139. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2140. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2141. public static float2 floor(float2 x) { return new float2(floor(x.x), floor(x.y)); }
  2142. /// <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>
  2143. /// <param name="x">Input value.</param>
  2144. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2145. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2146. public static float3 floor(float3 x) { return new float3(floor(x.x), floor(x.y), floor(x.z)); }
  2147. /// <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>
  2148. /// <param name="x">Input value.</param>
  2149. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2150. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2151. public static float4 floor(float4 x) { return new float4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  2152. /// <summary>Returns the result of rounding a double value up to the nearest integral value less or equal to the original value.</summary>
  2153. /// <param name="x">Input value.</param>
  2154. /// <returns>The round down to nearest integral value of the input.</returns>
  2155. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2156. public static double floor(double x) { return System.Math.Floor(x); }
  2157. /// <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>
  2158. /// <param name="x">Input value.</param>
  2159. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2160. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2161. public static double2 floor(double2 x) { return new double2(floor(x.x), floor(x.y)); }
  2162. /// <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>
  2163. /// <param name="x">Input value.</param>
  2164. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2165. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2166. public static double3 floor(double3 x) { return new double3(floor(x.x), floor(x.y), floor(x.z)); }
  2167. /// <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>
  2168. /// <param name="x">Input value.</param>
  2169. /// <returns>The componentwise round down to nearest integral value of the input.</returns>
  2170. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2171. public static double4 floor(double4 x) { return new double4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); }
  2172. /// <summary>Returns the result of rounding a float value up to the nearest integral value greater or equal to the original value.</summary>
  2173. /// <param name="x">Input value.</param>
  2174. /// <returns>The round up to nearest integral value of the input.</returns>
  2175. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2176. public static float ceil(float x) { return (float)System.Math.Ceiling((float)x); }
  2177. /// <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>
  2178. /// <param name="x">Input value.</param>
  2179. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2180. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2181. public static float2 ceil(float2 x) { return new float2(ceil(x.x), ceil(x.y)); }
  2182. /// <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>
  2183. /// <param name="x">Input value.</param>
  2184. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2185. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2186. public static float3 ceil(float3 x) { return new float3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  2187. /// <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>
  2188. /// <param name="x">Input value.</param>
  2189. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2190. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2191. public static float4 ceil(float4 x) { return new float4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  2192. /// <summary>Returns the result of rounding a double value up to the nearest greater integral value greater or equal to the original value.</summary>
  2193. /// <param name="x">Input value.</param>
  2194. /// <returns>The round up to nearest integral value of the input.</returns>
  2195. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2196. public static double ceil(double x) { return System.Math.Ceiling(x); }
  2197. /// <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>
  2198. /// <param name="x">Input value.</param>
  2199. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2201. public static double2 ceil(double2 x) { return new double2(ceil(x.x), ceil(x.y)); }
  2202. /// <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>
  2203. /// <param name="x">Input value.</param>
  2204. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2205. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2206. public static double3 ceil(double3 x) { return new double3(ceil(x.x), ceil(x.y), ceil(x.z)); }
  2207. /// <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>
  2208. /// <param name="x">Input value.</param>
  2209. /// <returns>The componentwise round up to nearest integral value of the input.</returns>
  2210. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2211. public static double4 ceil(double4 x) { return new double4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); }
  2212. /// <summary>Returns the result of rounding a float value to the nearest integral value.</summary>
  2213. /// <param name="x">Input value.</param>
  2214. /// <returns>The round to nearest integral value of the input.</returns>
  2215. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2216. public static float round(float x) { return (float)System.Math.Round((float)x); }
  2217. /// <summary>Returns the result of rounding each component of a float2 vector value to the nearest integral value.</summary>
  2218. /// <param name="x">Input value.</param>
  2219. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2220. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2221. public static float2 round(float2 x) { return new float2(round(x.x), round(x.y)); }
  2222. /// <summary>Returns the result of rounding each component of a float3 vector value to the nearest integral value.</summary>
  2223. /// <param name="x">Input value.</param>
  2224. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2225. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2226. public static float3 round(float3 x) { return new float3(round(x.x), round(x.y), round(x.z)); }
  2227. /// <summary>Returns the result of rounding each component of a float4 vector value to the nearest integral value.</summary>
  2228. /// <param name="x">Input value.</param>
  2229. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2230. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2231. public static float4 round(float4 x) { return new float4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  2232. /// <summary>Returns the result of rounding a double value to the nearest integral value.</summary>
  2233. /// <param name="x">Input value.</param>
  2234. /// <returns>The round to nearest integral value of the input.</returns>
  2235. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2236. public static double round(double x) { return System.Math.Round(x); }
  2237. /// <summary>Returns the result of rounding each component of a double2 vector value to the nearest integral value.</summary>
  2238. /// <param name="x">Input value.</param>
  2239. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2240. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2241. public static double2 round(double2 x) { return new double2(round(x.x), round(x.y)); }
  2242. /// <summary>Returns the result of rounding each component of a double3 vector value to the nearest integral value.</summary>
  2243. /// <param name="x">Input value.</param>
  2244. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2246. public static double3 round(double3 x) { return new double3(round(x.x), round(x.y), round(x.z)); }
  2247. /// <summary>Returns the result of rounding each component of a double4 vector value to the nearest integral value.</summary>
  2248. /// <param name="x">Input value.</param>
  2249. /// <returns>The componentwise round to nearest integral value of the input.</returns>
  2250. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2251. public static double4 round(double4 x) { return new double4(round(x.x), round(x.y), round(x.z), round(x.w)); }
  2252. /// <summary>Returns the result of truncating a float value to an integral float value.</summary>
  2253. /// <param name="x">Input value.</param>
  2254. /// <returns>The truncation of the input.</returns>
  2255. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2256. public static float trunc(float x) { return (float)System.Math.Truncate((float)x); }
  2257. /// <summary>Returns the result of a componentwise truncation of a float2 value to an integral float2 value.</summary>
  2258. /// <param name="x">Input value.</param>
  2259. /// <returns>The componentwise truncation of the input.</returns>
  2260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2261. public static float2 trunc(float2 x) { return new float2(trunc(x.x), trunc(x.y)); }
  2262. /// <summary>Returns the result of a componentwise truncation of a float3 value to an integral float3 value.</summary>
  2263. /// <param name="x">Input value.</param>
  2264. /// <returns>The componentwise truncation of the input.</returns>
  2265. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2266. public static float3 trunc(float3 x) { return new float3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  2267. /// <summary>Returns the result of a componentwise truncation of a float4 value to an integral float4 value.</summary>
  2268. /// <param name="x">Input value.</param>
  2269. /// <returns>The componentwise truncation of the input.</returns>
  2270. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2271. public static float4 trunc(float4 x) { return new float4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  2272. /// <summary>Returns the result of truncating a double value to an integral double value.</summary>
  2273. /// <param name="x">Input value.</param>
  2274. /// <returns>The truncation of the input.</returns>
  2275. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2276. public static double trunc(double x) { return System.Math.Truncate(x); }
  2277. /// <summary>Returns the result of a componentwise truncation of a double2 value to an integral double2 value.</summary>
  2278. /// <param name="x">Input value.</param>
  2279. /// <returns>The componentwise truncation of the input.</returns>
  2280. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2281. public static double2 trunc(double2 x) { return new double2(trunc(x.x), trunc(x.y)); }
  2282. /// <summary>Returns the result of a componentwise truncation of a double3 value to an integral double3 value.</summary>
  2283. /// <param name="x">Input value.</param>
  2284. /// <returns>The componentwise truncation of the input.</returns>
  2285. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2286. public static double3 trunc(double3 x) { return new double3(trunc(x.x), trunc(x.y), trunc(x.z)); }
  2287. /// <summary>Returns the result of a componentwise truncation of a double4 value to an integral double4 value.</summary>
  2288. /// <param name="x">Input value.</param>
  2289. /// <returns>The componentwise truncation of the input.</returns>
  2290. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2291. public static double4 trunc(double4 x) { return new double4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); }
  2292. /// <summary>Returns the fractional part of a float value.</summary>
  2293. /// <param name="x">Input value.</param>
  2294. /// <returns>The fractional part of the input.</returns>
  2295. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2296. public static float frac(float x) { return x - floor(x); }
  2297. /// <summary>Returns the componentwise fractional parts of a float2 vector.</summary>
  2298. /// <param name="x">Input value.</param>
  2299. /// <returns>The componentwise fractional part of the input.</returns>
  2300. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2301. public static float2 frac(float2 x) { return x - floor(x); }
  2302. /// <summary>Returns the componentwise fractional parts of a float3 vector.</summary>
  2303. /// <param name="x">Input value.</param>
  2304. /// <returns>The componentwise fractional part of the input.</returns>
  2305. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2306. public static float3 frac(float3 x) { return x - floor(x); }
  2307. /// <summary>Returns the componentwise fractional parts of a float4 vector.</summary>
  2308. /// <param name="x">Input value.</param>
  2309. /// <returns>The componentwise fractional part of the input.</returns>
  2310. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2311. public static float4 frac(float4 x) { return x - floor(x); }
  2312. /// <summary>Returns the fractional part of a double value.</summary>
  2313. /// <param name="x">Input value.</param>
  2314. /// <returns>The fractional part of the input.</returns>
  2315. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2316. public static double frac(double x) { return x - floor(x); }
  2317. /// <summary>Returns the componentwise fractional parts of a double2 vector.</summary>
  2318. /// <param name="x">Input value.</param>
  2319. /// <returns>The componentwise fractional part of the input.</returns>
  2320. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2321. public static double2 frac(double2 x) { return x - floor(x); }
  2322. /// <summary>Returns the componentwise fractional parts of a double3 vector.</summary>
  2323. /// <param name="x">Input value.</param>
  2324. /// <returns>The componentwise fractional part of the input.</returns>
  2325. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2326. public static double3 frac(double3 x) { return x - floor(x); }
  2327. /// <summary>Returns the componentwise fractional parts of a double4 vector.</summary>
  2328. /// <param name="x">Input value.</param>
  2329. /// <returns>The componentwise fractional part of the input.</returns>
  2330. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2331. public static double4 frac(double4 x) { return x - floor(x); }
  2332. /// <summary>Returns the reciprocal a float value.</summary>
  2333. /// <param name="x">Input value.</param>
  2334. /// <returns>The reciprocal of the input.</returns>
  2335. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2336. public static float rcp(float x) { return 1.0f / x; }
  2337. /// <summary>Returns the componentwise reciprocal a float2 vector.</summary>
  2338. /// <param name="x">Input value.</param>
  2339. /// <returns>The componentwise reciprocal of the input.</returns>
  2340. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2341. public static float2 rcp(float2 x) { return 1.0f / x; }
  2342. /// <summary>Returns the componentwise reciprocal a float3 vector.</summary>
  2343. /// <param name="x">Input value.</param>
  2344. /// <returns>The componentwise reciprocal of the input.</returns>
  2345. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2346. public static float3 rcp(float3 x) { return 1.0f / x; }
  2347. /// <summary>Returns the componentwise reciprocal a float4 vector.</summary>
  2348. /// <param name="x">Input value.</param>
  2349. /// <returns>The componentwise reciprocal of the input.</returns>
  2350. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2351. public static float4 rcp(float4 x) { return 1.0f / x; }
  2352. /// <summary>Returns the reciprocal a double value.</summary>
  2353. /// <param name="x">Input value.</param>
  2354. /// <returns>The reciprocal of the input.</returns>
  2355. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2356. public static double rcp(double x) { return 1.0 / x; }
  2357. /// <summary>Returns the componentwise reciprocal a double2 vector.</summary>
  2358. /// <param name="x">Input value.</param>
  2359. /// <returns>The componentwise reciprocal of the input.</returns>
  2360. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2361. public static double2 rcp(double2 x) { return 1.0 / x; }
  2362. /// <summary>Returns the componentwise reciprocal a double3 vector.</summary>
  2363. /// <param name="x">Input value.</param>
  2364. /// <returns>The componentwise reciprocal of the input.</returns>
  2365. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2366. public static double3 rcp(double3 x) { return 1.0 / x; }
  2367. /// <summary>Returns the componentwise reciprocal a double4 vector.</summary>
  2368. /// <param name="x">Input value.</param>
  2369. /// <returns>The componentwise reciprocal of the input.</returns>
  2370. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2371. public static double4 rcp(double4 x) { return 1.0 / x; }
  2372. /// <summary>Returns the sign of a int value. -1 if it is less than zero, 0 if it is zero and 1 if it greater than zero.</summary>
  2373. /// <param name="x">Input value.</param>
  2374. /// <returns>The sign of the input.</returns>
  2375. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2376. public static int sign(int x) { return (x > 0 ? 1 : 0) - (x < 0 ? 1 : 0); }
  2377. /// <summary>Returns the componentwise sign of a int2 value. 1 for positive components, 0 for zero components and -1 for negative components.</summary>
  2378. /// <param name="x">Input value.</param>
  2379. /// <returns>The componentwise sign of the input.</returns>
  2380. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2381. public static int2 sign(int2 x) { return new int2(sign(x.x), sign(x.y)); }
  2382. /// <summary>Returns the componentwise sign of a int3 value. 1 for positive components, 0 for zero components and -1 for negative components.</summary>
  2383. /// <param name="x">Input value.</param>
  2384. /// <returns>The componentwise sign of the input.</returns>
  2385. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2386. public static int3 sign(int3 x) { return new int3(sign(x.x), sign(x.y), sign(x.z)); }
  2387. /// <summary>Returns the componentwise sign of a int4 value. 1 for positive components, 0 for zero components and -1 for negative components.</summary>
  2388. /// <param name="x">Input value.</param>
  2389. /// <returns>The componentwise sign of the input.</returns>
  2390. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2391. public static int4 sign(int4 x) { return new int4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  2392. /// <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>
  2393. /// <param name="x">Input value.</param>
  2394. /// <returns>The sign of the input.</returns>
  2395. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2396. public static float sign(float x) { return (x > 0.0f ? 1.0f : 0.0f) - (x < 0.0f ? 1.0f : 0.0f); }
  2397. /// <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>
  2398. /// <param name="x">Input value.</param>
  2399. /// <returns>The componentwise sign of the input.</returns>
  2400. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2401. public static float2 sign(float2 x) { return new float2(sign(x.x), sign(x.y)); }
  2402. /// <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>
  2403. /// <param name="x">Input value.</param>
  2404. /// <returns>The componentwise sign of the input.</returns>
  2405. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2406. public static float3 sign(float3 x) { return new float3(sign(x.x), sign(x.y), sign(x.z)); }
  2407. /// <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>
  2408. /// <param name="x">Input value.</param>
  2409. /// <returns>The componentwise sign of the input.</returns>
  2410. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2411. public static float4 sign(float4 x) { return new float4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  2412. /// <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>
  2413. /// <param name="x">Input value.</param>
  2414. /// <returns>The sign of the input.</returns>
  2415. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2416. public static double sign(double x) { return x == 0 ? 0 : (x > 0.0 ? 1.0 : 0.0) - (x < 0.0 ? 1.0 : 0.0); }
  2417. /// <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>
  2418. /// <param name="x">Input value.</param>
  2419. /// <returns>The componentwise sign of the input.</returns>
  2420. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2421. public static double2 sign(double2 x) { return new double2(sign(x.x), sign(x.y)); }
  2422. /// <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>
  2423. /// <param name="x">Input value.</param>
  2424. /// <returns>The componentwise sign of the input.</returns>
  2425. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2426. public static double3 sign(double3 x) { return new double3(sign(x.x), sign(x.y), sign(x.z)); }
  2427. /// <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>
  2428. /// <param name="x">Input value.</param>
  2429. /// <returns>The componentwise sign of the input.</returns>
  2430. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2431. public static double4 sign(double4 x) { return new double4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); }
  2432. /// <summary>Returns x raised to the power y.</summary>
  2433. /// <param name="x">The exponent base.</param>
  2434. /// <param name="y">The exponent power.</param>
  2435. /// <returns>The result of raising x to the power y.</returns>
  2436. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2437. public static float pow(float x, float y) { return (float)System.Math.Pow((float)x, (float)y); }
  2438. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2439. /// <param name="x">The exponent base.</param>
  2440. /// <param name="y">The exponent power.</param>
  2441. /// <returns>The componentwise result of raising x to the power y.</returns>
  2442. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2443. public static float2 pow(float2 x, float2 y) { return new float2(pow(x.x, y.x), pow(x.y, y.y)); }
  2444. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2445. /// <param name="x">The exponent base.</param>
  2446. /// <param name="y">The exponent power.</param>
  2447. /// <returns>The componentwise result of raising x to the power y.</returns>
  2448. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2449. 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)); }
  2450. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2451. /// <param name="x">The exponent base.</param>
  2452. /// <param name="y">The exponent power.</param>
  2453. /// <returns>The componentwise result of raising x to the power y.</returns>
  2454. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2455. 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)); }
  2456. /// <summary>Returns x raised to the power y.</summary>
  2457. /// <param name="x">The exponent base.</param>
  2458. /// <param name="y">The exponent power.</param>
  2459. /// <returns>The result of raising x to the power y.</returns>
  2460. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2461. public static double pow(double x, double y) { return System.Math.Pow(x, y); }
  2462. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2463. /// <param name="x">The exponent base.</param>
  2464. /// <param name="y">The exponent power.</param>
  2465. /// <returns>The componentwise result of raising x to the power y.</returns>
  2466. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2467. public static double2 pow(double2 x, double2 y) { return new double2(pow(x.x, y.x), pow(x.y, y.y)); }
  2468. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2469. /// <param name="x">The exponent base.</param>
  2470. /// <param name="y">The exponent power.</param>
  2471. /// <returns>The componentwise result of raising x to the power y.</returns>
  2472. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2473. 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)); }
  2474. /// <summary>Returns the componentwise result of raising x to the power y.</summary>
  2475. /// <param name="x">The exponent base.</param>
  2476. /// <param name="y">The exponent power.</param>
  2477. /// <returns>The componentwise result of raising x to the power y.</returns>
  2478. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2479. 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)); }
  2480. /// <summary>Returns the base-e exponential of x.</summary>
  2481. /// <param name="x">Input value.</param>
  2482. /// <returns>The base-e exponential of the input.</returns>
  2483. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2484. public static float exp(float x) { return (float)System.Math.Exp((float)x); }
  2485. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2486. /// <param name="x">Input value.</param>
  2487. /// <returns>The componentwise base-e exponential of the input.</returns>
  2488. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2489. public static float2 exp(float2 x) { return new float2(exp(x.x), exp(x.y)); }
  2490. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2491. /// <param name="x">Input value.</param>
  2492. /// <returns>The componentwise base-e exponential of the input.</returns>
  2493. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2494. public static float3 exp(float3 x) { return new float3(exp(x.x), exp(x.y), exp(x.z)); }
  2495. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2496. /// <param name="x">Input value.</param>
  2497. /// <returns>The componentwise base-e exponential of the input.</returns>
  2498. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2499. public static float4 exp(float4 x) { return new float4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  2500. /// <summary>Returns the base-e exponential of x.</summary>
  2501. /// <param name="x">Input value.</param>
  2502. /// <returns>The base-e exponential of the input.</returns>
  2503. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2504. public static double exp(double x) { return System.Math.Exp(x); }
  2505. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2506. /// <param name="x">Input value.</param>
  2507. /// <returns>The componentwise base-e exponential of the input.</returns>
  2508. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2509. public static double2 exp(double2 x) { return new double2(exp(x.x), exp(x.y)); }
  2510. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2511. /// <param name="x">Input value.</param>
  2512. /// <returns>The componentwise base-e exponential of the input.</returns>
  2513. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2514. public static double3 exp(double3 x) { return new double3(exp(x.x), exp(x.y), exp(x.z)); }
  2515. /// <summary>Returns the componentwise base-e exponential of x.</summary>
  2516. /// <param name="x">Input value.</param>
  2517. /// <returns>The componentwise base-e exponential of the input.</returns>
  2518. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2519. public static double4 exp(double4 x) { return new double4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); }
  2520. /// <summary>Returns the base-2 exponential of x.</summary>
  2521. /// <param name="x">Input value.</param>
  2522. /// <returns>The base-2 exponential of the input.</returns>
  2523. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2524. public static float exp2(float x) { return (float)System.Math.Exp((float)x * 0.69314718f); }
  2525. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2526. /// <param name="x">Input value.</param>
  2527. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2528. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2529. public static float2 exp2(float2 x) { return new float2(exp2(x.x), exp2(x.y)); }
  2530. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2531. /// <param name="x">Input value.</param>
  2532. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2533. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2534. public static float3 exp2(float3 x) { return new float3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  2535. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2536. /// <param name="x">Input value.</param>
  2537. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2538. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2539. public static float4 exp2(float4 x) { return new float4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  2540. /// <summary>Returns the base-2 exponential of x.</summary>
  2541. /// <param name="x">Input value.</param>
  2542. /// <returns>The base-2 exponential of the input.</returns>
  2543. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2544. public static double exp2(double x) { return System.Math.Exp(x * 0.693147180559945309); }
  2545. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2546. /// <param name="x">Input value.</param>
  2547. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2548. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2549. public static double2 exp2(double2 x) { return new double2(exp2(x.x), exp2(x.y)); }
  2550. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2551. /// <param name="x">Input value.</param>
  2552. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2553. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2554. public static double3 exp2(double3 x) { return new double3(exp2(x.x), exp2(x.y), exp2(x.z)); }
  2555. /// <summary>Returns the componentwise base-2 exponential of x.</summary>
  2556. /// <param name="x">Input value.</param>
  2557. /// <returns>The componentwise base-2 exponential of the input.</returns>
  2558. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2559. public static double4 exp2(double4 x) { return new double4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); }
  2560. /// <summary>Returns the base-10 exponential of x.</summary>
  2561. /// <param name="x">Input value.</param>
  2562. /// <returns>The base-10 exponential of the input.</returns>
  2563. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2564. public static float exp10(float x) { return (float)System.Math.Exp((float)x * 2.30258509f); }
  2565. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2566. /// <param name="x">Input value.</param>
  2567. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2568. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2569. public static float2 exp10(float2 x) { return new float2(exp10(x.x), exp10(x.y)); }
  2570. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2571. /// <param name="x">Input value.</param>
  2572. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2573. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2574. public static float3 exp10(float3 x) { return new float3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  2575. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2576. /// <param name="x">Input value.</param>
  2577. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2578. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2579. public static float4 exp10(float4 x) { return new float4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  2580. /// <summary>Returns the base-10 exponential of x.</summary>
  2581. /// <param name="x">Input value.</param>
  2582. /// <returns>The base-10 exponential of the input.</returns>
  2583. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2584. public static double exp10(double x) { return System.Math.Exp(x * 2.302585092994045684); }
  2585. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2586. /// <param name="x">Input value.</param>
  2587. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2588. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2589. public static double2 exp10(double2 x) { return new double2(exp10(x.x), exp10(x.y)); }
  2590. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2591. /// <param name="x">Input value.</param>
  2592. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2593. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2594. public static double3 exp10(double3 x) { return new double3(exp10(x.x), exp10(x.y), exp10(x.z)); }
  2595. /// <summary>Returns the componentwise base-10 exponential of x.</summary>
  2596. /// <param name="x">Input value.</param>
  2597. /// <returns>The componentwise base-10 exponential of the input.</returns>
  2598. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2599. public static double4 exp10(double4 x) { return new double4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); }
  2600. /// <summary>Returns the natural logarithm of a float value.</summary>
  2601. /// <param name="x">Input value.</param>
  2602. /// <returns>The natural logarithm of the input.</returns>
  2603. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2604. public static float log(float x) { return (float)System.Math.Log((float)x); }
  2605. /// <summary>Returns the componentwise natural logarithm of a float2 vector.</summary>
  2606. /// <param name="x">Input value.</param>
  2607. /// <returns>The componentwise natural logarithm of the input.</returns>
  2608. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2609. public static float2 log(float2 x) { return new float2(log(x.x), log(x.y)); }
  2610. /// <summary>Returns the componentwise natural logarithm of a float3 vector.</summary>
  2611. /// <param name="x">Input value.</param>
  2612. /// <returns>The componentwise natural logarithm of the input.</returns>
  2613. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2614. public static float3 log(float3 x) { return new float3(log(x.x), log(x.y), log(x.z)); }
  2615. /// <summary>Returns the componentwise natural logarithm of a float4 vector.</summary>
  2616. /// <param name="x">Input value.</param>
  2617. /// <returns>The componentwise natural logarithm of the input.</returns>
  2618. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2619. public static float4 log(float4 x) { return new float4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  2620. /// <summary>Returns the natural logarithm of a double value.</summary>
  2621. /// <param name="x">Input value.</param>
  2622. /// <returns>The natural logarithm of the input.</returns>
  2623. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2624. public static double log(double x) { return System.Math.Log(x); }
  2625. /// <summary>Returns the componentwise natural logarithm of a double2 vector.</summary>
  2626. /// <param name="x">Input value.</param>
  2627. /// <returns>The componentwise natural logarithm of the input.</returns>
  2628. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2629. public static double2 log(double2 x) { return new double2(log(x.x), log(x.y)); }
  2630. /// <summary>Returns the componentwise natural logarithm of a double3 vector.</summary>
  2631. /// <param name="x">Input value.</param>
  2632. /// <returns>The componentwise natural logarithm of the input.</returns>
  2633. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2634. public static double3 log(double3 x) { return new double3(log(x.x), log(x.y), log(x.z)); }
  2635. /// <summary>Returns the componentwise natural logarithm of a double4 vector.</summary>
  2636. /// <param name="x">Input value.</param>
  2637. /// <returns>The componentwise natural logarithm of the input.</returns>
  2638. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2639. public static double4 log(double4 x) { return new double4(log(x.x), log(x.y), log(x.z), log(x.w)); }
  2640. /// <summary>Returns the base-2 logarithm of a float value.</summary>
  2641. /// <param name="x">Input value.</param>
  2642. /// <returns>The base-2 logarithm of the input.</returns>
  2643. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2644. public static float log2(float x) { return (float)System.Math.Log((float)x, 2.0f); }
  2645. /// <summary>Returns the componentwise base-2 logarithm of a float2 vector.</summary>
  2646. /// <param name="x">Input value.</param>
  2647. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2648. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2649. public static float2 log2(float2 x) { return new float2(log2(x.x), log2(x.y)); }
  2650. /// <summary>Returns the componentwise base-2 logarithm of a float3 vector.</summary>
  2651. /// <param name="x">Input value.</param>
  2652. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2653. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2654. public static float3 log2(float3 x) { return new float3(log2(x.x), log2(x.y), log2(x.z)); }
  2655. /// <summary>Returns the componentwise base-2 logarithm of a float4 vector.</summary>
  2656. /// <param name="x">Input value.</param>
  2657. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2658. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2659. public static float4 log2(float4 x) { return new float4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  2660. /// <summary>Returns the base-2 logarithm of a double value.</summary>
  2661. /// <param name="x">Input value.</param>
  2662. /// <returns>The base-2 logarithm of the input.</returns>
  2663. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2664. public static double log2(double x) { return System.Math.Log(x, 2.0); }
  2665. /// <summary>Returns the componentwise base-2 logarithm of a double2 vector.</summary>
  2666. /// <param name="x">Input value.</param>
  2667. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2668. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2669. public static double2 log2(double2 x) { return new double2(log2(x.x), log2(x.y)); }
  2670. /// <summary>Returns the componentwise base-2 logarithm of a double3 vector.</summary>
  2671. /// <param name="x">Input value.</param>
  2672. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2673. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2674. public static double3 log2(double3 x) { return new double3(log2(x.x), log2(x.y), log2(x.z)); }
  2675. /// <summary>Returns the componentwise base-2 logarithm of a double4 vector.</summary>
  2676. /// <param name="x">Input value.</param>
  2677. /// <returns>The componentwise base-2 logarithm of the input.</returns>
  2678. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2679. public static double4 log2(double4 x) { return new double4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); }
  2680. /// <summary>Returns the base-10 logarithm of a float value.</summary>
  2681. /// <param name="x">Input value.</param>
  2682. /// <returns>The base-10 logarithm of the input.</returns>
  2683. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2684. public static float log10(float x) { return (float)System.Math.Log10((float)x); }
  2685. /// <summary>Returns the componentwise base-10 logarithm of a float2 vector.</summary>
  2686. /// <param name="x">Input value.</param>
  2687. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2688. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2689. public static float2 log10(float2 x) { return new float2(log10(x.x), log10(x.y)); }
  2690. /// <summary>Returns the componentwise base-10 logarithm of a float3 vector.</summary>
  2691. /// <param name="x">Input value.</param>
  2692. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2693. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2694. public static float3 log10(float3 x) { return new float3(log10(x.x), log10(x.y), log10(x.z)); }
  2695. /// <summary>Returns the componentwise base-10 logarithm of a float4 vector.</summary>
  2696. /// <param name="x">Input value.</param>
  2697. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2698. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2699. public static float4 log10(float4 x) { return new float4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  2700. /// <summary>Returns the base-10 logarithm of a double value.</summary>
  2701. /// <param name="x">Input value.</param>
  2702. /// <returns>The base-10 logarithm of the input.</returns>
  2703. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2704. public static double log10(double x) { return System.Math.Log10(x); }
  2705. /// <summary>Returns the componentwise base-10 logarithm of a double2 vector.</summary>
  2706. /// <param name="x">Input value.</param>
  2707. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2708. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2709. public static double2 log10(double2 x) { return new double2(log10(x.x), log10(x.y)); }
  2710. /// <summary>Returns the componentwise base-10 logarithm of a double3 vector.</summary>
  2711. /// <param name="x">Input value.</param>
  2712. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2713. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2714. public static double3 log10(double3 x) { return new double3(log10(x.x), log10(x.y), log10(x.z)); }
  2715. /// <summary>Returns the componentwise base-10 logarithm of a double4 vector.</summary>
  2716. /// <param name="x">Input value.</param>
  2717. /// <returns>The componentwise base-10 logarithm of the input.</returns>
  2718. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2719. public static double4 log10(double4 x) { return new double4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); }
  2720. /// <summary>Returns the floating point remainder of x/y.</summary>
  2721. /// <param name="x">The dividend in x/y.</param>
  2722. /// <param name="y">The divisor in x/y.</param>
  2723. /// <returns>The remainder of x/y.</returns>
  2724. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2725. public static float fmod(float x, float y) { return x % y; }
  2726. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2727. /// <param name="x">The dividend in x/y.</param>
  2728. /// <param name="y">The divisor in x/y.</param>
  2729. /// <returns>The componentwise remainder of x/y.</returns>
  2730. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2731. public static float2 fmod(float2 x, float2 y) { return new float2(x.x % y.x, x.y % y.y); }
  2732. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2733. /// <param name="x">The dividend in x/y.</param>
  2734. /// <param name="y">The divisor in x/y.</param>
  2735. /// <returns>The componentwise remainder of x/y.</returns>
  2736. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2737. public static float3 fmod(float3 x, float3 y) { return new float3(x.x % y.x, x.y % y.y, x.z % y.z); }
  2738. /// <summary>Returns the componentwise floating point remainder of x/y.</summary>
  2739. /// <param name="x">The dividend in x/y.</param>
  2740. /// <param name="y">The divisor in x/y.</param>
  2741. /// <returns>The componentwise remainder of x/y.</returns>
  2742. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2743. 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); }
  2744. /// <summary>Returns the double precision floating point remainder of x/y.</summary>
  2745. /// <param name="x">The dividend in x/y.</param>
  2746. /// <param name="y">The divisor in x/y.</param>
  2747. /// <returns>The remainder of x/y.</returns>
  2748. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2749. public static double fmod(double x, double y) { return x % y; }
  2750. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2751. /// <param name="x">The dividend in x/y.</param>
  2752. /// <param name="y">The divisor in x/y.</param>
  2753. /// <returns>The componentwise remainder of x/y.</returns>
  2754. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2755. public static double2 fmod(double2 x, double2 y) { return new double2(x.x % y.x, x.y % y.y); }
  2756. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2757. /// <param name="x">The dividend in x/y.</param>
  2758. /// <param name="y">The divisor in x/y.</param>
  2759. /// <returns>The componentwise remainder of x/y.</returns>
  2760. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2761. public static double3 fmod(double3 x, double3 y) { return new double3(x.x % y.x, x.y % y.y, x.z % y.z); }
  2762. /// <summary>Returns the componentwise double precision floating point remainder of x/y.</summary>
  2763. /// <param name="x">The dividend in x/y.</param>
  2764. /// <param name="y">The divisor in x/y.</param>
  2765. /// <returns>The componentwise remainder of x/y.</returns>
  2766. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2767. 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); }
  2768. /// <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>
  2769. /// <param name="x">Value to split into integral and fractional part.</param>
  2770. /// <param name="i">Output value containing integral part of x.</param>
  2771. /// <returns>The fractional part of x.</returns>
  2772. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2773. public static float modf(float x, out float i) { i = trunc(x); return x - i; }
  2774. /// <summary>
  2775. /// Performs a componentwise split of a float2 vector into an integral part i and a fractional part that gets returned.
  2776. /// Both parts take the sign of the corresponding input component.
  2777. /// </summary>
  2778. /// <param name="x">Value to split into integral and fractional part.</param>
  2779. /// <param name="i">Output value containing integral part of x.</param>
  2780. /// <returns>The componentwise fractional part of x.</returns>
  2781. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2782. public static float2 modf(float2 x, out float2 i) { i = trunc(x); return x - i; }
  2783. /// <summary>
  2784. /// Performs a componentwise split of a float3 vector into an integral part i and a fractional part that gets returned.
  2785. /// Both parts take the sign of the corresponding input component.
  2786. /// </summary>
  2787. /// <param name="x">Value to split into integral and fractional part.</param>
  2788. /// <param name="i">Output value containing integral part of x.</param>
  2789. /// <returns>The componentwise fractional part of x.</returns>
  2790. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2791. public static float3 modf(float3 x, out float3 i) { i = trunc(x); return x - i; }
  2792. /// <summary>
  2793. /// Performs a componentwise split of a float4 vector into an integral part i and a fractional part that gets returned.
  2794. /// Both parts take the sign of the corresponding input component.
  2795. /// </summary>
  2796. /// <param name="x">Value to split into integral and fractional part.</param>
  2797. /// <param name="i">Output value containing integral part of x.</param>
  2798. /// <returns>The componentwise fractional part of x.</returns>
  2799. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2800. public static float4 modf(float4 x, out float4 i) { i = trunc(x); return x - i; }
  2801. /// <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>
  2802. /// <param name="x">Value to split into integral and fractional part.</param>
  2803. /// <param name="i">Output value containing integral part of x.</param>
  2804. /// <returns>The fractional part of x.</returns>
  2805. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2806. public static double modf(double x, out double i) { i = trunc(x); return x - i; }
  2807. /// <summary>
  2808. /// Performs a componentwise split of a double2 vector into an integral part i and a fractional part that gets returned.
  2809. /// Both parts take the sign of the corresponding input component.
  2810. /// </summary>
  2811. /// <param name="x">Value to split into integral and fractional part.</param>
  2812. /// <param name="i">Output value containing integral part of x.</param>
  2813. /// <returns>The componentwise fractional part of x.</returns>
  2814. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2815. public static double2 modf(double2 x, out double2 i) { i = trunc(x); return x - i; }
  2816. /// <summary>
  2817. /// Performs a componentwise split of a double3 vector into an integral part i and a fractional part that gets returned.
  2818. /// Both parts take the sign of the corresponding input component.
  2819. /// </summary>
  2820. /// <param name="x">Value to split into integral and fractional part.</param>
  2821. /// <param name="i">Output value containing integral part of x.</param>
  2822. /// <returns>The componentwise fractional part of x.</returns>
  2823. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2824. public static double3 modf(double3 x, out double3 i) { i = trunc(x); return x - i; }
  2825. /// <summary>
  2826. /// Performs a componentwise split of a double4 vector into an integral part i and a fractional part that gets returned.
  2827. /// Both parts take the sign of the corresponding input component.
  2828. /// </summary>
  2829. /// <param name="x">Value to split into integral and fractional part.</param>
  2830. /// <param name="i">Output value containing integral part of x.</param>
  2831. /// <returns>The componentwise fractional part of x.</returns>
  2832. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2833. public static double4 modf(double4 x, out double4 i) { i = trunc(x); return x - i; }
  2834. /// <summary>Returns the square root of a float value.</summary>
  2835. /// <param name="x">Value to use when computing square root.</param>
  2836. /// <returns>The square root.</returns>
  2837. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2838. public static float sqrt(float x) { return (float)System.Math.Sqrt((float)x); }
  2839. /// <summary>Returns the componentwise square root of a float2 vector.</summary>
  2840. /// <param name="x">Value to use when computing square root.</param>
  2841. /// <returns>The componentwise square root.</returns>
  2842. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2843. public static float2 sqrt(float2 x) { return new float2(sqrt(x.x), sqrt(x.y)); }
  2844. /// <summary>Returns the componentwise square root of a float3 vector.</summary>
  2845. /// <param name="x">Value to use when computing square root.</param>
  2846. /// <returns>The componentwise square root.</returns>
  2847. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2848. public static float3 sqrt(float3 x) { return new float3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  2849. /// <summary>Returns the componentwise square root of a float4 vector.</summary>
  2850. /// <param name="x">Value to use when computing square root.</param>
  2851. /// <returns>The componentwise square root.</returns>
  2852. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2853. public static float4 sqrt(float4 x) { return new float4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  2854. /// <summary>Returns the square root of a double value.</summary>
  2855. /// <param name="x">Value to use when computing square root.</param>
  2856. /// <returns>The square root.</returns>
  2857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2858. public static double sqrt(double x) { return System.Math.Sqrt(x); }
  2859. /// <summary>Returns the componentwise square root of a double2 vector.</summary>
  2860. /// <param name="x">Value to use when computing square root.</param>
  2861. /// <returns>The componentwise square root.</returns>
  2862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2863. public static double2 sqrt(double2 x) { return new double2(sqrt(x.x), sqrt(x.y)); }
  2864. /// <summary>Returns the componentwise square root of a double3 vector.</summary>
  2865. /// <param name="x">Value to use when computing square root.</param>
  2866. /// <returns>The componentwise square root.</returns>
  2867. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2868. public static double3 sqrt(double3 x) { return new double3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); }
  2869. /// <summary>Returns the componentwise square root of a double4 vector.</summary>
  2870. /// <param name="x">Value to use when computing square root.</param>
  2871. /// <returns>The componentwise square root.</returns>
  2872. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2873. public static double4 sqrt(double4 x) { return new double4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); }
  2874. /// <summary>Returns the reciprocal square root of a float value.</summary>
  2875. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2876. /// <returns>The reciprocal square root.</returns>
  2877. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2878. public static float rsqrt(float x) { return 1.0f / sqrt(x); }
  2879. /// <summary>Returns the componentwise reciprocal square root of a float2 vector.</summary>
  2880. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2881. /// <returns>The componentwise reciprocal square root.</returns>
  2882. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2883. public static float2 rsqrt(float2 x) { return 1.0f / sqrt(x); }
  2884. /// <summary>Returns the componentwise reciprocal square root of a float3 vector.</summary>
  2885. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2886. /// <returns>The componentwise reciprocal square root.</returns>
  2887. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2888. public static float3 rsqrt(float3 x) { return 1.0f / sqrt(x); }
  2889. /// <summary>Returns the componentwise reciprocal square root of a float4 vector</summary>
  2890. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2891. /// <returns>The componentwise reciprocal square root.</returns>
  2892. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2893. public static float4 rsqrt(float4 x) { return 1.0f / sqrt(x); }
  2894. /// <summary>Returns the reciprocal square root of a double value.</summary>
  2895. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2896. /// <returns>The reciprocal square root.</returns>
  2897. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2898. public static double rsqrt(double x) { return 1.0 / sqrt(x); }
  2899. /// <summary>Returns the componentwise reciprocal square root of a double2 vector.</summary>
  2900. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2901. /// <returns>The componentwise reciprocal square root.</returns>
  2902. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2903. public static double2 rsqrt(double2 x) { return 1.0 / sqrt(x); }
  2904. /// <summary>Returns the componentwise reciprocal square root of a double3 vector.</summary>
  2905. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2906. /// <returns>The componentwise reciprocal square root.</returns>
  2907. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2908. public static double3 rsqrt(double3 x) { return 1.0 / sqrt(x); }
  2909. /// <summary>Returns the componentwise reciprocal square root of a double4 vector.</summary>
  2910. /// <param name="x">Value to use when computing reciprocal square root.</param>
  2911. /// <returns>The componentwise reciprocal square root.</returns>
  2912. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2913. public static double4 rsqrt(double4 x) { return 1.0 / sqrt(x); }
  2914. /// <summary>Returns a normalized version of the float2 vector x by scaling it by 1 / length(x).</summary>
  2915. /// <param name="x">Vector to normalize.</param>
  2916. /// <returns>The normalized vector.</returns>
  2917. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2918. public static float2 normalize(float2 x) { return rsqrt(dot(x, x)) * x; }
  2919. /// <summary>Returns a normalized version of the float3 vector x by scaling it by 1 / length(x).</summary>
  2920. /// <param name="x">Vector to normalize.</param>
  2921. /// <returns>The normalized vector.</returns>
  2922. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2923. public static float3 normalize(float3 x) { return rsqrt(dot(x, x)) * x; }
  2924. /// <summary>Returns a normalized version of the float4 vector x by scaling it by 1 / length(x).</summary>
  2925. /// <param name="x">Vector to normalize.</param>
  2926. /// <returns>The normalized vector.</returns>
  2927. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2928. public static float4 normalize(float4 x) { return rsqrt(dot(x, x)) * x; }
  2929. /// <summary>Returns a normalized version of the double2 vector x by scaling it by 1 / length(x).</summary>
  2930. /// <param name="x">Vector to normalize.</param>
  2931. /// <returns>The normalized vector.</returns>
  2932. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2933. public static double2 normalize(double2 x) { return rsqrt(dot(x, x)) * x; }
  2934. /// <summary>Returns a normalized version of the double3 vector x by scaling it by 1 / length(x).</summary>
  2935. /// <param name="x">Vector to normalize.</param>
  2936. /// <returns>The normalized vector.</returns>
  2937. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2938. public static double3 normalize(double3 x) { return rsqrt(dot(x, x)) * x; }
  2939. /// <summary>Returns a normalized version of the double4 vector x by scaling it by 1 / length(x).</summary>
  2940. /// <param name="x">Vector to normalize.</param>
  2941. /// <returns>The normalized vector.</returns>
  2942. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2943. public static double4 normalize(double4 x) { return rsqrt(dot(x, x)) * x; }
  2944. /// <summary>
  2945. /// Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x).
  2946. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2947. /// </summary>
  2948. /// <param name="x">Vector to normalize.</param>
  2949. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2950. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2951. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2952. static public float2 normalizesafe(float2 x, float2 defaultvalue = new float2())
  2953. {
  2954. float len = math.dot(x, x);
  2955. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2956. }
  2957. /// <summary>
  2958. /// Returns a safe normalized version of the float3 vector x by scaling it by 1 / length(x).
  2959. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2960. /// </summary>
  2961. /// <param name="x">Vector to normalize.</param>
  2962. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2963. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2964. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2965. static public float3 normalizesafe(float3 x, float3 defaultvalue = new float3())
  2966. {
  2967. float len = math.dot(x, x);
  2968. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2969. }
  2970. /// <summary>
  2971. /// Returns a safe normalized version of the float4 vector x by scaling it by 1 / length(x).
  2972. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2973. /// </summary>
  2974. /// <param name="x">Vector to normalize.</param>
  2975. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2976. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2977. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2978. static public float4 normalizesafe(float4 x, float4 defaultvalue = new float4())
  2979. {
  2980. float len = math.dot(x, x);
  2981. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2982. }
  2983. /// <summary>
  2984. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  2985. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2986. /// </summary>
  2987. /// <param name="x">Vector to normalize.</param>
  2988. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  2989. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  2990. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  2991. static public double2 normalizesafe(double2 x, double2 defaultvalue = new double2())
  2992. {
  2993. double len = math.dot(x, x);
  2994. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  2995. }
  2996. /// <summary>
  2997. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  2998. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  2999. /// </summary>
  3000. /// <param name="x">Vector to normalize.</param>
  3001. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  3002. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  3003. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3004. static public double3 normalizesafe(double3 x, double3 defaultvalue = new double3())
  3005. {
  3006. double len = math.dot(x, x);
  3007. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  3008. }
  3009. /// <summary>
  3010. /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x).
  3011. /// Returns the given default value when 1 / length(x) does not produce a finite number.
  3012. /// </summary>
  3013. /// <param name="x">Vector to normalize.</param>
  3014. /// <param name="defaultvalue">Vector to return if normalized vector is not finite.</param>
  3015. /// <returns>The normalized vector or the default value if the normalized vector is not finite.</returns>
  3016. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3017. static public double4 normalizesafe(double4 x, double4 defaultvalue = new double4())
  3018. {
  3019. double len = math.dot(x, x);
  3020. return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL);
  3021. }
  3022. /// <summary>Returns the length of a float value. Equivalent to the absolute value.</summary>
  3023. /// <param name="x">Value to use when computing length.</param>
  3024. /// <returns>Length of x.</returns>
  3025. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3026. public static float length(float x) { return abs(x); }
  3027. /// <summary>Returns the length of a float2 vector.</summary>
  3028. /// <param name="x">Vector to use when computing length.</param>
  3029. /// <returns>Length of vector x.</returns>
  3030. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3031. public static float length(float2 x) { return sqrt(dot(x, x)); }
  3032. /// <summary>Returns the length of a float3 vector.</summary>
  3033. /// <param name="x">Vector to use when computing length.</param>
  3034. /// <returns>Length of vector x.</returns>
  3035. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3036. public static float length(float3 x) { return sqrt(dot(x, x)); }
  3037. /// <summary>Returns the length of a float4 vector.</summary>
  3038. /// <param name="x">Vector to use when computing length.</param>
  3039. /// <returns>Length of vector x.</returns>
  3040. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3041. public static float length(float4 x) { return sqrt(dot(x, x)); }
  3042. /// <summary>Returns the length of a double value. Equivalent to the absolute value.</summary>
  3043. /// <param name="x">Value to use when computing squared length.</param>
  3044. /// <returns>Squared length of x.</returns>
  3045. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3046. public static double length(double x) { return abs(x); }
  3047. /// <summary>Returns the length of a double2 vector.</summary>
  3048. /// <param name="x">Vector to use when computing squared length.</param>
  3049. /// <returns>Squared length of vector x.</returns>
  3050. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3051. public static double length(double2 x) { return sqrt(dot(x, x)); }
  3052. /// <summary>Returns the length of a double3 vector.</summary>
  3053. /// <param name="x">Vector to use when computing squared length.</param>
  3054. /// <returns>Squared length of vector x.</returns>
  3055. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3056. public static double length(double3 x) { return sqrt(dot(x, x)); }
  3057. /// <summary>Returns the length of a double4 vector.</summary>
  3058. /// <param name="x">Vector to use when computing squared length.</param>
  3059. /// <returns>Squared length of vector x.</returns>
  3060. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3061. public static double length(double4 x) { return sqrt(dot(x, x)); }
  3062. /// <summary>Returns the squared length of a float value. Equivalent to squaring the value.</summary>
  3063. /// <param name="x">Value to use when computing squared length.</param>
  3064. /// <returns>Squared length of x.</returns>
  3065. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3066. public static float lengthsq(float x) { return x*x; }
  3067. /// <summary>Returns the squared length of a float2 vector.</summary>
  3068. /// <param name="x">Vector to use when computing squared length.</param>
  3069. /// <returns>Squared length of vector x.</returns>
  3070. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3071. public static float lengthsq(float2 x) { return dot(x, x); }
  3072. /// <summary>Returns the squared length of a float3 vector.</summary>
  3073. /// <param name="x">Vector to use when computing squared length.</param>
  3074. /// <returns>Squared length of vector x.</returns>
  3075. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3076. public static float lengthsq(float3 x) { return dot(x, x); }
  3077. /// <summary>Returns the squared length of a float4 vector.</summary>
  3078. /// <param name="x">Vector to use when computing squared length.</param>
  3079. /// <returns>Squared length of vector x.</returns>
  3080. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3081. public static float lengthsq(float4 x) { return dot(x, x); }
  3082. /// <summary>Returns the squared length of a double value. Equivalent to squaring the value.</summary>
  3083. /// <param name="x">Value to use when computing squared length.</param>
  3084. /// <returns>Squared length of x.</returns>
  3085. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3086. public static double lengthsq(double x) { return x * x; }
  3087. /// <summary>Returns the squared length of a double2 vector.</summary>
  3088. /// <param name="x">Vector to use when computing squared length.</param>
  3089. /// <returns>Squared length of vector x.</returns>
  3090. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3091. public static double lengthsq(double2 x) { return dot(x, x); }
  3092. /// <summary>Returns the squared length of a double3 vector.</summary>
  3093. /// <param name="x">Vector to use when computing squared length.</param>
  3094. /// <returns>Squared length of vector x.</returns>
  3095. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3096. public static double lengthsq(double3 x) { return dot(x, x); }
  3097. /// <summary>Returns the squared length of a double4 vector.</summary>
  3098. /// <param name="x">Vector to use when computing squared length.</param>
  3099. /// <returns>Squared length of vector x.</returns>
  3100. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3101. public static double lengthsq(double4 x) { return dot(x, x); }
  3102. /// <summary>Returns the distance between two float values.</summary>
  3103. /// <param name="x">First value to use in distance computation.</param>
  3104. /// <param name="y">Second value to use in distance computation.</param>
  3105. /// <returns>The distance between x and y.</returns>
  3106. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3107. public static float distance(float x, float y) { return abs(y - x); }
  3108. /// <summary>Returns the distance between two float2 vectors.</summary>
  3109. /// <param name="x">First vector to use in distance computation.</param>
  3110. /// <param name="y">Second vector to use in distance computation.</param>
  3111. /// <returns>The distance between x and y.</returns>
  3112. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3113. public static float distance(float2 x, float2 y) { return length(y - x); }
  3114. /// <summary>Returns the distance between two float3 vectors.</summary>
  3115. /// <param name="x">First vector to use in distance computation.</param>
  3116. /// <param name="y">Second vector to use in distance computation.</param>
  3117. /// <returns>The distance between x and y.</returns>
  3118. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3119. public static float distance(float3 x, float3 y) { return length(y - x); }
  3120. /// <summary>Returns the distance between two float4 vectors.</summary>
  3121. /// <param name="x">First vector to use in distance computation.</param>
  3122. /// <param name="y">Second vector to use in distance computation.</param>
  3123. /// <returns>The distance between x and y.</returns>
  3124. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3125. public static float distance(float4 x, float4 y) { return length(y - x); }
  3126. /// <summary>Returns the distance between two double values.</summary>
  3127. /// <param name="x">First value to use in distance computation.</param>
  3128. /// <param name="y">Second value to use in distance computation.</param>
  3129. /// <returns>The distance between x and y.</returns>
  3130. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3131. public static double distance(double x, double y) { return abs(y - x); }
  3132. /// <summary>Returns the distance between two double2 vectors.</summary>
  3133. /// <param name="x">First vector to use in distance computation.</param>
  3134. /// <param name="y">Second vector to use in distance computation.</param>
  3135. /// <returns>The distance between x and y.</returns>
  3136. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3137. public static double distance(double2 x, double2 y) { return length(y - x); }
  3138. /// <summary>Returns the distance between two double3 vectors.</summary>
  3139. /// <param name="x">First vector to use in distance computation.</param>
  3140. /// <param name="y">Second vector to use in distance computation.</param>
  3141. /// <returns>The distance between x and y.</returns>
  3142. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3143. public static double distance(double3 x, double3 y) { return length(y - x); }
  3144. /// <summary>Returns the distance between two double4 vectors.</summary>
  3145. /// <param name="x">First vector to use in distance computation.</param>
  3146. /// <param name="y">Second vector to use in distance computation.</param>
  3147. /// <returns>The distance between x and y.</returns>
  3148. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3149. public static double distance(double4 x, double4 y) { return length(y - x); }
  3150. /// <summary>Returns the squared distance between two float values.</summary>
  3151. /// <param name="x">First value to use in distance computation.</param>
  3152. /// <param name="y">Second value to use in distance computation.</param>
  3153. /// <returns>The squared distance between x and y.</returns>
  3154. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3155. public static float distancesq(float x, float y) { return (y - x) * (y - x); }
  3156. /// <summary>Returns the squared distance between two float2 vectors.</summary>
  3157. /// <param name="x">First vector to use in distance computation.</param>
  3158. /// <param name="y">Second vector to use in distance computation.</param>
  3159. /// <returns>The squared distance between x and y.</returns>
  3160. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3161. public static float distancesq(float2 x, float2 y) { return lengthsq(y - x); }
  3162. /// <summary>Returns the squared distance between two float3 vectors.</summary>
  3163. /// <param name="x">First vector to use in distance computation.</param>
  3164. /// <param name="y">Second vector to use in distance computation.</param>
  3165. /// <returns>The squared distance between x and y.</returns>
  3166. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3167. public static float distancesq(float3 x, float3 y) { return lengthsq(y - x); }
  3168. /// <summary>Returns the squared distance between two float4 vectors.</summary>
  3169. /// <param name="x">First vector to use in distance computation.</param>
  3170. /// <param name="y">Second vector to use in distance computation.</param>
  3171. /// <returns>The squared distance between x and y.</returns>
  3172. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3173. public static float distancesq(float4 x, float4 y) { return lengthsq(y - x); }
  3174. /// <summary>Returns the squared distance between two double values.</summary>
  3175. /// <param name="x">First value to use in distance computation.</param>
  3176. /// <param name="y">Second value to use in distance computation.</param>
  3177. /// <returns>The squared distance between x and y.</returns>
  3178. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3179. public static double distancesq(double x, double y) { return (y - x) * (y - x); }
  3180. /// <summary>Returns the squared distance between two double2 vectors.</summary>
  3181. /// <param name="x">First vector to use in distance computation.</param>
  3182. /// <param name="y">Second vector to use in distance computation.</param>
  3183. /// <returns>The squared distance between x and y.</returns>
  3184. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3185. public static double distancesq(double2 x, double2 y) { return lengthsq(y - x); }
  3186. /// <summary>Returns the squared distance between two double3 vectors.</summary>
  3187. /// <param name="x">First vector to use in distance computation.</param>
  3188. /// <param name="y">Second vector to use in distance computation.</param>
  3189. /// <returns>The squared distance between x and y.</returns>
  3190. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3191. public static double distancesq(double3 x, double3 y) { return lengthsq(y - x); }
  3192. /// <summary>Returns the squared distance between two double4 vectors.</summary>
  3193. /// <param name="x">First vector to use in distance computation.</param>
  3194. /// <param name="y">Second vector to use in distance computation.</param>
  3195. /// <returns>The squared distance between x and y.</returns>
  3196. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3197. public static double distancesq(double4 x, double4 y) { return lengthsq(y - x); }
  3198. /// <summary>Returns the cross product of two float3 vectors.</summary>
  3199. /// <param name="x">First vector to use in cross product.</param>
  3200. /// <param name="y">Second vector to use in cross product.</param>
  3201. /// <returns>The cross product of x and y.</returns>
  3202. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3203. public static float3 cross(float3 x, float3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  3204. /// <summary>Returns the cross product of two double3 vectors.</summary>
  3205. /// <param name="x">First vector to use in cross product.</param>
  3206. /// <param name="y">Second vector to use in cross product.</param>
  3207. /// <returns>The cross product of x and y.</returns>
  3208. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3209. public static double3 cross(double3 x, double3 y) { return (x * y.yzx - x.yzx * y).yzx; }
  3210. /// <summary>Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax].</summary>
  3211. /// <param name="xMin">The minimum range of the x parameter.</param>
  3212. /// <param name="xMax">The maximum range of the x parameter.</param>
  3213. /// <param name="x">The value to be interpolated.</param>
  3214. /// <returns>Returns a value camped to the range [0, 1].</returns>
  3215. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3216. public static float smoothstep(float xMin, float xMax, float x)
  3217. {
  3218. var t = saturate((x - xMin) / (xMax - xMin));
  3219. return t * t * (3.0f - (2.0f * t));
  3220. }
  3221. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax].</summary>
  3222. /// <param name="xMin">The minimum range of the x parameter.</param>
  3223. /// <param name="xMax">The maximum range of the x parameter.</param>
  3224. /// <param name="x">The value to be interpolated.</param>
  3225. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3226. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3227. public static float2 smoothstep(float2 xMin, float2 xMax, float2 x)
  3228. {
  3229. var t = saturate((x - xMin) / (xMax - xMin));
  3230. return t * t * (3.0f - (2.0f * t));
  3231. }
  3232. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax].</summary>
  3233. /// <param name="xMin">The minimum range of the x parameter.</param>
  3234. /// <param name="xMax">The maximum range of the x parameter.</param>
  3235. /// <param name="x">The value to be interpolated.</param>
  3236. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3237. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3238. public static float3 smoothstep(float3 xMin, float3 xMax, float3 x)
  3239. {
  3240. var t = saturate((x - xMin) / (xMax - xMin));
  3241. return t * t * (3.0f - (2.0f * t));
  3242. }
  3243. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in the interval (inclusive) [xMin, xMax].</summary>
  3244. /// <param name="xMin">The minimum range of the x parameter.</param>
  3245. /// <param name="xMax">The maximum range of the x parameter.</param>
  3246. /// <param name="x">The value to be interpolated.</param>
  3247. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3248. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3249. public static float4 smoothstep(float4 xMin, float4 xMax, float4 x)
  3250. {
  3251. var t = saturate((x - xMin) / (xMax - xMin));
  3252. return t * t * (3.0f - (2.0f * t));
  3253. }
  3254. /// <summary>Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax].</summary>
  3255. /// <param name="xMin">The minimum range of the x parameter.</param>
  3256. /// <param name="xMax">The maximum range of the x parameter.</param>
  3257. /// <param name="x">The value to be interpolated.</param>
  3258. /// <returns>Returns a value camped to the range [0, 1].</returns>
  3259. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3260. public static double smoothstep(double xMin, double xMax, double x)
  3261. {
  3262. var t = saturate((x - xMin) / (xMax - xMin));
  3263. return t * t * (3.0 - (2.0 * t));
  3264. }
  3265. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax].</summary>
  3266. /// <param name="xMin">The minimum range of the x parameter.</param>
  3267. /// <param name="xMax">The maximum range of the x parameter.</param>
  3268. /// <param name="x">The value to be interpolated.</param>
  3269. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3270. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3271. public static double2 smoothstep(double2 xMin, double2 xMax, double2 x)
  3272. {
  3273. var t = saturate((x - xMin) / (xMax - xMin));
  3274. return t * t * (3.0 - (2.0 * t));
  3275. }
  3276. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax].</summary>
  3277. /// <param name="xMin">The minimum range of the x parameter.</param>
  3278. /// <param name="xMax">The maximum range of the x parameter.</param>
  3279. /// <param name="x">The value to be interpolated.</param>
  3280. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3281. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3282. public static double3 smoothstep(double3 xMin, double3 xMax, double3 x)
  3283. {
  3284. var t = saturate((x - xMin) / (xMax - xMin));
  3285. return t * t * (3.0 - (2.0 * t));
  3286. }
  3287. /// <summary>Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in the interval (inclusive) [xMin, xMax].</summary>
  3288. /// <param name="xMin">The minimum range of the x parameter.</param>
  3289. /// <param name="xMax">The maximum range of the x parameter.</param>
  3290. /// <param name="x">The value to be interpolated.</param>
  3291. /// <returns>Returns component values camped to the range [0, 1].</returns>
  3292. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3293. public static double4 smoothstep(double4 xMin, double4 xMax, double4 x)
  3294. {
  3295. var t = saturate((x - xMin) / (xMax - xMin));
  3296. return t * t * (3.0 - (2.0 * t));
  3297. }
  3298. /// <summary>Returns true if any component of the input bool2 vector is true, false otherwise.</summary>
  3299. /// <param name="x">Vector of values to compare.</param>
  3300. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3301. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3302. public static bool any(bool2 x) { return x.x || x.y; }
  3303. /// <summary>Returns true if any component of the input bool3 vector is true, false otherwise.</summary>
  3304. /// <param name="x">Vector of values to compare.</param>
  3305. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3306. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3307. public static bool any(bool3 x) { return x.x || x.y || x.z; }
  3308. /// <summary>Returns true if any components of the input bool4 vector is true, false otherwise.</summary>
  3309. /// <param name="x">Vector of values to compare.</param>
  3310. /// <returns>True if any the components of x are true, false otherwise.</returns>
  3311. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3312. public static bool any(bool4 x) { return x.x || x.y || x.z || x.w; }
  3313. /// <summary>Returns true if any component of the input int2 vector is non-zero, false otherwise.</summary>
  3314. /// <param name="x">Vector of values to compare.</param>
  3315. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3316. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3317. public static bool any(int2 x) { return x.x != 0 || x.y != 0; }
  3318. /// <summary>Returns true if any component of the input int3 vector is non-zero, false otherwise.</summary>
  3319. /// <param name="x">Vector of values to compare.</param>
  3320. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3321. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3322. public static bool any(int3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  3323. /// <summary>Returns true if any components of the input int4 vector is non-zero, false otherwise.</summary>
  3324. /// <param name="x">Vector of values to compare.</param>
  3325. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3326. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3327. public static bool any(int4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  3328. /// <summary>Returns true if any component of the input uint2 vector is non-zero, false otherwise.</summary>
  3329. /// <param name="x">Vector of values to compare.</param>
  3330. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3331. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3332. public static bool any(uint2 x) { return x.x != 0 || x.y != 0; }
  3333. /// <summary>Returns true if any component of the input uint3 vector is non-zero, false otherwise.</summary>
  3334. /// <param name="x">Vector of values to compare.</param>
  3335. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3336. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3337. public static bool any(uint3 x) { return x.x != 0 || x.y != 0 || x.z != 0; }
  3338. /// <summary>Returns true if any components of the input uint4 vector is non-zero, false otherwise.</summary>
  3339. /// <param name="x">Vector of values to compare.</param>
  3340. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3341. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3342. public static bool any(uint4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; }
  3343. /// <summary>Returns true if any component of the input float2 vector is non-zero, false otherwise.</summary>
  3344. /// <param name="x">Vector of values to compare.</param>
  3345. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3346. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3347. public static bool any(float2 x) { return x.x != 0.0f || x.y != 0.0f; }
  3348. /// <summary>Returns true if any component of the input float3 vector is non-zero, false otherwise.</summary>
  3349. /// <param name="x">Vector of values to compare.</param>
  3350. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3352. public static bool any(float3 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f; }
  3353. /// <summary>Returns true if any component of the input float4 vector is non-zero, false otherwise.</summary>
  3354. /// <param name="x">Vector of values to compare.</param>
  3355. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3356. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3357. public static bool any(float4 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f || x.w != 0.0f; }
  3358. /// <summary>Returns true if any component of the input double2 vector is non-zero, false otherwise.</summary>
  3359. /// <param name="x">Vector of values to compare.</param>
  3360. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3361. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3362. public static bool any(double2 x) { return x.x != 0.0 || x.y != 0.0; }
  3363. /// <summary>Returns true if any component of the input double3 vector is non-zero, false otherwise.</summary>
  3364. /// <param name="x">Vector of values to compare.</param>
  3365. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3366. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3367. public static bool any(double3 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0; }
  3368. /// <summary>Returns true if any component of the input double4 vector is non-zero, false otherwise.</summary>
  3369. /// <param name="x">Vector of values to compare.</param>
  3370. /// <returns>True if any the components of x are non-zero, false otherwise.</returns>
  3371. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3372. public static bool any(double4 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0 || x.w != 0.0; }
  3373. /// <summary>Returns true if all components of the input bool2 vector are true, false otherwise.</summary>
  3374. /// <param name="x">Vector of values to compare.</param>
  3375. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3376. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3377. public static bool all(bool2 x) { return x.x && x.y; }
  3378. /// <summary>Returns true if all components of the input bool3 vector are true, false otherwise.</summary>
  3379. /// <param name="x">Vector of values to compare.</param>
  3380. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3381. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3382. public static bool all(bool3 x) { return x.x && x.y && x.z; }
  3383. /// <summary>Returns true if all components of the input bool4 vector are true, false otherwise.</summary>
  3384. /// <param name="x">Vector of values to compare.</param>
  3385. /// <returns>True if all the components of x are true, false otherwise.</returns>
  3386. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3387. public static bool all(bool4 x) { return x.x && x.y && x.z && x.w; }
  3388. /// <summary>Returns true if all components of the input int2 vector are non-zero, false otherwise.</summary>
  3389. /// <param name="x">Vector of values to compare.</param>
  3390. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3391. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3392. public static bool all(int2 x) { return x.x != 0 && x.y != 0; }
  3393. /// <summary>Returns true if all components of the input int3 vector are non-zero, false otherwise.</summary>
  3394. /// <param name="x">Vector of values to compare.</param>
  3395. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3396. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3397. public static bool all(int3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  3398. /// <summary>Returns true if all components of the input int4 vector are non-zero, false otherwise.</summary>
  3399. /// <param name="x">Vector of values to compare.</param>
  3400. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3401. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3402. public static bool all(int4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  3403. /// <summary>Returns true if all components of the input uint2 vector are non-zero, false otherwise.</summary>
  3404. /// <param name="x">Vector of values to compare.</param>
  3405. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3406. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3407. public static bool all(uint2 x) { return x.x != 0 && x.y != 0; }
  3408. /// <summary>Returns true if all components of the input uint3 vector are non-zero, false otherwise.</summary>
  3409. /// <param name="x">Vector of values to compare.</param>
  3410. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3411. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3412. public static bool all(uint3 x) { return x.x != 0 && x.y != 0 && x.z != 0; }
  3413. /// <summary>Returns true if all components of the input uint4 vector are non-zero, false otherwise.</summary>
  3414. /// <param name="x">Vector of values to compare.</param>
  3415. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3416. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3417. public static bool all(uint4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; }
  3418. /// <summary>Returns true if all components of the input float2 vector are non-zero, false otherwise.</summary>
  3419. /// <param name="x">Vector of values to compare.</param>
  3420. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3421. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3422. public static bool all(float2 x) { return x.x != 0.0f && x.y != 0.0f; }
  3423. /// <summary>Returns true if all components of the input float3 vector are non-zero, false otherwise.</summary>
  3424. /// <param name="x">Vector of values to compare.</param>
  3425. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3426. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3427. public static bool all(float3 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f; }
  3428. /// <summary>Returns true if all components of the input float4 vector are non-zero, false otherwise.</summary>
  3429. /// <param name="x">Vector of values to compare.</param>
  3430. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3431. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3432. public static bool all(float4 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f && x.w != 0.0f; }
  3433. /// <summary>Returns true if all components of the input double2 vector are non-zero, false otherwise.</summary>
  3434. /// <param name="x">Vector of values to compare.</param>
  3435. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3436. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3437. public static bool all(double2 x) { return x.x != 0.0 && x.y != 0.0; }
  3438. /// <summary>Returns true if all components of the input double3 vector are non-zero, false otherwise.</summary>
  3439. /// <param name="x">Vector of values to compare.</param>
  3440. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3441. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3442. public static bool all(double3 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0; }
  3443. /// <summary>Returns true if all components of the input double4 vector are non-zero, false otherwise.</summary>
  3444. /// <param name="x">Vector of values to compare.</param>
  3445. /// <returns>True if all the components of x are non-zero, false otherwise.</returns>
  3446. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3447. public static bool all(double4 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0 && x.w != 0.0; }
  3448. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3449. /// <param name="falseValue">Value to use if test is false.</param>
  3450. /// <param name="trueValue">Value to use if test is true.</param>
  3451. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3452. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3453. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3454. public static int select(int falseValue, int trueValue, bool test) { return test ? trueValue : falseValue; }
  3455. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3456. /// <param name="falseValue">Value to use if test is false.</param>
  3457. /// <param name="trueValue">Value to use if test is true.</param>
  3458. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3459. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3460. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3461. public static int2 select(int2 falseValue, int2 trueValue, bool test) { return test ? trueValue : falseValue; }
  3462. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3463. /// <param name="falseValue">Value to use if test is false.</param>
  3464. /// <param name="trueValue">Value to use if test is true.</param>
  3465. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3466. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3467. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3468. public static int3 select(int3 falseValue, int3 trueValue, bool test) { return test ? trueValue : falseValue; }
  3469. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3470. /// <param name="falseValue">Value to use if test is false.</param>
  3471. /// <param name="trueValue">Value to use if test is true.</param>
  3472. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3473. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3474. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3475. public static int4 select(int4 falseValue, int4 trueValue, bool test) { return test ? trueValue : falseValue; }
  3476. /// <summary>
  3477. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3478. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3479. /// </summary>
  3480. /// <param name="falseValue">Values to use if test is false.</param>
  3481. /// <param name="trueValue">Values to use if test is true.</param>
  3482. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3483. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3484. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3485. public static int2 select(int2 falseValue, int2 trueValue, bool2 test) { return new int2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); }
  3486. /// <summary>
  3487. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3488. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3489. /// </summary>
  3490. /// <param name="falseValue">Values to use if test is false.</param>
  3491. /// <param name="trueValue">Values to use if test is true.</param>
  3492. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3493. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3494. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3495. public static int3 select(int3 falseValue, int3 trueValue, bool3 test) { return new int3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); }
  3496. /// <summary>
  3497. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3498. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3499. /// </summary>
  3500. /// <param name="falseValue">Values to use if test is false.</param>
  3501. /// <param name="trueValue">Values to use if test is true.</param>
  3502. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3503. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3504. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3505. public static int4 select(int4 falseValue, int4 trueValue, bool4 test) { return new int4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); }
  3506. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3507. /// <param name="falseValue">Value to use if test is false.</param>
  3508. /// <param name="trueValue">Value to use if test is true.</param>
  3509. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3510. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3511. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3512. public static uint select(uint falseValue, uint trueValue, bool test) { return test ? trueValue : falseValue; }
  3513. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3514. /// <param name="falseValue">Value to use if test is false.</param>
  3515. /// <param name="trueValue">Value to use if test is true.</param>
  3516. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3517. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3518. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3519. public static uint2 select(uint2 falseValue, uint2 trueValue, bool test) { return test ? trueValue : falseValue; }
  3520. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3521. /// <param name="falseValue">Value to use if test is false.</param>
  3522. /// <param name="trueValue">Value to use if test is true.</param>
  3523. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3524. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3525. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3526. public static uint3 select(uint3 falseValue, uint3 trueValue, bool test) { return test ? trueValue : falseValue; }
  3527. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3528. /// <param name="falseValue">Value to use if test is false.</param>
  3529. /// <param name="trueValue">Value to use if test is true.</param>
  3530. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3531. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3532. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3533. public static uint4 select(uint4 falseValue, uint4 trueValue, bool test) { return test ? trueValue : falseValue; }
  3534. /// <summary>
  3535. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3536. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3537. /// </summary>
  3538. /// <param name="falseValue">Values to use if test is false.</param>
  3539. /// <param name="trueValue">Values to use if test is true.</param>
  3540. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3541. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3542. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3543. public static uint2 select(uint2 falseValue, uint2 trueValue, bool2 test) { return new uint2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); }
  3544. /// <summary>
  3545. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3546. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3547. /// </summary>
  3548. /// <param name="falseValue">Values to use if test is false.</param>
  3549. /// <param name="trueValue">Values to use if test is true.</param>
  3550. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3551. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3552. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3553. public static uint3 select(uint3 falseValue, uint3 trueValue, bool3 test) { return new uint3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); }
  3554. /// <summary>
  3555. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3556. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3557. /// </summary>
  3558. /// <param name="falseValue">Values to use if test is false.</param>
  3559. /// <param name="trueValue">Values to use if test is true.</param>
  3560. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3561. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3562. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3563. public static uint4 select(uint4 falseValue, uint4 trueValue, bool4 test) { return new uint4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); }
  3564. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3565. /// <param name="falseValue">Value to use if test is false.</param>
  3566. /// <param name="trueValue">Value to use if test is true.</param>
  3567. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3568. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3569. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3570. public static long select(long falseValue, long trueValue, bool test) { return test ? trueValue : falseValue; }
  3571. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3572. /// <param name="falseValue">Value to use if test is false.</param>
  3573. /// <param name="trueValue">Value to use if test is true.</param>
  3574. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3575. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3576. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3577. public static ulong select(ulong falseValue, ulong trueValue, bool test) { return test ? trueValue : falseValue; }
  3578. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3579. /// <param name="falseValue">Value to use if test is false.</param>
  3580. /// <param name="trueValue">Value to use if test is true.</param>
  3581. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3582. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3583. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3584. public static float select(float falseValue, float trueValue, bool test) { return test ? trueValue : falseValue; }
  3585. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3586. /// <param name="falseValue">Value to use if test is false.</param>
  3587. /// <param name="trueValue">Value to use if test is true.</param>
  3588. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3589. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3590. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3591. public static float2 select(float2 falseValue, float2 trueValue, bool test) { return test ? trueValue : falseValue; }
  3592. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3593. /// <param name="falseValue">Value to use if test is false.</param>
  3594. /// <param name="trueValue">Value to use if test is true.</param>
  3595. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3596. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3597. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3598. public static float3 select(float3 falseValue, float3 trueValue, bool test) { return test ? trueValue : falseValue; }
  3599. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3600. /// <param name="falseValue">Value to use if test is false.</param>
  3601. /// <param name="trueValue">Value to use if test is true.</param>
  3602. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3603. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3604. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3605. public static float4 select(float4 falseValue, float4 trueValue, bool test) { return test ? trueValue : falseValue; }
  3606. /// <summary>
  3607. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3608. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3609. /// </summary>
  3610. /// <param name="falseValue">Values to use if test is false.</param>
  3611. /// <param name="trueValue">Values to use if test is true.</param>
  3612. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3613. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3614. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3615. public static float2 select(float2 falseValue, float2 trueValue, bool2 test) { return new float2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); }
  3616. /// <summary>
  3617. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3618. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3619. /// </summary>
  3620. /// <param name="falseValue">Values to use if test is false.</param>
  3621. /// <param name="trueValue">Values to use if test is true.</param>
  3622. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3623. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3624. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3625. public static float3 select(float3 falseValue, float3 trueValue, bool3 test) { return new float3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); }
  3626. /// <summary>
  3627. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3628. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3629. /// </summary>
  3630. /// <param name="falseValue">Values to use if test is false.</param>
  3631. /// <param name="trueValue">Values to use if test is true.</param>
  3632. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3633. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3634. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3635. public static float4 select(float4 falseValue, float4 trueValue, bool4 test) { return new float4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); }
  3636. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3637. /// <param name="falseValue">Value to use if test is false.</param>
  3638. /// <param name="trueValue">Value to use if test is true.</param>
  3639. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3640. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3641. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3642. public static double select(double falseValue, double trueValue, bool test) { return test ? trueValue : falseValue; }
  3643. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3644. /// <param name="falseValue">Value to use if test is false.</param>
  3645. /// <param name="trueValue">Value to use if test is true.</param>
  3646. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3647. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3648. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3649. public static double2 select(double2 falseValue, double2 trueValue, bool test) { return test ? trueValue : falseValue; }
  3650. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3651. /// <param name="falseValue">Value to use if test is false.</param>
  3652. /// <param name="trueValue">Value to use if test is true.</param>
  3653. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3654. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3655. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3656. public static double3 select(double3 falseValue, double3 trueValue, bool test) { return test ? trueValue : falseValue; }
  3657. /// <summary>Returns trueValue if test is true, falseValue otherwise.</summary>
  3658. /// <param name="falseValue">Value to use if test is false.</param>
  3659. /// <param name="trueValue">Value to use if test is true.</param>
  3660. /// <param name="test">Bool value to choose between falseValue and trueValue.</param>
  3661. /// <returns>The selection between falseValue and trueValue according to bool test.</returns>
  3662. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3663. public static double4 select(double4 falseValue, double4 trueValue, bool test) { return test ? trueValue : falseValue; }
  3664. /// <summary>
  3665. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3666. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3667. /// </summary>
  3668. /// <param name="falseValue">Values to use if test is false.</param>
  3669. /// <param name="trueValue">Values to use if test is true.</param>
  3670. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3671. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3672. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3673. public static double2 select(double2 falseValue, double2 trueValue, bool2 test) { return new double2(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y); }
  3674. /// <summary>
  3675. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3676. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3677. /// </summary>
  3678. /// <param name="falseValue">Values to use if test is false.</param>
  3679. /// <param name="trueValue">Values to use if test is true.</param>
  3680. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3681. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3682. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3683. public static double3 select(double3 falseValue, double3 trueValue, bool3 test) { return new double3(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z); }
  3684. /// <summary>
  3685. /// Returns a componentwise selection between two double4 vectors falseValue and trueValue based on a bool4 selection mask test.
  3686. /// Per component, the component from trueValue is selected when test is true, otherwise the component from falseValue is selected.
  3687. /// </summary>
  3688. /// <param name="falseValue">Values to use if test is false.</param>
  3689. /// <param name="trueValue">Values to use if test is true.</param>
  3690. /// <param name="test">Selection mask to choose between falseValue and trueValue.</param>
  3691. /// <returns>The componentwise selection between falseValue and trueValue according to selection mask test.</returns>
  3692. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3693. public static double4 select(double4 falseValue, double4 trueValue, bool4 test) { return new double4(test.x ? trueValue.x : falseValue.x, test.y ? trueValue.y : falseValue.y, test.z ? trueValue.z : falseValue.z, test.w ? trueValue.w : falseValue.w); }
  3694. /// <summary>Returns the result of a step function where the result is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3695. /// <param name="threshold">Value to be used as a threshold for returning 1.</param>
  3696. /// <param name="x">Value to compare against threshold.</param>
  3697. /// <returns>1 if the comparison x &gt;= threshold is true, otherwise 0.</returns>
  3698. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3699. public static float step(float threshold, float x) { return select(0.0f, 1.0f, x >= threshold); }
  3700. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3701. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3702. /// <param name="x">Vector of values to compare against threshold.</param>
  3703. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3704. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3705. public static float2 step(float2 threshold, float2 x) { return select(float2(0.0f), float2(1.0f), x >= threshold); }
  3706. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3707. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3708. /// <param name="x">Vector of values to compare against threshold.</param>
  3709. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3710. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3711. public static float3 step(float3 threshold, float3 x) { return select(float3(0.0f), float3(1.0f), x >= threshold); }
  3712. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3713. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3714. /// <param name="x">Vector of values to compare against threshold.</param>
  3715. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3716. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3717. public static float4 step(float4 threshold, float4 x) { return select(float4(0.0f), float4(1.0f), x >= threshold); }
  3718. /// <summary>Returns the result of a step function where the result is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3719. /// <param name="threshold">Values to be used as a threshold for returning 1.</param>
  3720. /// <param name="x">Value to compare against threshold.</param>
  3721. /// <returns>1 if the comparison x &gt;= threshold is true, otherwise 0.</returns>
  3722. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3723. public static double step(double threshold, double x) { return select(0.0, 1.0, x >= threshold); }
  3724. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3725. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3726. /// <param name="x">Vector of values to compare against threshold.</param>
  3727. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3728. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3729. public static double2 step(double2 threshold, double2 x) { return select(double2(0.0), double2(1.0), x >= threshold); }
  3730. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3731. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3732. /// <param name="x">Vector of values to compare against threshold.</param>
  3733. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3734. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3735. public static double3 step(double3 threshold, double3 x) { return select(double3(0.0), double3(1.0), x >= threshold); }
  3736. /// <summary>Returns the result of a componentwise step function where each component is 1.0f when x &gt;= threshold and 0.0f otherwise.</summary>
  3737. /// <param name="threshold">Vector of values to be used as a threshold for returning 1.</param>
  3738. /// <param name="x">Vector of values to compare against threshold.</param>
  3739. /// <returns>1 if the componentwise comparison x &gt;= threshold is true, otherwise 0.</returns>
  3740. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3741. public static double4 step(double4 threshold, double4 x) { return select(double4(0.0), double4(1.0), x >= threshold); }
  3742. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3743. /// <param name="i">Incident vector.</param>
  3744. /// <param name="n">Normal vector.</param>
  3745. /// <returns>Reflection vector.</returns>
  3746. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3747. public static float2 reflect(float2 i, float2 n) { return i - 2f * n * dot(i, n); }
  3748. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3749. /// <param name="i">Incident vector.</param>
  3750. /// <param name="n">Normal vector.</param>
  3751. /// <returns>Reflection vector.</returns>
  3752. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3753. public static float3 reflect(float3 i, float3 n) { return i - 2f * n * dot(i, n); }
  3754. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n.</summary>
  3755. /// <param name="i">Incident vector.</param>
  3756. /// <param name="n">Normal vector.</param>
  3757. /// <returns>Reflection vector.</returns>
  3758. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3759. public static float4 reflect(float4 i, float4 n) { return i - 2f * n * dot(i, n); }
  3760. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3761. /// <param name="i">Incident vector.</param>
  3762. /// <param name="n">Normal vector.</param>
  3763. /// <returns>Reflection vector.</returns>
  3764. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3765. public static double2 reflect(double2 i, double2 n) { return i - 2 * n * dot(i, n); }
  3766. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3767. /// <param name="i">Incident vector.</param>
  3768. /// <param name="n">Normal vector.</param>
  3769. /// <returns>Reflection vector.</returns>
  3770. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3771. public static double3 reflect(double3 i, double3 n) { return i - 2 * n * dot(i, n); }
  3772. /// <summary>Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n.</summary>
  3773. /// <param name="i">Incident vector.</param>
  3774. /// <param name="n">Normal vector.</param>
  3775. /// <returns>Reflection vector.</returns>
  3776. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3777. public static double4 reflect(double4 i, double4 n) { return i - 2 * n * dot(i, n); }
  3778. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3779. /// <param name="i">Incident vector.</param>
  3780. /// <param name="n">Normal vector.</param>
  3781. /// <param name="indexOfRefraction">Index of refraction.</param>
  3782. /// <returns>Refraction vector.</returns>
  3783. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3784. public static float2 refract(float2 i, float2 n, float indexOfRefraction)
  3785. {
  3786. float ni = dot(n, i);
  3787. float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
  3788. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3789. }
  3790. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3791. /// <param name="i">Incident vector.</param>
  3792. /// <param name="n">Normal vector.</param>
  3793. /// <param name="indexOfRefraction">Index of refraction.</param>
  3794. /// <returns>Refraction vector.</returns>
  3795. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3796. public static float3 refract(float3 i, float3 n, float indexOfRefraction)
  3797. {
  3798. float ni = dot(n, i);
  3799. float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
  3800. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3801. }
  3802. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3803. /// <param name="i">Incident vector.</param>
  3804. /// <param name="n">Normal vector.</param>
  3805. /// <param name="indexOfRefraction">Index of refraction.</param>
  3806. /// <returns>Refraction vector.</returns>
  3807. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3808. public static float4 refract(float4 i, float4 n, float indexOfRefraction)
  3809. {
  3810. float ni = dot(n, i);
  3811. float k = 1.0f - indexOfRefraction * indexOfRefraction * (1.0f - ni * ni);
  3812. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3813. }
  3814. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3815. /// <param name="i">Incident vector.</param>
  3816. /// <param name="n">Normal vector.</param>
  3817. /// <param name="indexOfRefraction">Index of refraction.</param>
  3818. /// <returns>Refraction vector.</returns>
  3819. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3820. public static double2 refract(double2 i, double2 n, double indexOfRefraction)
  3821. {
  3822. double ni = dot(n, i);
  3823. double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
  3824. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3825. }
  3826. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3827. /// <param name="i">Incident vector.</param>
  3828. /// <param name="n">Normal vector.</param>
  3829. /// <param name="indexOfRefraction">Index of refraction.</param>
  3830. /// <returns>Refraction vector.</returns>
  3831. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3832. public static double3 refract(double3 i, double3 n, double indexOfRefraction)
  3833. {
  3834. double ni = dot(n, i);
  3835. double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
  3836. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3837. }
  3838. /// <summary>Returns the refraction vector given the incident vector i, the normal vector n and the refraction index.</summary>
  3839. /// <param name="i">Incident vector.</param>
  3840. /// <param name="n">Normal vector.</param>
  3841. /// <param name="indexOfRefraction">Index of refraction.</param>
  3842. /// <returns>Refraction vector.</returns>
  3843. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3844. public static double4 refract(double4 i, double4 n, double indexOfRefraction)
  3845. {
  3846. double ni = dot(n, i);
  3847. double k = 1.0 - indexOfRefraction * indexOfRefraction * (1.0 - ni * ni);
  3848. return select(0.0f, indexOfRefraction * i - (indexOfRefraction * ni + sqrt(k)) * n, k >= 0);
  3849. }
  3850. /// <summary>
  3851. /// Compute vector projection of a onto b.
  3852. /// </summary>
  3853. /// <remarks>
  3854. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3855. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3856. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float2,Unity.Mathematics.float2,Unity.Mathematics.float2)"/>
  3857. /// which will use a given default value if the result is not finite.
  3858. /// </remarks>
  3859. /// <param name="a">Vector to project.</param>
  3860. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3861. /// <returns>Vector projection of a onto b.</returns>
  3862. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3863. public static float2 project(float2 a, float2 ontoB)
  3864. {
  3865. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  3866. }
  3867. /// <summary>
  3868. /// Compute vector projection of a onto b.
  3869. /// </summary>
  3870. /// <remarks>
  3871. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3872. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3873. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float3,Unity.Mathematics.float3,Unity.Mathematics.float3)"/>
  3874. /// which will use a given default value if the result is not finite.
  3875. /// </remarks>
  3876. /// <param name="a">Vector to project.</param>
  3877. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3878. /// <returns>Vector projection of a onto b.</returns>
  3879. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3880. public static float3 project(float3 a, float3 ontoB)
  3881. {
  3882. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  3883. }
  3884. /// <summary>
  3885. /// Compute vector projection of a onto b.
  3886. /// </summary>
  3887. /// <remarks>
  3888. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3889. /// are very large (close to Single.MaxValue) or when b's components are very small (close to FLT_MIN_NORMAL).
  3890. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.float4,Unity.Mathematics.float4,Unity.Mathematics.float4)"/>
  3891. /// which will use a given default value if the result is not finite.
  3892. /// </remarks>
  3893. /// <param name="a">Vector to project.</param>
  3894. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3895. /// <returns>Vector projection of a onto b.</returns>
  3896. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3897. public static float4 project(float4 a, float4 ontoB)
  3898. {
  3899. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  3900. }
  3901. /// <summary>
  3902. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3903. /// </summary>
  3904. /// <remarks>
  3905. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3906. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3907. /// <see cref="project(Unity.Mathematics.float2,Unity.Mathematics.float2)"/> instead which is faster than this
  3908. /// function.
  3909. /// </remarks>
  3910. /// <param name="a">Vector to project.</param>
  3911. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3912. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3913. /// <returns>Vector projection of a onto b or the default value.</returns>
  3914. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3915. public static float2 projectsafe(float2 a, float2 ontoB, float2 defaultValue = new float2())
  3916. {
  3917. var proj = project(a, ontoB);
  3918. return select(defaultValue, proj, all(isfinite(proj)));
  3919. }
  3920. /// <summary>
  3921. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3922. /// </summary>
  3923. /// <remarks>
  3924. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3925. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3926. /// <see cref="project(Unity.Mathematics.float3,Unity.Mathematics.float3)"/> instead which is faster than this
  3927. /// function.
  3928. /// </remarks>
  3929. /// <param name="a">Vector to project.</param>
  3930. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3931. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3932. /// <returns>Vector projection of a onto b or the default value.</returns>
  3933. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3934. public static float3 projectsafe(float3 a, float3 ontoB, float3 defaultValue = new float3())
  3935. {
  3936. var proj = project(a, ontoB);
  3937. return select(defaultValue, proj, all(isfinite(proj)));
  3938. }
  3939. /// <summary>
  3940. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  3941. /// </summary>
  3942. /// <remarks>
  3943. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  3944. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  3945. /// <see cref="project(Unity.Mathematics.float4,Unity.Mathematics.float4)"/> instead which is faster than this
  3946. /// function.
  3947. /// </remarks>
  3948. /// <param name="a">Vector to project.</param>
  3949. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3950. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  3951. /// <returns>Vector projection of a onto b or the default value.</returns>
  3952. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3953. public static float4 projectsafe(float4 a, float4 ontoB, float4 defaultValue = new float4())
  3954. {
  3955. var proj = project(a, ontoB);
  3956. return select(defaultValue, proj, all(isfinite(proj)));
  3957. }
  3958. /// <summary>
  3959. /// Compute vector projection of a onto b.
  3960. /// </summary>
  3961. /// <remarks>
  3962. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3963. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3964. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double2,Unity.Mathematics.double2,Unity.Mathematics.double2)"/>
  3965. /// which will use a given default value if the result is not finite.
  3966. /// </remarks>
  3967. /// <param name="a">Vector to project.</param>
  3968. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3969. /// <returns>Vector projection of a onto b.</returns>
  3970. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3971. public static double2 project(double2 a, double2 ontoB)
  3972. {
  3973. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  3974. }
  3975. /// <summary>
  3976. /// Compute vector projection of a onto b.
  3977. /// </summary>
  3978. /// <remarks>
  3979. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3980. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3981. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double3,Unity.Mathematics.double3,Unity.Mathematics.double3)"/>
  3982. /// which will use a given default value if the result is not finite.
  3983. /// </remarks>
  3984. /// <param name="a">Vector to project.</param>
  3985. /// <param name="ontoB">Non-zero vector to project onto.</param>
  3986. /// <returns>Vector projection of a onto b.</returns>
  3987. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  3988. public static double3 project(double3 a, double3 ontoB)
  3989. {
  3990. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  3991. }
  3992. /// <summary>
  3993. /// Compute vector projection of a onto b.
  3994. /// </summary>
  3995. /// <remarks>
  3996. /// Some finite vectors a and b could generate a non-finite result. This is most likely when a's components
  3997. /// are very large (close to Double.MaxValue) or when b's components are very small (close to DBL_MIN_NORMAL).
  3998. /// In these cases, you can call <see cref="projectsafe(Unity.Mathematics.double4,Unity.Mathematics.double4,Unity.Mathematics.double4)"/>
  3999. /// which will use a given default value if the result is not finite.
  4000. /// </remarks>
  4001. /// <param name="a">Vector to project.</param>
  4002. /// <param name="ontoB">Non-zero vector to project onto.</param>
  4003. /// <returns>Vector projection of a onto b.</returns>
  4004. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4005. public static double4 project(double4 a, double4 ontoB)
  4006. {
  4007. return (dot(a, ontoB) / dot(ontoB, ontoB)) * ontoB;
  4008. }
  4009. /// <summary>
  4010. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  4011. /// </summary>
  4012. /// <remarks>
  4013. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  4014. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  4015. /// <see cref="project(Unity.Mathematics.double2,Unity.Mathematics.double2)"/> instead which is faster than this
  4016. /// function.
  4017. /// </remarks>
  4018. /// <param name="a">Vector to project.</param>
  4019. /// <param name="ontoB">Non-zero vector to project onto.</param>
  4020. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  4021. /// <returns>Vector projection of a onto b or the default value.</returns>
  4022. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4023. public static double2 projectsafe(double2 a, double2 ontoB, double2 defaultValue = new double2())
  4024. {
  4025. var proj = project(a, ontoB);
  4026. return select(defaultValue, proj, all(isfinite(proj)));
  4027. }
  4028. /// <summary>
  4029. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  4030. /// </summary>
  4031. /// <remarks>
  4032. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  4033. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  4034. /// <see cref="project(Unity.Mathematics.double3,Unity.Mathematics.double3)"/> instead which is faster than this
  4035. /// function.
  4036. /// </remarks>
  4037. /// <param name="a">Vector to project.</param>
  4038. /// <param name="ontoB">Non-zero vector to project onto.</param>
  4039. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  4040. /// <returns>Vector projection of a onto b or the default value.</returns>
  4041. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4042. public static double3 projectsafe(double3 a, double3 ontoB, double3 defaultValue = new double3())
  4043. {
  4044. var proj = project(a, ontoB);
  4045. return select(defaultValue, proj, all(isfinite(proj)));
  4046. }
  4047. /// <summary>
  4048. /// Compute vector projection of a onto b. If result is not finite, then return the default value instead.
  4049. /// </summary>
  4050. /// <remarks>
  4051. /// This function performs extra checks to see if the result of projecting a onto b is finite. If you know that
  4052. /// your inputs will generate a finite result or you don't care if the result is finite, then you can call
  4053. /// <see cref="project(Unity.Mathematics.double4,Unity.Mathematics.double4)"/> instead which is faster than this
  4054. /// function.
  4055. /// </remarks>
  4056. /// <param name="a">Vector to project.</param>
  4057. /// <param name="ontoB">Non-zero vector to project onto.</param>
  4058. /// <param name="defaultValue">Default value to return if projection is not finite.</param>
  4059. /// <returns>Vector projection of a onto b or the default value.</returns>
  4060. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4061. public static double4 projectsafe(double4 a, double4 ontoB, double4 defaultValue = new double4())
  4062. {
  4063. var proj = project(a, ontoB);
  4064. return select(defaultValue, proj, all(isfinite(proj)));
  4065. }
  4066. /// <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>
  4067. /// <param name="n">Vector to conditionally flip.</param>
  4068. /// <param name="i">First vector in direction comparison.</param>
  4069. /// <param name="ng">Second vector in direction comparison.</param>
  4070. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4071. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4072. public static float2 faceforward(float2 n, float2 i, float2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4073. /// <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>
  4074. /// <param name="n">Vector to conditionally flip.</param>
  4075. /// <param name="i">First vector in direction comparison.</param>
  4076. /// <param name="ng">Second vector in direction comparison.</param>
  4077. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4078. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4079. public static float3 faceforward(float3 n, float3 i, float3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4080. /// <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>
  4081. /// <param name="n">Vector to conditionally flip.</param>
  4082. /// <param name="i">First vector in direction comparison.</param>
  4083. /// <param name="ng">Second vector in direction comparison.</param>
  4084. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4085. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4086. public static float4 faceforward(float4 n, float4 i, float4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4087. /// <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>
  4088. /// <param name="n">Vector to conditionally flip.</param>
  4089. /// <param name="i">First vector in direction comparison.</param>
  4090. /// <param name="ng">Second vector in direction comparison.</param>
  4091. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4092. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4093. public static double2 faceforward(double2 n, double2 i, double2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4094. /// <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>
  4095. /// <param name="n">Vector to conditionally flip.</param>
  4096. /// <param name="i">First vector in direction comparison.</param>
  4097. /// <param name="ng">Second vector in direction comparison.</param>
  4098. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4099. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4100. public static double3 faceforward(double3 n, double3 i, double3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4101. /// <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>
  4102. /// <param name="n">Vector to conditionally flip.</param>
  4103. /// <param name="i">First vector in direction comparison.</param>
  4104. /// <param name="ng">Second vector in direction comparison.</param>
  4105. /// <returns>-n if i and ng point in the same direction; otherwise return n unchanged.</returns>
  4106. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4107. public static double4 faceforward(double4 n, double4 i, double4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); }
  4108. /// <summary>Returns the sine and cosine of the input float value x through the out parameters s and c.</summary>
  4109. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4110. /// <param name="x">Input angle in radians.</param>
  4111. /// <param name="s">Output sine of the input.</param>
  4112. /// <param name="c">Output cosine of the input.</param>
  4113. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4114. public static void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); }
  4115. /// <summary>Returns the componentwise sine and cosine of the input float2 vector x through the out parameters s and c.</summary>
  4116. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4117. /// <param name="x">Input vector containing angles in radians.</param>
  4118. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4119. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4120. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4121. public static void sincos(float2 x, out float2 s, out float2 c) { s = sin(x); c = cos(x); }
  4122. /// <summary>Returns the componentwise sine and cosine of the input float3 vector x through the out parameters s and c.</summary>
  4123. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4124. /// <param name="x">Input vector containing angles in radians.</param>
  4125. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4126. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4127. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4128. public static void sincos(float3 x, out float3 s, out float3 c) { s = sin(x); c = cos(x); }
  4129. /// <summary>Returns the componentwise sine and cosine of the input float4 vector x through the out parameters s and c.</summary>
  4130. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4131. /// <param name="x">Input vector containing angles in radians.</param>
  4132. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4133. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4134. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4135. public static void sincos(float4 x, out float4 s, out float4 c) { s = sin(x); c = cos(x); }
  4136. /// <summary>Returns the sine and cosine of the input double value x through the out parameters s and c.</summary>
  4137. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4138. /// <param name="x">Input angle in radians.</param>
  4139. /// <param name="s">Output sine of the input.</param>
  4140. /// <param name="c">Output cosine of the input.</param>
  4141. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4142. public static void sincos(double x, out double s, out double c) { s = sin(x); c = cos(x); }
  4143. /// <summary>Returns the componentwise sine and cosine of the input double2 vector x through the out parameters s and c.</summary>
  4144. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4145. /// <param name="x">Input vector containing angles in radians.</param>
  4146. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4147. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4148. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4149. public static void sincos(double2 x, out double2 s, out double2 c) { s = sin(x); c = cos(x); }
  4150. /// <summary>Returns the componentwise sine and cosine of the input double3 vector x through the out parameters s and c.</summary>
  4151. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4152. /// <param name="x">Input vector containing angles in radians.</param>
  4153. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4154. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4155. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4156. public static void sincos(double3 x, out double3 s, out double3 c) { s = sin(x); c = cos(x); }
  4157. /// <summary>Returns the componentwise sine and cosine of the input double4 vector x through the out parameters s and c.</summary>
  4158. /// <remarks>When Burst compiled, his method is faster than calling sin() and cos() separately.</remarks>
  4159. /// <param name="x">Input vector containing angles in radians.</param>
  4160. /// <param name="s">Output vector containing the componentwise sine of the input.</param>
  4161. /// <param name="c">Output vector containing the componentwise cosine of the input.</param>
  4162. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4163. public static void sincos(double4 x, out double4 s, out double4 c) { s = sin(x); c = cos(x); }
  4164. /// <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>
  4165. /// <param name="x">int value in which to count bits set to 1.</param>
  4166. /// <returns>Number of bits set to 1 within x.</returns>
  4167. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4168. public static int countbits(int x) { return countbits((uint)x); }
  4169. /// <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>
  4170. /// <param name="x">int2 value in which to count bits for each component.</param>
  4171. /// <returns>int2 containing number of bits set to 1 within each component of x.</returns>
  4172. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4173. public static int2 countbits(int2 x) { return countbits((uint2)x); }
  4174. /// <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>
  4175. /// <param name="x">Number in which to count bits.</param>
  4176. /// <returns>int3 containing number of bits set to 1 within each component of x.</returns>
  4177. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4178. public static int3 countbits(int3 x) { return countbits((uint3)x); }
  4179. /// <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>
  4180. /// <param name="x">Number in which to count bits.</param>
  4181. /// <returns>int4 containing number of bits set to 1 within each component of x.</returns>
  4182. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4183. public static int4 countbits(int4 x) { return countbits((uint4)x); }
  4184. /// <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>
  4185. /// <param name="x">Number in which to count bits.</param>
  4186. /// <returns>Number of bits set to 1 within x.</returns>
  4187. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4188. public static int countbits(uint x)
  4189. {
  4190. x = x - ((x >> 1) & 0x55555555);
  4191. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4192. return (int)((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4193. }
  4194. /// <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>
  4195. /// <param name="x">Number in which to count bits.</param>
  4196. /// <returns>int2 containing number of bits set to 1 within each component of x.</returns>
  4197. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4198. public static int2 countbits(uint2 x)
  4199. {
  4200. x = x - ((x >> 1) & 0x55555555);
  4201. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4202. return int2((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4203. }
  4204. /// <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>
  4205. /// <param name="x">Number in which to count bits.</param>
  4206. /// <returns>int3 containing number of bits set to 1 within each component of x.</returns>
  4207. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4208. public static int3 countbits(uint3 x)
  4209. {
  4210. x = x - ((x >> 1) & 0x55555555);
  4211. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4212. return int3((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4213. }
  4214. /// <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>
  4215. /// <param name="x">Number in which to count bits.</param>
  4216. /// <returns>int4 containing number of bits set to 1 within each component of x.</returns>
  4217. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4218. public static int4 countbits(uint4 x)
  4219. {
  4220. x = x - ((x >> 1) & 0x55555555);
  4221. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  4222. return int4((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
  4223. }
  4224. /// <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>
  4225. /// <param name="x">Number in which to count bits.</param>
  4226. /// <returns>Number of bits set to 1 within x.</returns>
  4227. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4228. public static int countbits(ulong x)
  4229. {
  4230. x = x - ((x >> 1) & 0x5555555555555555);
  4231. x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
  4232. return (int)((((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56);
  4233. }
  4234. /// <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>
  4235. /// <param name="x">Number in which to count bits.</param>
  4236. /// <returns>Number of bits set to 1 within x.</returns>
  4237. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4238. public static int countbits(long x) { return countbits((ulong)x); }
  4239. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int vector.</summary>
  4240. /// <param name="x">Input value.</param>
  4241. /// <returns>The number of leading zeros of the input.</returns>
  4242. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4243. public static int lzcnt(int x) { return lzcnt((uint)x); }
  4244. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int2 vector.</summary>
  4245. /// <param name="x">Input value.</param>
  4246. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4247. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4248. public static int2 lzcnt(int2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  4249. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int3 vector.</summary>
  4250. /// <param name="x">Input value.</param>
  4251. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4252. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4253. public static int3 lzcnt(int3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  4254. /// <summary>Returns the componentwise number of leading zeros in the binary representations of an int4 vector.</summary>
  4255. /// <param name="x">Input value.</param>
  4256. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4257. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4258. public static int4 lzcnt(int4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  4259. /// <summary>Returns number of leading zeros in the binary representations of a uint value.</summary>
  4260. /// <param name="x">Input value.</param>
  4261. /// <returns>The number of leading zeros of the input.</returns>
  4262. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4263. public static int lzcnt(uint x)
  4264. {
  4265. if (x == 0)
  4266. return 32;
  4267. LongDoubleUnion u;
  4268. u.doubleValue = 0.0;
  4269. u.longValue = 0x4330000000000000L + x;
  4270. u.doubleValue -= 4503599627370496.0;
  4271. return 0x41E - (int)(u.longValue >> 52);
  4272. }
  4273. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint2 vector.</summary>
  4274. /// <param name="x">Input value.</param>
  4275. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4276. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4277. public static int2 lzcnt(uint2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); }
  4278. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint3 vector.</summary>
  4279. /// <param name="x">Input value.</param>
  4280. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4281. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4282. public static int3 lzcnt(uint3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); }
  4283. /// <summary>Returns the componentwise number of leading zeros in the binary representations of a uint4 vector.</summary>
  4284. /// <param name="x">Input value.</param>
  4285. /// <returns>The componentwise number of leading zeros of the input.</returns>
  4286. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4287. public static int4 lzcnt(uint4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); }
  4288. /// <summary>Returns number of leading zeros in the binary representations of a long value.</summary>
  4289. /// <param name="x">Input value.</param>
  4290. /// <returns>The number of leading zeros of the input.</returns>
  4291. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4292. public static int lzcnt(long x) { return lzcnt((ulong)x); }
  4293. /// <summary>Returns number of leading zeros in the binary representations of a ulong value.</summary>
  4294. /// <param name="x">Input value.</param>
  4295. /// <returns>The number of leading zeros of the input.</returns>
  4296. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4297. public static int lzcnt(ulong x)
  4298. {
  4299. if (x == 0)
  4300. return 64;
  4301. uint xh = (uint)(x >> 32);
  4302. uint bits = xh != 0 ? xh : (uint)x;
  4303. int offset = xh != 0 ? 0x41E : 0x43E;
  4304. LongDoubleUnion u;
  4305. u.doubleValue = 0.0;
  4306. u.longValue = 0x4330000000000000L + bits;
  4307. u.doubleValue -= 4503599627370496.0;
  4308. return offset - (int)(u.longValue >> 52);
  4309. }
  4310. /// <summary>
  4311. /// Computes the trailing zero count in the binary representation of the input value.
  4312. /// </summary>
  4313. /// <remarks>
  4314. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4315. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4316. /// trailing zero count is zero.
  4317. /// </remarks>
  4318. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4319. /// <returns>Returns the trailing zero count of the input.</returns>
  4320. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4321. public static int tzcnt(int x) { return tzcnt((uint)x); }
  4322. /// <summary>
  4323. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4324. /// </summary>
  4325. /// <remarks>
  4326. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4327. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4328. /// trailing zero count is zero.
  4329. /// </remarks>
  4330. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4331. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4332. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4333. public static int2 tzcnt(int2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  4334. /// <summary>
  4335. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4336. /// </summary>
  4337. /// <remarks>
  4338. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4339. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4340. /// trailing zero count is zero.
  4341. /// </remarks>
  4342. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4343. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4344. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4345. public static int3 tzcnt(int3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); }
  4346. /// <summary>
  4347. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4348. /// </summary>
  4349. /// <remarks>
  4350. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4351. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4352. /// trailing zero count is zero.
  4353. /// </remarks>
  4354. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4355. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4356. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4357. public static int4 tzcnt(int4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); }
  4358. /// <summary>
  4359. /// Computes the trailing zero count in the binary representation of the input value.
  4360. /// </summary>
  4361. /// <remarks>
  4362. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4363. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4364. /// trailing zero count is zero.
  4365. /// </remarks>
  4366. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4367. /// <returns>Returns the trailing zero count of the input.</returns>
  4368. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4369. public static int tzcnt(uint x)
  4370. {
  4371. if (x == 0)
  4372. return 32;
  4373. x &= (uint)-x;
  4374. LongDoubleUnion u;
  4375. u.doubleValue = 0.0;
  4376. u.longValue = 0x4330000000000000L + x;
  4377. u.doubleValue -= 4503599627370496.0;
  4378. return (int)(u.longValue >> 52) - 0x3FF;
  4379. }
  4380. /// <summary>
  4381. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4382. /// </summary>
  4383. /// <remarks>
  4384. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4385. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4386. /// trailing zero count is zero.
  4387. /// </remarks>
  4388. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4389. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4390. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4391. public static int2 tzcnt(uint2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); }
  4392. /// <summary>
  4393. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4394. /// </summary>
  4395. /// <remarks>
  4396. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4397. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4398. /// trailing zero count is zero.
  4399. /// </remarks>
  4400. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4401. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4402. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4403. public static int3 tzcnt(uint3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); }
  4404. /// <summary>
  4405. /// Computes the component-wise trailing zero count in the binary representation of the input value.
  4406. /// </summary>
  4407. /// <remarks>
  4408. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4409. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4410. /// trailing zero count is zero.
  4411. /// </remarks>
  4412. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4413. /// <returns>Returns the component-wise trailing zero count of the input.</returns>
  4414. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4415. public static int4 tzcnt(uint4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); }
  4416. /// <summary>
  4417. /// Computes the trailing zero count in the binary representation of the input value.
  4418. /// </summary>
  4419. /// <remarks>
  4420. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4421. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4422. /// trailing zero count is zero.
  4423. /// </remarks>
  4424. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4425. /// <returns>Returns the trailing zero count of the input.</returns>
  4426. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4427. public static int tzcnt(long x) { return tzcnt((ulong)x); }
  4428. /// <summary>
  4429. /// Computes the trailing zero count in the binary representation of the input value.
  4430. /// </summary>
  4431. /// <remarks>
  4432. /// Assuming that the least significant bit is on the right, the integer value 4 has a binary representation
  4433. /// 0100 and the trailing zero count is two. The integer value 1 has a binary representation 0001 and the
  4434. /// trailing zero count is zero.
  4435. /// </remarks>
  4436. /// <param name="x">Input to use when computing the trailing zero count.</param>
  4437. /// <returns>Returns the trailing zero count of the input.</returns>
  4438. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4439. public static int tzcnt(ulong x)
  4440. {
  4441. if (x == 0)
  4442. return 64;
  4443. x = x & (ulong)-(long)x;
  4444. uint xl = (uint)x;
  4445. uint bits = xl != 0 ? xl : (uint)(x >> 32);
  4446. int offset = xl != 0 ? 0x3FF : 0x3DF;
  4447. LongDoubleUnion u;
  4448. u.doubleValue = 0.0;
  4449. u.longValue = 0x4330000000000000L + bits;
  4450. u.doubleValue -= 4503599627370496.0;
  4451. return (int)(u.longValue >> 52) - offset;
  4452. }
  4453. /// <summary>Returns the result of performing a reversal of the bit pattern of an int value.</summary>
  4454. /// <param name="x">Value to reverse.</param>
  4455. /// <returns>Value with reversed bits.</returns>
  4456. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4457. public static int reversebits(int x) { return (int)reversebits((uint)x); }
  4458. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int2 vector.</summary>
  4459. /// <param name="x">Value to reverse.</param>
  4460. /// <returns>Value with componentwise reversed bits.</returns>
  4461. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4462. public static int2 reversebits(int2 x) { return (int2)reversebits((uint2)x); }
  4463. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int3 vector.</summary>
  4464. /// <param name="x">Value to reverse.</param>
  4465. /// <returns>Value with componentwise reversed bits.</returns>
  4466. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4467. public static int3 reversebits(int3 x) { return (int3)reversebits((uint3)x); }
  4468. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an int4 vector.</summary>
  4469. /// <param name="x">Value to reverse.</param>
  4470. /// <returns>Value with componentwise reversed bits.</returns>
  4471. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4472. public static int4 reversebits(int4 x) { return (int4)reversebits((uint4)x); }
  4473. /// <summary>Returns the result of performing a reversal of the bit pattern of a uint value.</summary>
  4474. /// <param name="x">Value to reverse.</param>
  4475. /// <returns>Value with reversed bits.</returns>
  4476. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4477. public static uint reversebits(uint x) {
  4478. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4479. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4480. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4481. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4482. return (x >> 16) | (x << 16);
  4483. }
  4484. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint2 vector.</summary>
  4485. /// <param name="x">Value to reverse.</param>
  4486. /// <returns>Value with componentwise reversed bits.</returns>
  4487. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4488. public static uint2 reversebits(uint2 x)
  4489. {
  4490. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4491. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4492. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4493. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4494. return (x >> 16) | (x << 16);
  4495. }
  4496. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint3 vector.</summary>
  4497. /// <param name="x">Value to reverse.</param>
  4498. /// <returns>Value with componentwise reversed bits.</returns>
  4499. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4500. public static uint3 reversebits(uint3 x)
  4501. {
  4502. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4503. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4504. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4505. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4506. return (x >> 16) | (x << 16);
  4507. }
  4508. /// <summary>Returns the result of performing a componentwise reversal of the bit pattern of an uint4 vector.</summary>
  4509. /// <param name="x">Value to reverse.</param>
  4510. /// <returns>Value with componentwise reversed bits.</returns>
  4511. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4512. public static uint4 reversebits(uint4 x)
  4513. {
  4514. x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
  4515. x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
  4516. x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4);
  4517. x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8);
  4518. return (x >> 16) | (x << 16);
  4519. }
  4520. /// <summary>Returns the result of performing a reversal of the bit pattern of a long value.</summary>
  4521. /// <param name="x">Value to reverse.</param>
  4522. /// <returns>Value with reversed bits.</returns>
  4523. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4524. public static long reversebits(long x) { return (long)reversebits((ulong)x); }
  4525. /// <summary>Returns the result of performing a reversal of the bit pattern of a ulong value.</summary>
  4526. /// <param name="x">Value to reverse.</param>
  4527. /// <returns>Value with reversed bits.</returns>
  4528. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4529. public static ulong reversebits(ulong x)
  4530. {
  4531. x = ((x >> 1) & 0x5555555555555555ul) | ((x & 0x5555555555555555ul) << 1);
  4532. x = ((x >> 2) & 0x3333333333333333ul) | ((x & 0x3333333333333333ul) << 2);
  4533. x = ((x >> 4) & 0x0F0F0F0F0F0F0F0Ful) | ((x & 0x0F0F0F0F0F0F0F0Ful) << 4);
  4534. x = ((x >> 8) & 0x00FF00FF00FF00FFul) | ((x & 0x00FF00FF00FF00FFul) << 8);
  4535. x = ((x >> 16) & 0x0000FFFF0000FFFFul) | ((x & 0x0000FFFF0000FFFFul) << 16);
  4536. return (x >> 32) | (x << 32);
  4537. }
  4538. /// <summary>Returns the result of rotating the bits of an int left by bits n.</summary>
  4539. /// <param name="x">Value to rotate.</param>
  4540. /// <param name="n">Number of bits to rotate.</param>
  4541. /// <returns>The rotated value.</returns>
  4542. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4543. public static int rol(int x, int n) { return (int)rol((uint)x, n); }
  4544. /// <summary>Returns the componentwise result of rotating the bits of an int2 left by bits n.</summary>
  4545. /// <param name="x">Value to rotate.</param>
  4546. /// <param name="n">Number of bits to rotate.</param>
  4547. /// <returns>The componentwise rotated value.</returns>
  4548. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4549. public static int2 rol(int2 x, int n) { return (int2)rol((uint2)x, n); }
  4550. /// <summary>Returns the componentwise result of rotating the bits of an int3 left by bits n.</summary>
  4551. /// <param name="x">Value to rotate.</param>
  4552. /// <param name="n">Number of bits to rotate.</param>
  4553. /// <returns>The componentwise rotated value.</returns>
  4554. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4555. public static int3 rol(int3 x, int n) { return (int3)rol((uint3)x, n); }
  4556. /// <summary>Returns the componentwise result of rotating the bits of an int4 left by bits n.</summary>
  4557. /// <param name="x">Value to rotate.</param>
  4558. /// <param name="n">Number of bits to rotate.</param>
  4559. /// <returns>The componentwise rotated value.</returns>
  4560. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4561. public static int4 rol(int4 x, int n) { return (int4)rol((uint4)x, n); }
  4562. /// <summary>Returns the result of rotating the bits of a uint left by bits n.</summary>
  4563. /// <param name="x">Value to rotate.</param>
  4564. /// <param name="n">Number of bits to rotate.</param>
  4565. /// <returns>The rotated value.</returns>
  4566. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4567. public static uint rol(uint x, int n) { return (x << n) | (x >> (32 - n)); }
  4568. /// <summary>Returns the componentwise result of rotating the bits of a uint2 left by bits n.</summary>
  4569. /// <param name="x">Value to rotate.</param>
  4570. /// <param name="n">Number of bits to rotate.</param>
  4571. /// <returns>The componentwise rotated value.</returns>
  4572. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4573. public static uint2 rol(uint2 x, int n) { return (x << n) | (x >> (32 - n)); }
  4574. /// <summary>Returns the componentwise result of rotating the bits of a uint3 left by bits n.</summary>
  4575. /// <param name="x">Value to rotate.</param>
  4576. /// <param name="n">Number of bits to rotate.</param>
  4577. /// <returns>The componentwise rotated value.</returns>
  4578. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4579. public static uint3 rol(uint3 x, int n) { return (x << n) | (x >> (32 - n)); }
  4580. /// <summary>Returns the componentwise result of rotating the bits of a uint4 left by bits n.</summary>
  4581. /// <param name="x">Value to rotate.</param>
  4582. /// <param name="n">Number of bits to rotate.</param>
  4583. /// <returns>The componentwise rotated value.</returns>
  4584. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4585. public static uint4 rol(uint4 x, int n) { return (x << n) | (x >> (32 - n)); }
  4586. /// <summary>Returns the result of rotating the bits of a long left by bits n.</summary>
  4587. /// <param name="x">Value to rotate.</param>
  4588. /// <param name="n">Number of bits to rotate.</param>
  4589. /// <returns>The rotated value.</returns>
  4590. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4591. public static long rol(long x, int n) { return (long)rol((ulong)x, n); }
  4592. /// <summary>Returns the result of rotating the bits of a ulong left by bits n.</summary>
  4593. /// <param name="x">Value to rotate.</param>
  4594. /// <param name="n">Number of bits to rotate.</param>
  4595. /// <returns>The rotated value.</returns>
  4596. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4597. public static ulong rol(ulong x, int n) { return (x << n) | (x >> (64 - n)); }
  4598. /// <summary>Returns the result of rotating the bits of an int right by bits n.</summary>
  4599. /// <param name="x">Value to rotate.</param>
  4600. /// <param name="n">Number of bits to rotate.</param>
  4601. /// <returns>The rotated value.</returns>
  4602. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4603. public static int ror(int x, int n) { return (int)ror((uint)x, n); }
  4604. /// <summary>Returns the componentwise result of rotating the bits of an int2 right by bits n.</summary>
  4605. /// <param name="x">Value to rotate.</param>
  4606. /// <param name="n">Number of bits to rotate.</param>
  4607. /// <returns>The componentwise rotated value.</returns>
  4608. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4609. public static int2 ror(int2 x, int n) { return (int2)ror((uint2)x, n); }
  4610. /// <summary>Returns the componentwise result of rotating the bits of an int3 right by bits n.</summary>
  4611. /// <param name="x">Value to rotate.</param>
  4612. /// <param name="n">Number of bits to rotate.</param>
  4613. /// <returns>The componentwise rotated value.</returns>
  4614. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4615. public static int3 ror(int3 x, int n) { return (int3)ror((uint3)x, n); }
  4616. /// <summary>Returns the componentwise result of rotating the bits of an int4 right by bits n.</summary>
  4617. /// <param name="x">Value to rotate.</param>
  4618. /// <param name="n">Number of bits to rotate.</param>
  4619. /// <returns>The componentwise rotated value.</returns>
  4620. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4621. public static int4 ror(int4 x, int n) { return (int4)ror((uint4)x, n); }
  4622. /// <summary>Returns the result of rotating the bits of a uint right by bits n.</summary>
  4623. /// <param name="x">Value to rotate.</param>
  4624. /// <param name="n">Number of bits to rotate.</param>
  4625. /// <returns>The rotated value.</returns>
  4626. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4627. public static uint ror(uint x, int n) { return (x >> n) | (x << (32 - n)); }
  4628. /// <summary>Returns the componentwise result of rotating the bits of a uint2 right by bits n.</summary>
  4629. /// <param name="x">Value to rotate.</param>
  4630. /// <param name="n">Number of bits to rotate.</param>
  4631. /// <returns>The componentwise rotated value.</returns>
  4632. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4633. public static uint2 ror(uint2 x, int n) { return (x >> n) | (x << (32 - n)); }
  4634. /// <summary>Returns the componentwise result of rotating the bits of a uint3 right by bits n.</summary>
  4635. /// <param name="x">Value to rotate.</param>
  4636. /// <param name="n">Number of bits to rotate.</param>
  4637. /// <returns>The componentwise rotated value.</returns>
  4638. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4639. public static uint3 ror(uint3 x, int n) { return (x >> n) | (x << (32 - n)); }
  4640. /// <summary>Returns the componentwise result of rotating the bits of a uint4 right by bits n.</summary>
  4641. /// <param name="x">Value to rotate.</param>
  4642. /// <param name="n">Number of bits to rotate.</param>
  4643. /// <returns>The componentwise rotated value.</returns>
  4644. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4645. public static uint4 ror(uint4 x, int n) { return (x >> n) | (x << (32 - n)); }
  4646. /// <summary>Returns the result of rotating the bits of a long right by bits n.</summary>
  4647. /// <param name="x">Value to rotate.</param>
  4648. /// <param name="n">Number of bits to rotate.</param>
  4649. /// <returns>The rotated value.</returns>
  4650. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4651. public static long ror(long x, int n) { return (long)ror((ulong)x, n); }
  4652. /// <summary>Returns the result of rotating the bits of a ulong right by bits n.</summary>
  4653. /// <param name="x">Value to rotate.</param>
  4654. /// <param name="n">Number of bits to rotate.</param>
  4655. /// <returns>The rotated value.</returns>
  4656. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4657. public static ulong ror(ulong x, int n) { return (x >> n) | (x << (64 - n)); }
  4658. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4659. /// <remarks>Also known as nextpow2.</remarks>
  4660. /// <param name="x">Input value.</param>
  4661. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4662. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4663. public static int ceilpow2(int x)
  4664. {
  4665. x -= 1;
  4666. x |= x >> 1;
  4667. x |= x >> 2;
  4668. x |= x >> 4;
  4669. x |= x >> 8;
  4670. x |= x >> 16;
  4671. return x + 1;
  4672. }
  4673. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4674. /// <remarks>Also known as nextpow2.</remarks>
  4675. /// <param name="x">Input value.</param>
  4676. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4677. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4678. public static int2 ceilpow2(int2 x)
  4679. {
  4680. x -= 1;
  4681. x |= x >> 1;
  4682. x |= x >> 2;
  4683. x |= x >> 4;
  4684. x |= x >> 8;
  4685. x |= x >> 16;
  4686. return x + 1;
  4687. }
  4688. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4689. /// <remarks>Also known as nextpow2.</remarks>
  4690. /// <param name="x">Input value.</param>
  4691. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4692. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4693. public static int3 ceilpow2(int3 x)
  4694. {
  4695. x -= 1;
  4696. x |= x >> 1;
  4697. x |= x >> 2;
  4698. x |= x >> 4;
  4699. x |= x >> 8;
  4700. x |= x >> 16;
  4701. return x + 1;
  4702. }
  4703. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4704. /// <remarks>Also known as nextpow2.</remarks>
  4705. /// <param name="x">Input value.</param>
  4706. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4707. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4708. public static int4 ceilpow2(int4 x)
  4709. {
  4710. x -= 1;
  4711. x |= x >> 1;
  4712. x |= x >> 2;
  4713. x |= x >> 4;
  4714. x |= x >> 8;
  4715. x |= x >> 16;
  4716. return x + 1;
  4717. }
  4718. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4719. /// <remarks>Also known as nextpow2.</remarks>
  4720. /// <param name="x">Input value.</param>
  4721. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4722. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4723. public static uint ceilpow2(uint x)
  4724. {
  4725. x -= 1;
  4726. x |= x >> 1;
  4727. x |= x >> 2;
  4728. x |= x >> 4;
  4729. x |= x >> 8;
  4730. x |= x >> 16;
  4731. return x + 1;
  4732. }
  4733. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4734. /// <remarks>Also known as nextpow2.</remarks>
  4735. /// <param name="x">Input value.</param>
  4736. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4737. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4738. public static uint2 ceilpow2(uint2 x)
  4739. {
  4740. x -= 1;
  4741. x |= x >> 1;
  4742. x |= x >> 2;
  4743. x |= x >> 4;
  4744. x |= x >> 8;
  4745. x |= x >> 16;
  4746. return x + 1;
  4747. }
  4748. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4749. /// <remarks>Also known as nextpow2.</remarks>
  4750. /// <param name="x">Input value.</param>
  4751. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4752. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4753. public static uint3 ceilpow2(uint3 x)
  4754. {
  4755. x -= 1;
  4756. x |= x >> 1;
  4757. x |= x >> 2;
  4758. x |= x >> 4;
  4759. x |= x >> 8;
  4760. x |= x >> 16;
  4761. return x + 1;
  4762. }
  4763. /// <summary>Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input.</summary>
  4764. /// <remarks>Also known as nextpow2.</remarks>
  4765. /// <param name="x">Input value.</param>
  4766. /// <returns>The componentwise smallest power of two greater than or equal to the input.</returns>
  4767. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4768. public static uint4 ceilpow2(uint4 x)
  4769. {
  4770. x -= 1;
  4771. x |= x >> 1;
  4772. x |= x >> 2;
  4773. x |= x >> 4;
  4774. x |= x >> 8;
  4775. x |= x >> 16;
  4776. return x + 1;
  4777. }
  4778. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4779. /// <remarks>Also known as nextpow2.</remarks>
  4780. /// <param name="x">Input value.</param>
  4781. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4782. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4783. public static long ceilpow2(long x)
  4784. {
  4785. x -= 1;
  4786. x |= x >> 1;
  4787. x |= x >> 2;
  4788. x |= x >> 4;
  4789. x |= x >> 8;
  4790. x |= x >> 16;
  4791. x |= x >> 32;
  4792. return x + 1;
  4793. }
  4794. /// <summary>Returns the smallest power of two greater than or equal to the input.</summary>
  4795. /// <remarks>Also known as nextpow2.</remarks>
  4796. /// <param name="x">Input value.</param>
  4797. /// <returns>The smallest power of two greater than or equal to the input.</returns>
  4798. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4799. public static ulong ceilpow2(ulong x)
  4800. {
  4801. x -= 1;
  4802. x |= x >> 1;
  4803. x |= x >> 2;
  4804. x |= x >> 4;
  4805. x |= x >> 8;
  4806. x |= x >> 16;
  4807. x |= x >> 32;
  4808. return x + 1;
  4809. }
  4810. /// <summary>
  4811. /// Computes the ceiling of the base-2 logarithm of x.
  4812. /// </summary>
  4813. /// <remarks>
  4814. /// x must be greater than 0, otherwise the result is undefined.
  4815. /// </remarks>
  4816. /// <param name="x">Integer to be used as input.</param>
  4817. /// <returns>Ceiling of the base-2 logarithm of x, as an integer.</returns>
  4818. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4819. public static int ceillog2(int x)
  4820. {
  4821. return 32 - lzcnt((uint)x - 1);
  4822. }
  4823. /// <summary>
  4824. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4825. /// </summary>
  4826. /// <remarks>
  4827. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4828. /// </remarks>
  4829. /// <param name="x">int2 to be used as input.</param>
  4830. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4831. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4832. public static int2 ceillog2(int2 x)
  4833. {
  4834. return new int2(ceillog2(x.x), ceillog2(x.y));
  4835. }
  4836. /// <summary>
  4837. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4838. /// </summary>
  4839. /// <remarks>
  4840. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4841. /// </remarks>
  4842. /// <param name="x">int3 to be used as input.</param>
  4843. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4844. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4845. public static int3 ceillog2(int3 x)
  4846. {
  4847. return new int3(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z));
  4848. }
  4849. /// <summary>
  4850. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4851. /// </summary>
  4852. /// <remarks>
  4853. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4854. /// </remarks>
  4855. /// <param name="x">int4 to be used as input.</param>
  4856. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4857. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4858. public static int4 ceillog2(int4 x)
  4859. {
  4860. return new int4(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z), ceillog2(x.w));
  4861. }
  4862. /// <summary>
  4863. /// Computes the ceiling of the base-2 logarithm of x.
  4864. /// </summary>
  4865. /// <remarks>
  4866. /// x must be greater than 0, otherwise the result is undefined.
  4867. /// </remarks>
  4868. /// <param name="x">Unsigned integer to be used as input.</param>
  4869. /// <returns>Ceiling of the base-2 logarithm of x, as an integer.</returns>
  4870. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4871. public static int ceillog2(uint x)
  4872. {
  4873. return 32 - lzcnt(x - 1);
  4874. }
  4875. /// <summary>
  4876. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4877. /// </summary>
  4878. /// <remarks>
  4879. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4880. /// </remarks>
  4881. /// <param name="x">uint2 to be used as input.</param>
  4882. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4883. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4884. public static int2 ceillog2(uint2 x)
  4885. {
  4886. return new int2(ceillog2(x.x), ceillog2(x.y));
  4887. }
  4888. /// <summary>
  4889. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4890. /// </summary>
  4891. /// <remarks>
  4892. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4893. /// </remarks>
  4894. /// <param name="x">uint3 to be used as input.</param>
  4895. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4896. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4897. public static int3 ceillog2(uint3 x)
  4898. {
  4899. return new int3(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z));
  4900. }
  4901. /// <summary>
  4902. /// Computes the componentwise ceiling of the base-2 logarithm of x.
  4903. /// </summary>
  4904. /// <remarks>
  4905. /// Components of x must be greater than 0, otherwise the result for that component is undefined.
  4906. /// </remarks>
  4907. /// <param name="x">uint4 to be used as input.</param>
  4908. /// <returns>Componentwise ceiling of the base-2 logarithm of x.</returns>
  4909. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4910. public static int4 ceillog2(uint4 x)
  4911. {
  4912. return new int4(ceillog2(x.x), ceillog2(x.y), ceillog2(x.z), ceillog2(x.w));
  4913. }
  4914. /// <summary>
  4915. /// Computes the floor of the base-2 logarithm of x.
  4916. /// </summary>
  4917. /// <remarks>x must be greater than zero, otherwise the result is undefined.</remarks>
  4918. /// <param name="x">Integer to be used as input.</param>
  4919. /// <returns>Floor of base-2 logarithm of x.</returns>
  4920. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4921. public static int floorlog2(int x)
  4922. {
  4923. return 31 - lzcnt((uint)x);
  4924. }
  4925. /// <summary>
  4926. /// Computes the componentwise floor of the base-2 logarithm of x.
  4927. /// </summary>
  4928. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4929. /// <param name="x">int2 to be used as input.</param>
  4930. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4931. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4932. public static int2 floorlog2(int2 x)
  4933. {
  4934. return new int2(floorlog2(x.x), floorlog2(x.y));
  4935. }
  4936. /// <summary>
  4937. /// Computes the componentwise floor of the base-2 logarithm of x.
  4938. /// </summary>
  4939. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4940. /// <param name="x">int3 to be used as input.</param>
  4941. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4942. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4943. public static int3 floorlog2(int3 x)
  4944. {
  4945. return new int3(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z));
  4946. }
  4947. /// <summary>
  4948. /// Computes the componentwise floor of the base-2 logarithm of x.
  4949. /// </summary>
  4950. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4951. /// <param name="x">int4 to be used as input.</param>
  4952. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4953. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4954. public static int4 floorlog2(int4 x)
  4955. {
  4956. return new int4(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z), floorlog2(x.w));
  4957. }
  4958. /// <summary>
  4959. /// Computes the floor of the base-2 logarithm of x.
  4960. /// </summary>
  4961. /// <remarks>x must be greater than zero, otherwise the result is undefined.</remarks>
  4962. /// <param name="x">Unsigned integer to be used as input.</param>
  4963. /// <returns>Floor of base-2 logarithm of x.</returns>
  4964. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4965. public static int floorlog2(uint x)
  4966. {
  4967. return 31 - lzcnt(x);
  4968. }
  4969. /// <summary>
  4970. /// Computes the componentwise floor of the base-2 logarithm of x.
  4971. /// </summary>
  4972. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4973. /// <param name="x">uint2 to be used as input.</param>
  4974. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4975. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4976. public static int2 floorlog2(uint2 x)
  4977. {
  4978. return new int2(floorlog2(x.x), floorlog2(x.y));
  4979. }
  4980. /// <summary>
  4981. /// Computes the componentwise floor of the base-2 logarithm of x.
  4982. /// </summary>
  4983. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4984. /// <param name="x">uint3 to be used as input.</param>
  4985. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4986. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4987. public static int3 floorlog2(uint3 x)
  4988. {
  4989. return new int3(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z));
  4990. }
  4991. /// <summary>
  4992. /// Computes the componentwise floor of the base-2 logarithm of x.
  4993. /// </summary>
  4994. /// <remarks>Components of x must be greater than zero, otherwise the result of the component is undefined.</remarks>
  4995. /// <param name="x">uint4 to be used as input.</param>
  4996. /// <returns>Componentwise floor of base-2 logarithm of x.</returns>
  4997. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  4998. public static int4 floorlog2(uint4 x)
  4999. {
  5000. return new int4(floorlog2(x.x), floorlog2(x.y), floorlog2(x.z), floorlog2(x.w));
  5001. }
  5002. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  5003. /// <param name="x">Angle in degrees.</param>
  5004. /// <returns>Angle converted to radians.</returns>
  5005. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5006. public static float radians(float x) { return x * TORADIANS; }
  5007. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  5008. /// <param name="x">Vector containing angles in degrees.</param>
  5009. /// <returns>Vector containing angles converted to radians.</returns>
  5010. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5011. public static float2 radians(float2 x) { return x * TORADIANS; }
  5012. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  5013. /// <param name="x">Vector containing angles in degrees.</param>
  5014. /// <returns>Vector containing angles converted to radians.</returns>
  5015. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5016. public static float3 radians(float3 x) { return x * TORADIANS; }
  5017. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  5018. /// <param name="x">Vector containing angles in degrees.</param>
  5019. /// <returns>Vector containing angles converted to radians.</returns>
  5020. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5021. public static float4 radians(float4 x) { return x * TORADIANS; }
  5022. /// <summary>Returns the result of converting a float value from degrees to radians.</summary>
  5023. /// <param name="x">Angle in degrees.</param>
  5024. /// <returns>Angle converted to radians.</returns>
  5025. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5026. public static double radians(double x) { return x * TORADIANS_DBL; }
  5027. /// <summary>Returns the result of a componentwise conversion of a float2 vector from degrees to radians.</summary>
  5028. /// <param name="x">Vector containing angles in degrees.</param>
  5029. /// <returns>Vector containing angles converted to radians.</returns>
  5030. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5031. public static double2 radians(double2 x) { return x * TORADIANS_DBL; }
  5032. /// <summary>Returns the result of a componentwise conversion of a float3 vector from degrees to radians.</summary>
  5033. /// <param name="x">Vector containing angles in degrees.</param>
  5034. /// <returns>Vector containing angles converted to radians.</returns>
  5035. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5036. public static double3 radians(double3 x) { return x * TORADIANS_DBL; }
  5037. /// <summary>Returns the result of a componentwise conversion of a float4 vector from degrees to radians.</summary>
  5038. /// <param name="x">Vector containing angles in degrees.</param>
  5039. /// <returns>Vector containing angles converted to radians.</returns>
  5040. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5041. public static double4 radians(double4 x) { return x * TORADIANS_DBL; }
  5042. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  5043. /// <param name="x">Angle in radians.</param>
  5044. /// <returns>Angle converted to degrees.</returns>
  5045. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5046. public static float degrees(float x) { return x * TODEGREES; }
  5047. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  5048. /// <param name="x">Vector containing angles in radians.</param>
  5049. /// <returns>Vector containing angles converted to degrees.</returns>
  5050. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5051. public static float2 degrees(float2 x) { return x * TODEGREES; }
  5052. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  5053. /// <param name="x">Vector containing angles in radians.</param>
  5054. /// <returns>Vector containing angles converted to degrees.</returns>
  5055. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5056. public static float3 degrees(float3 x) { return x * TODEGREES; }
  5057. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  5058. /// <param name="x">Vector containing angles in radians.</param>
  5059. /// <returns>Vector containing angles converted to degrees.</returns>
  5060. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5061. public static float4 degrees(float4 x) { return x * TODEGREES; }
  5062. /// <summary>Returns the result of converting a double value from radians to degrees.</summary>
  5063. /// <param name="x">Angle in radians.</param>
  5064. /// <returns>Angle converted to degrees.</returns>
  5065. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5066. public static double degrees(double x) { return x * TODEGREES_DBL; }
  5067. /// <summary>Returns the result of a componentwise conversion of a double2 vector from radians to degrees.</summary>
  5068. /// <param name="x">Vector containing angles in radians.</param>
  5069. /// <returns>Vector containing angles converted to degrees.</returns>
  5070. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5071. public static double2 degrees(double2 x) { return x * TODEGREES_DBL; }
  5072. /// <summary>Returns the result of a componentwise conversion of a double3 vector from radians to degrees.</summary>
  5073. /// <param name="x">Vector containing angles in radians.</param>
  5074. /// <returns>Vector containing values converted to degrees.</returns>
  5075. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5076. public static double3 degrees(double3 x) { return x * TODEGREES_DBL; }
  5077. /// <summary>Returns the result of a componentwise conversion of a double4 vector from radians to degrees.</summary>
  5078. /// <param name="x">Vector containing angles in radians.</param>
  5079. /// <returns>Vector containing angles converted to degrees.</returns>
  5080. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5081. public static double4 degrees(double4 x) { return x * TODEGREES_DBL; }
  5082. /// <summary>Returns the minimum component of an int2 vector.</summary>
  5083. /// <param name="x">The vector to use when computing the minimum component.</param>
  5084. /// <returns>The value of the minimum component of the vector.</returns>
  5085. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5086. public static int cmin(int2 x) { return min(x.x, x.y); }
  5087. /// <summary>Returns the minimum component of an int3 vector.</summary>
  5088. /// <param name="x">The vector to use when computing the minimum component.</param>
  5089. /// <returns>The value of the minimum component of the vector.</returns>
  5090. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5091. public static int cmin(int3 x) { return min(min(x.x, x.y), x.z); }
  5092. /// <summary>Returns the minimum component of an int4 vector.</summary>
  5093. /// <param name="x">The vector to use when computing the minimum component.</param>
  5094. /// <returns>The value of the minimum component of the vector.</returns>
  5095. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5096. public static int cmin(int4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  5097. /// <summary>Returns the minimum component of a uint2 vector.</summary>
  5098. /// <param name="x">The vector to use when computing the minimum component.</param>
  5099. /// <returns>The value of the minimum component of the vector.</returns>
  5100. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5101. public static uint cmin(uint2 x) { return min(x.x, x.y); }
  5102. /// <summary>Returns the minimum component of a uint3 vector.</summary>
  5103. /// <param name="x">The vector to use when computing the minimum component.</param>
  5104. /// <returns>The value of the minimum component of the vector.</returns>
  5105. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5106. public static uint cmin(uint3 x) { return min(min(x.x, x.y), x.z); }
  5107. /// <summary>Returns the minimum component of a uint4 vector.</summary>
  5108. /// <param name="x">The vector to use when computing the minimum component.</param>
  5109. /// <returns>The value of the minimum component of the vector.</returns>
  5110. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5111. public static uint cmin(uint4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  5112. /// <summary>Returns the minimum component of a float2 vector.</summary>
  5113. /// <param name="x">The vector to use when computing the minimum component.</param>
  5114. /// <returns>The value of the minimum component of the vector.</returns>
  5115. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5116. public static float cmin(float2 x) { return min(x.x, x.y); }
  5117. /// <summary>Returns the minimum component of a float3 vector.</summary>
  5118. /// <param name="x">The vector to use when computing the minimum component.</param>
  5119. /// <returns>The value of the minimum component of the vector.</returns>
  5120. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5121. public static float cmin(float3 x) { return min(min(x.x, x.y), x.z); }
  5122. /// <summary>Returns the minimum component of a float4 vector.</summary>
  5123. /// <param name="x">The vector to use when computing the minimum component.</param>
  5124. /// <returns>The value of the minimum component of the vector.</returns>
  5125. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5126. public static float cmin(float4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  5127. /// <summary>Returns the minimum component of a double2 vector.</summary>
  5128. /// <param name="x">The vector to use when computing the minimum component.</param>
  5129. /// <returns>The value of the minimum component of the vector.</returns>
  5130. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5131. public static double cmin(double2 x) { return min(x.x, x.y); }
  5132. /// <summary>Returns the minimum component of a double3 vector.</summary>
  5133. /// <param name="x">The vector to use when computing the minimum component.</param>
  5134. /// <returns>The value of the minimum component of the vector.</returns>
  5135. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5136. public static double cmin(double3 x) { return min(min(x.x, x.y), x.z); }
  5137. /// <summary>Returns the minimum component of a double4 vector.</summary>
  5138. /// <param name="x">The vector to use when computing the minimum component.</param>
  5139. /// <returns>The value of the minimum component of the vector.</returns>
  5140. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5141. public static double cmin(double4 x) { return min(min(x.x, x.y), min(x.z, x.w)); }
  5142. /// <summary>Returns the maximum component of an int2 vector.</summary>
  5143. /// <param name="x">The vector to use when computing the maximum component.</param>
  5144. /// <returns>The value of the maximum component of the vector.</returns>
  5145. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5146. public static int cmax(int2 x) { return max(x.x, x.y); }
  5147. /// <summary>Returns the maximum component of an int3 vector.</summary>
  5148. /// <param name="x">The vector to use when computing the maximum component.</param>
  5149. /// <returns>The value of the maximum component of the vector.</returns>
  5150. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5151. public static int cmax(int3 x) { return max(max(x.x, x.y), x.z); }
  5152. /// <summary>Returns the maximum component of an int4 vector.</summary>
  5153. /// <param name="x">The vector to use when computing the maximum component.</param>
  5154. /// <returns>The value of the maximum component of the vector.</returns>
  5155. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5156. public static int cmax(int4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  5157. /// <summary>Returns the maximum component of a uint2 vector.</summary>
  5158. /// <param name="x">The vector to use when computing the maximum component.</param>
  5159. /// <returns>The value of the maximum component of the vector.</returns>
  5160. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5161. public static uint cmax(uint2 x) { return max(x.x, x.y); }
  5162. /// <summary>Returns the maximum component of a uint3 vector.</summary>
  5163. /// <param name="x">The vector to use when computing the maximum component.</param>
  5164. /// <returns>The value of the maximum component of the vector.</returns>
  5165. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5166. public static uint cmax(uint3 x) { return max(max(x.x, x.y), x.z); }
  5167. /// <summary>Returns the maximum component of a uint4 vector.</summary>
  5168. /// <param name="x">The vector to use when computing the maximum component.</param>
  5169. /// <returns>The value of the maximum component of the vector.</returns>
  5170. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5171. public static uint cmax(uint4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  5172. /// <summary>Returns the maximum component of a float2 vector.</summary>
  5173. /// <param name="x">The vector to use when computing the maximum component.</param>
  5174. /// <returns>The value of the maximum component of the vector.</returns>
  5175. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5176. public static float cmax(float2 x) { return max(x.x, x.y); }
  5177. /// <summary>Returns the maximum component of a float3 vector.</summary>
  5178. /// <param name="x">The vector to use when computing the maximum component.</param>
  5179. /// <returns>The value of the maximum component of the vector.</returns>
  5180. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5181. public static float cmax(float3 x) { return max(max(x.x, x.y), x.z); }
  5182. /// <summary>Returns the maximum component of a float4 vector.</summary>
  5183. /// <param name="x">The vector to use when computing the maximum component.</param>
  5184. /// <returns>The value of the maximum component of the vector.</returns>
  5185. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5186. public static float cmax(float4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  5187. /// <summary>Returns the maximum component of a double2 vector.</summary>
  5188. /// <param name="x">The vector to use when computing the maximum component.</param>
  5189. /// <returns>The value of the maximum component of the vector.</returns>
  5190. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5191. public static double cmax(double2 x) { return max(x.x, x.y); }
  5192. /// <summary>Returns the maximum component of a double3 vector.</summary>
  5193. /// <param name="x">The vector to use when computing the maximum component.</param>
  5194. /// <returns>The value of the maximum component of the vector.</returns>
  5195. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5196. public static double cmax(double3 x) { return max(max(x.x, x.y), x.z); }
  5197. /// <summary>Returns the maximum component of a double4 vector.</summary>
  5198. /// <param name="x">The vector to use when computing the maximum component.</param>
  5199. /// <returns>The value of the maximum component of the vector.</returns>
  5200. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5201. public static double cmax(double4 x) { return max(max(x.x, x.y), max(x.z, x.w)); }
  5202. /// <summary>Returns the horizontal sum of components of an int2 vector.</summary>
  5203. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5204. /// <returns>The horizontal sum of of components of the vector.</returns>
  5205. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5206. public static int csum(int2 x) { return x.x + x.y; }
  5207. /// <summary>Returns the horizontal sum of components of an int3 vector.</summary>
  5208. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5209. /// <returns>The horizontal sum of of components of the vector.</returns>
  5210. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5211. public static int csum(int3 x) { return x.x + x.y + x.z; }
  5212. /// <summary>Returns the horizontal sum of components of an int4 vector.</summary>
  5213. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5214. /// <returns>The horizontal sum of of components of the vector.</returns>
  5215. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5216. public static int csum(int4 x) { return x.x + x.y + x.z + x.w; }
  5217. /// <summary>Returns the horizontal sum of components of a uint2 vector.</summary>
  5218. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5219. /// <returns>The horizontal sum of of components of the vector.</returns>
  5220. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5221. public static uint csum(uint2 x) { return x.x + x.y; }
  5222. /// <summary>Returns the horizontal sum of components of a uint3 vector.</summary>
  5223. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5224. /// <returns>The horizontal sum of of components of the vector.</returns>
  5225. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5226. public static uint csum(uint3 x) { return x.x + x.y + x.z; }
  5227. /// <summary>Returns the horizontal sum of components of a uint4 vector.</summary>
  5228. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5229. /// <returns>The horizontal sum of of components of the vector.</returns>
  5230. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5231. public static uint csum(uint4 x) { return x.x + x.y + x.z + x.w; }
  5232. /// <summary>Returns the horizontal sum of components of a float2 vector.</summary>
  5233. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5234. /// <returns>The horizontal sum of of components of the vector.</returns>
  5235. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5236. public static float csum(float2 x) { return x.x + x.y; }
  5237. /// <summary>Returns the horizontal sum of components of a float3 vector.</summary>
  5238. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5239. /// <returns>The horizontal sum of of components of the vector.</returns>
  5240. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5241. public static float csum(float3 x) { return x.x + x.y + x.z; }
  5242. /// <summary>Returns the horizontal sum of components of a float4 vector.</summary>
  5243. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5244. /// <returns>The horizontal sum of of components of the vector.</returns>
  5245. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5246. public static float csum(float4 x) { return (x.x + x.y) + (x.z + x.w); }
  5247. /// <summary>Returns the horizontal sum of components of a double2 vector.</summary>
  5248. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5249. /// <returns>The horizontal sum of of components of the vector.</returns>
  5250. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5251. public static double csum(double2 x) { return x.x + x.y; }
  5252. /// <summary>Returns the horizontal sum of components of a double3 vector.</summary>
  5253. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5254. /// <returns>The horizontal sum of of components of the vector.</returns>
  5255. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5256. public static double csum(double3 x) { return x.x + x.y + x.z; }
  5257. /// <summary>Returns the horizontal sum of components of a double4 vector.</summary>
  5258. /// <param name="x">The vector to use when computing the horizontal sum.</param>
  5259. /// <returns>The horizontal sum of of components of the vector.</returns>
  5260. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5261. public static double csum(double4 x) { return (x.x + x.y) + (x.z + x.w); }
  5262. /// <summary>
  5263. /// Computes the square (x * x) of the input argument x.
  5264. /// </summary>
  5265. /// <param name="x">Value to square.</param>
  5266. /// <returns>Returns the square of the input.</returns>
  5267. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5268. public static float square(float x)
  5269. {
  5270. return x * x;
  5271. }
  5272. /// <summary>
  5273. /// Computes the component-wise square (x * x) of the input argument x.
  5274. /// </summary>
  5275. /// <param name="x">Value to square.</param>
  5276. /// <returns>Returns the square of the input.</returns>
  5277. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5278. public static float2 square(float2 x)
  5279. {
  5280. return x * x;
  5281. }
  5282. /// <summary>
  5283. /// Computes the component-wise square (x * x) of the input argument x.
  5284. /// </summary>
  5285. /// <param name="x">Value to square.</param>
  5286. /// <returns>Returns the square of the input.</returns>
  5287. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5288. public static float3 square(float3 x)
  5289. {
  5290. return x * x;
  5291. }
  5292. /// <summary>
  5293. /// Computes the component-wise square (x * x) of the input argument x.
  5294. /// </summary>
  5295. /// <param name="x">Value to square.</param>
  5296. /// <returns>Returns the square of the input.</returns>
  5297. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5298. public static float4 square(float4 x)
  5299. {
  5300. return x * x;
  5301. }
  5302. /// <summary>
  5303. /// Computes the square (x * x) of the input argument x.
  5304. /// </summary>
  5305. /// <param name="x">Value to square.</param>
  5306. /// <returns>Returns the square of the input.</returns>
  5307. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5308. public static double square(double x)
  5309. {
  5310. return x * x;
  5311. }
  5312. /// <summary>
  5313. /// Computes the component-wise square (x * x) of the input argument x.
  5314. /// </summary>
  5315. /// <param name="x">Value to square.</param>
  5316. /// <returns>Returns the square of the input.</returns>
  5317. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5318. public static double2 square(double2 x)
  5319. {
  5320. return x * x;
  5321. }
  5322. /// <summary>
  5323. /// Computes the component-wise square (x * x) of the input argument x.
  5324. /// </summary>
  5325. /// <param name="x">Value to square.</param>
  5326. /// <returns>Returns the square of the input.</returns>
  5327. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5328. public static double3 square(double3 x)
  5329. {
  5330. return x * x;
  5331. }
  5332. /// <summary>
  5333. /// Computes the component-wise square (x * x) of the input argument x.
  5334. /// </summary>
  5335. /// <param name="x">Value to square.</param>
  5336. /// <returns>Returns the square of the input.</returns>
  5337. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5338. public static double4 square(double4 x)
  5339. {
  5340. return x * x;
  5341. }
  5342. /// <summary>
  5343. /// Computes the square (x * x) of the input argument x.
  5344. /// </summary>
  5345. /// <remarks>
  5346. /// Due to integer overflow, it's not always guaranteed that <c>square(x)</c> is positive. For example, <c>square(46341)</c>
  5347. /// will return <c>-2147479015</c>.
  5348. /// </remarks>
  5349. /// <param name="x">Value to square.</param>
  5350. /// <returns>Returns the square of the input.</returns>
  5351. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5352. public static int square(int x)
  5353. {
  5354. return x * x;
  5355. }
  5356. /// <summary>
  5357. /// Computes the component-wise square (x * x) of the input argument x.
  5358. /// </summary>
  5359. /// <remarks>
  5360. /// Due to integer overflow, it's not always guaranteed that <c>square(x)</c> is positive. For example, <c>square(new int2(46341))</c>
  5361. /// will return <c>new int2(-2147479015)</c>.
  5362. /// </remarks>
  5363. /// <param name="x">Value to square.</param>
  5364. /// <returns>Returns the square of the input.</returns>
  5365. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5366. public static int2 square(int2 x)
  5367. {
  5368. return x * x;
  5369. }
  5370. /// <summary>
  5371. /// Computes the component-wise square (x * x) of the input argument x.
  5372. /// </summary>
  5373. /// <remarks>
  5374. /// Due to integer overflow, it's not always guaranteed that <c>square(x)</c> is positive. For example, <c>square(new int3(46341))</c>
  5375. /// will return <c>new int3(-2147479015)</c>.
  5376. /// </remarks>
  5377. /// <param name="x">Value to square.</param>
  5378. /// <returns>Returns the square of the input.</returns>
  5379. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5380. public static int3 square(int3 x)
  5381. {
  5382. return x * x;
  5383. }
  5384. /// <summary>
  5385. /// Computes the component-wise square (x * x) of the input argument x.
  5386. /// </summary>
  5387. /// <remarks>
  5388. /// Due to integer overflow, it's not always guaranteed that <c>square(x)</c> is positive. For example, <c>square(new int4(46341))</c>
  5389. /// will return <c>new int4(-2147479015)</c>.
  5390. /// </remarks>
  5391. /// <param name="x">Value to square.</param>
  5392. /// <returns>Returns the square of the input.</returns>
  5393. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5394. public static int4 square(int4 x)
  5395. {
  5396. return x * x;
  5397. }
  5398. /// <summary>
  5399. /// Computes the square (x * x) of the input argument x.
  5400. /// </summary>
  5401. /// <remarks>
  5402. /// Due to integer overflow, it's not always guaranteed that <c>square(x) &gt;= x</c>. For example, <c>square(4294967295u)</c>
  5403. /// will return <c>1u</c>.
  5404. /// </remarks>
  5405. /// <param name="x">Value to square.</param>
  5406. /// <returns>Returns the square of the input.</returns>
  5407. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5408. public static uint square(uint x)
  5409. {
  5410. return x * x;
  5411. }
  5412. /// <summary>
  5413. /// Computes the component-wise square (x * x) of the input argument x.
  5414. /// </summary>
  5415. /// <remarks>
  5416. /// Due to integer overflow, it's not always guaranteed that <c>square(x) &gt;= x</c>. For example, <c>square(new uint2(4294967295u))</c>
  5417. /// will return <c>new uint2(1u)</c>.
  5418. /// </remarks>
  5419. /// <param name="x">Value to square.</param>
  5420. /// <returns>Returns the square of the input.</returns>
  5421. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5422. public static uint2 square(uint2 x)
  5423. {
  5424. return x * x;
  5425. }
  5426. /// <summary>
  5427. /// Computes the component-wise square (x * x) of the input argument x.
  5428. /// </summary>
  5429. /// <remarks>
  5430. /// Due to integer overflow, it's not always guaranteed that <c>square(x) &gt;= x</c>. For example, <c>square(new uint3(4294967295u))</c>
  5431. /// will return <c>new uint3(1u)</c>.
  5432. /// </remarks>
  5433. /// <param name="x">Value to square.</param>
  5434. /// <returns>Returns the square of the input.</returns>
  5435. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5436. public static uint3 square(uint3 x)
  5437. {
  5438. return x * x;
  5439. }
  5440. /// <summary>
  5441. /// Computes the component-wise square (x * x) of the input argument x.
  5442. /// </summary>
  5443. /// <remarks>
  5444. /// Due to integer overflow, it's not always guaranteed that <c>square(x) &gt;= x</c>. For example, <c>square(new uint4(4294967295u))</c>
  5445. /// will return <c>new uint4(1u)</c>.
  5446. /// </remarks>
  5447. /// <param name="x">Value to square.</param>
  5448. /// <returns>Returns the square of the input.</returns>
  5449. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5450. public static uint4 square(uint4 x)
  5451. {
  5452. return x * x;
  5453. }
  5454. /// <summary>
  5455. /// Packs components with an enabled mask to the left.
  5456. /// </summary>
  5457. /// <remarks>
  5458. /// This function is also known as left packing. The effect of this function is to filter out components that
  5459. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5460. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5461. /// produce an output array of the things that intersected.
  5462. /// </remarks>
  5463. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5464. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5465. /// <param name="val">The value to to compress.</param>
  5466. /// <param name="mask">Mask indicating which components are enabled.</param>
  5467. /// <returns>Index to element after the last one stored.</returns>
  5468. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5469. public static unsafe int compress(int* output, int index, int4 val, bool4 mask)
  5470. {
  5471. if (mask.x)
  5472. output[index++] = val.x;
  5473. if (mask.y)
  5474. output[index++] = val.y;
  5475. if (mask.z)
  5476. output[index++] = val.z;
  5477. if (mask.w)
  5478. output[index++] = val.w;
  5479. return index;
  5480. }
  5481. /// <summary>
  5482. /// Packs components with an enabled mask to the left.
  5483. /// </summary>
  5484. /// <remarks>
  5485. /// This function is also known as left packing. The effect of this function is to filter out components that
  5486. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5487. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5488. /// produce an output array of the things that intersected.
  5489. /// </remarks>
  5490. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5491. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5492. /// <param name="val">The value to to compress.</param>
  5493. /// <param name="mask">Mask indicating which components are enabled.</param>
  5494. /// <returns>Index to element after the last one stored.</returns>
  5495. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5496. public static unsafe int compress(uint* output, int index, uint4 val, bool4 mask)
  5497. {
  5498. return compress((int*)output, index, *(int4*)&val, mask);
  5499. }
  5500. /// <summary>
  5501. /// Packs components with an enabled mask to the left.
  5502. /// </summary>
  5503. /// <remarks>
  5504. /// This function is also known as left packing. The effect of this function is to filter out components that
  5505. /// are not enabled and leave an output buffer tightly packed with only the enabled components. A common use
  5506. /// case is if you perform intersection tests on arrays of data in structure of arrays (SoA) form and need to
  5507. /// produce an output array of the things that intersected.
  5508. /// </remarks>
  5509. /// <param name="output">Pointer to packed output array where enabled components should be stored to.</param>
  5510. /// <param name="index">Index into output array where first enabled component should be stored to.</param>
  5511. /// <param name="val">The value to to compress.</param>
  5512. /// <param name="mask">Mask indicating which components are enabled.</param>
  5513. /// <returns>Index to element after the last one stored.</returns>
  5514. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5515. public static unsafe int compress(float* output, int index, float4 val, bool4 mask)
  5516. {
  5517. return compress((int*)output, index, *(int4*)&val, mask);
  5518. }
  5519. /// <summary>Returns the floating point representation of a half-precision floating point value.</summary>
  5520. /// <param name="x">The half precision float.</param>
  5521. /// <returns>The single precision float representation of the half precision float.</returns>
  5522. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5523. public static float f16tof32(uint x)
  5524. {
  5525. const uint shifted_exp = (0x7c00 << 13);
  5526. uint uf = (x & 0x7fff) << 13;
  5527. uint e = uf & shifted_exp;
  5528. uf += (127 - 15) << 23;
  5529. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5530. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5531. uf |= (x & 0x8000) << 16;
  5532. return asfloat(uf);
  5533. }
  5534. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5535. /// <param name="x">The half precision float vector.</param>
  5536. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5537. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5538. public static float2 f16tof32(uint2 x)
  5539. {
  5540. const uint shifted_exp = (0x7c00 << 13);
  5541. uint2 uf = (x & 0x7fff) << 13;
  5542. uint2 e = uf & shifted_exp;
  5543. uf += (127 - 15) << 23;
  5544. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5545. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5546. uf |= (x & 0x8000) << 16;
  5547. return asfloat(uf);
  5548. }
  5549. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5550. /// <param name="x">The half precision float vector.</param>
  5551. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5552. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5553. public static float3 f16tof32(uint3 x)
  5554. {
  5555. const uint shifted_exp = (0x7c00 << 13);
  5556. uint3 uf = (x & 0x7fff) << 13;
  5557. uint3 e = uf & shifted_exp;
  5558. uf += (127 - 15) << 23;
  5559. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5560. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5561. uf |= (x & 0x8000) << 16;
  5562. return asfloat(uf);
  5563. }
  5564. /// <summary>Returns the floating point representation of a half-precision floating point vector.</summary>
  5565. /// <param name="x">The half precision float vector.</param>
  5566. /// <returns>The single precision float vector representation of the half precision float vector.</returns>
  5567. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5568. public static float4 f16tof32(uint4 x)
  5569. {
  5570. const uint shifted_exp = (0x7c00 << 13);
  5571. uint4 uf = (x & 0x7fff) << 13;
  5572. uint4 e = uf & shifted_exp;
  5573. uf += (127 - 15) << 23;
  5574. uf += select(0, (128u - 16u) << 23, e == shifted_exp);
  5575. uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
  5576. uf |= (x & 0x8000) << 16;
  5577. return asfloat(uf);
  5578. }
  5579. /// <summary>Returns the result converting a float value to its nearest half-precision floating point representation.</summary>
  5580. /// <param name="x">The single precision float.</param>
  5581. /// <returns>The half precision float representation of the single precision float.</returns>
  5582. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5583. public static uint f32tof16(float x)
  5584. {
  5585. const int infinity_32 = 255 << 23;
  5586. const uint msk = 0x7FFFF000u;
  5587. uint ux = asuint(x);
  5588. uint uux = ux & msk;
  5589. uint h = (uint)(asuint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5590. h = select(h, select(0x7c00u, 0x7e00u, (int)uux > infinity_32), (int)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5591. return h | (ux & ~msk) >> 16;
  5592. }
  5593. /// <summary>Returns the result of a componentwise conversion of a float2 vector to its nearest half-precision floating point representation.</summary>
  5594. /// <param name="x">The single precision float vector.</param>
  5595. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5596. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5597. public static uint2 f32tof16(float2 x)
  5598. {
  5599. const int infinity_32 = 255 << 23;
  5600. const uint msk = 0x7FFFF000u;
  5601. uint2 ux = asuint(x);
  5602. uint2 uux = ux & msk;
  5603. uint2 h = (uint2)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5604. h = select(h, select(0x7c00u, 0x7e00u, (int2)uux > infinity_32), (int2)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5605. return h | (ux & ~msk) >> 16;
  5606. }
  5607. /// <summary>Returns the result of a componentwise conversion of a float3 vector to its nearest half-precision floating point representation.</summary>
  5608. /// <param name="x">The single precision float vector.</param>
  5609. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5610. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5611. public static uint3 f32tof16(float3 x)
  5612. {
  5613. const int infinity_32 = 255 << 23;
  5614. const uint msk = 0x7FFFF000u;
  5615. uint3 ux = asuint(x);
  5616. uint3 uux = ux & msk;
  5617. uint3 h = (uint3)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5618. h = select(h, select(0x7c00u, 0x7e00u, (int3)uux > infinity_32), (int3)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5619. return h | (ux & ~msk) >> 16;
  5620. }
  5621. /// <summary>Returns the result of a componentwise conversion of a float4 vector to its nearest half-precision floating point representation.</summary>
  5622. /// <param name="x">The single precision float vector.</param>
  5623. /// <returns>The half precision float vector representation of the single precision float vector.</returns>
  5624. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5625. public static uint4 f32tof16(float4 x)
  5626. {
  5627. const int infinity_32 = 255 << 23;
  5628. const uint msk = 0x7FFFF000u;
  5629. uint4 ux = asuint(x);
  5630. uint4 uux = ux & msk;
  5631. uint4 h = (uint4)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed
  5632. h = select(h, select(0x7c00u, 0x7e00u, (int4)uux > infinity_32), (int4)uux >= infinity_32); // NaN->qNaN and Inf->Inf
  5633. return h | (ux & ~msk) >> 16;
  5634. }
  5635. /// <summary>
  5636. /// Generate an orthonormal basis given a single unit length normal vector.
  5637. /// </summary>
  5638. /// <remarks>
  5639. /// This implementation is from "Building an Orthonormal Basis, Revisited"
  5640. /// https://graphics.pixar.com/library/OrthonormalB/paper.pdf
  5641. /// </remarks>
  5642. /// <param name="normal">Unit length normal vector.</param>
  5643. /// <param name="basis1">Output unit length vector, orthogonal to normal vector.</param>
  5644. /// <param name="basis2">Output unit length vector, orthogonal to normal vector and basis1.</param>
  5645. public static void orthonormal_basis(float3 normal, out float3 basis1, out float3 basis2)
  5646. {
  5647. var sign = normal.z >= 0.0f ? 1.0f : -1.0f;
  5648. var a = -1.0f / (sign + normal.z);
  5649. var b = normal.x * normal.y * a;
  5650. basis1.x = 1.0f + sign * normal.x * normal.x * a;
  5651. basis1.y = sign * b;
  5652. basis1.z = -sign * normal.x;
  5653. basis2.x = b;
  5654. basis2.y = sign + normal.y * normal.y * a;
  5655. basis2.z = -normal.y;
  5656. }
  5657. /// <summary>
  5658. /// Generate an orthonormal basis given a single unit length normal vector.
  5659. /// </summary>
  5660. /// <remarks>
  5661. /// This implementation is from "Building an Orthonormal Basis, Revisited"
  5662. /// https://graphics.pixar.com/library/OrthonormalB/paper.pdf
  5663. /// </remarks>
  5664. /// <param name="normal">Unit length normal vector.</param>
  5665. /// <param name="basis1">Output unit length vector, orthogonal to normal vector.</param>
  5666. /// <param name="basis2">Output unit length vector, orthogonal to normal vector and basis1.</param>
  5667. public static void orthonormal_basis(double3 normal, out double3 basis1, out double3 basis2)
  5668. {
  5669. var sign = normal.z >= 0.0 ? 1.0 : -1.0;
  5670. var a = -1.0 / (sign + normal.z);
  5671. var b = normal.x * normal.y * a;
  5672. basis1.x = 1.0 + sign * normal.x * normal.x * a;
  5673. basis1.y = sign * b;
  5674. basis1.z = -sign * normal.x;
  5675. basis2.x = b;
  5676. basis2.y = sign + normal.y * normal.y * a;
  5677. basis2.z = -normal.y;
  5678. }
  5679. /// <summary>Change the sign of x based on the most significant bit of y [msb(y) ? -x : x].</summary>
  5680. /// <param name="x">The single precision float to change the sign.</param>
  5681. /// <param name="y">The single precision float used to test the most significant bit.</param>
  5682. /// <returns>Returns x with changed sign based on y.</returns>
  5683. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5684. public static float chgsign(float x, float y)
  5685. {
  5686. return asfloat(asuint(x) ^ (asuint(y) & 0x80000000));
  5687. }
  5688. /// <summary>Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x].</summary>
  5689. /// <param name="x">The single precision float vector to change the sign.</param>
  5690. /// <param name="y">The single precision float vector used to test the most significant bit.</param>
  5691. /// <returns>Returns vector x with changed sign based on vector y.</returns>
  5692. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5693. public static float2 chgsign(float2 x, float2 y)
  5694. {
  5695. return asfloat(asuint(x) ^ (asuint(y) & 0x80000000));
  5696. }
  5697. /// <summary>Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x].</summary>
  5698. /// <param name="x">The single precision float vector to change the sign.</param>
  5699. /// <param name="y">The single precision float vector used to test the most significant bit.</param>
  5700. /// <returns>Returns vector x with changed sign based on vector y.</returns>
  5701. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5702. public static float3 chgsign(float3 x, float3 y)
  5703. {
  5704. return asfloat(asuint(x) ^ (asuint(y) & 0x80000000));
  5705. }
  5706. /// <summary>Change the sign of components of x based on the most significant bit of components of y [msb(y) ? -x : x].</summary>
  5707. /// <param name="x">The single precision float vector to change the sign.</param>
  5708. /// <param name="y">The single precision float vector used to test the most significant bit.</param>
  5709. /// <returns>Returns vector x with changed sign based on vector y.</returns>
  5710. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5711. public static float4 chgsign(float4 x, float4 y)
  5712. {
  5713. return asfloat(asuint(x) ^ (asuint(y) & 0x80000000));
  5714. }
  5715. /// <summary>Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context.</summary>
  5716. /// <param name="pBuffer">A pointer to the beginning of the data.</param>
  5717. /// <param name="numBytes">Number of bytes to hash.</param>
  5718. /// <param name="seed">Starting seed value.</param>
  5719. /// <returns>The 32 bit hash of the input data buffer.</returns>
  5720. public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0)
  5721. {
  5722. unchecked
  5723. {
  5724. const uint Prime1 = 2654435761;
  5725. const uint Prime2 = 2246822519;
  5726. const uint Prime3 = 3266489917;
  5727. const uint Prime4 = 668265263;
  5728. const uint Prime5 = 374761393;
  5729. uint4* p = (uint4*)pBuffer;
  5730. uint hash = seed + Prime5;
  5731. if (numBytes >= 16)
  5732. {
  5733. uint4 state = new uint4(Prime1 + Prime2, Prime2, 0, (uint)-Prime1) + seed;
  5734. int count = numBytes >> 4;
  5735. for (int i = 0; i < count; ++i)
  5736. {
  5737. state += *p++ * Prime2;
  5738. state = (state << 13) | (state >> 19);
  5739. state *= Prime1;
  5740. }
  5741. hash = rol(state.x, 1) + rol(state.y, 7) + rol(state.z, 12) + rol(state.w, 18);
  5742. }
  5743. hash += (uint)numBytes;
  5744. uint* puint = (uint*)p;
  5745. for (int i = 0; i < ((numBytes >> 2) & 3); ++i)
  5746. {
  5747. hash += *puint++ * Prime3;
  5748. hash = rol(hash, 17) * Prime4;
  5749. }
  5750. byte* pbyte = (byte*)puint;
  5751. for (int i = 0; i < ((numBytes) & 3); ++i)
  5752. {
  5753. hash += (*pbyte++) * Prime5;
  5754. hash = rol(hash, 11) * Prime1;
  5755. }
  5756. hash ^= hash >> 15;
  5757. hash *= Prime2;
  5758. hash ^= hash >> 13;
  5759. hash *= Prime3;
  5760. hash ^= hash >> 16;
  5761. return hash;
  5762. }
  5763. }
  5764. /// <summary>
  5765. /// Unity's up axis (0, 1, 0).
  5766. /// </summary>
  5767. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-up.html](https://docs.unity3d.com/ScriptReference/Vector3-up.html)</remarks>
  5768. /// <returns>The up axis.</returns>
  5769. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5770. public static float3 up() { return new float3(0.0f, 1.0f, 0.0f); } // for compatibility
  5771. /// <summary>
  5772. /// Unity's down axis (0, -1, 0).
  5773. /// </summary>
  5774. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-down.html](https://docs.unity3d.com/ScriptReference/Vector3-down.html)</remarks>
  5775. /// <returns>The down axis.</returns>
  5776. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5777. public static float3 down() { return new float3(0.0f, -1.0f, 0.0f); }
  5778. /// <summary>
  5779. /// Unity's forward axis (0, 0, 1).
  5780. /// </summary>
  5781. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-forward.html](https://docs.unity3d.com/ScriptReference/Vector3-forward.html)</remarks>
  5782. /// <returns>The forward axis.</returns>
  5783. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5784. public static float3 forward() { return new float3(0.0f, 0.0f, 1.0f); }
  5785. /// <summary>
  5786. /// Unity's back axis (0, 0, -1).
  5787. /// </summary>
  5788. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-back.html](https://docs.unity3d.com/ScriptReference/Vector3-back.html)</remarks>
  5789. /// <returns>The back axis.</returns>
  5790. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5791. public static float3 back() { return new float3(0.0f, 0.0f, -1.0f); }
  5792. /// <summary>
  5793. /// Unity's left axis (-1, 0, 0).
  5794. /// </summary>
  5795. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-left.html](https://docs.unity3d.com/ScriptReference/Vector3-left.html)</remarks>
  5796. /// <returns>The left axis.</returns>
  5797. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5798. public static float3 left() { return new float3(-1.0f, 0.0f, 0.0f); }
  5799. /// <summary>
  5800. /// Unity's right axis (1, 0, 0).
  5801. /// </summary>
  5802. /// <remarks>Matches [https://docs.unity3d.com/ScriptReference/Vector3-right.html](https://docs.unity3d.com/ScriptReference/Vector3-right.html)</remarks>
  5803. /// <returns>The right axis.</returns>
  5804. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5805. public static float3 right() { return new float3(1.0f, 0.0f, 0.0f); }
  5806. /// <summary>
  5807. /// Returns the Euler angle representation of the quaternion following the XYZ rotation order.
  5808. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5809. /// </summary>
  5810. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5811. /// <returns>The Euler angle representation of the quaternion in XYZ order.</returns>
  5812. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5813. public static float3 EulerXYZ(quaternion q)
  5814. {
  5815. const float epsilon = 1e-6f;
  5816. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5817. // prepare the data
  5818. var qv = q.value;
  5819. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5820. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  5821. var d3 = qv * qv;
  5822. var euler = Unity.Mathematics.float3.zero;
  5823. var y1 = d2.z - d1.y;
  5824. if (y1 * y1 < cutoff)
  5825. {
  5826. var x1 = d2.y + d1.x;
  5827. var x2 = d3.z + d3.w - d3.y - d3.x;
  5828. var z1 = d2.x + d1.z;
  5829. var z2 = d3.x + d3.w - d3.y - d3.z;
  5830. euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2));
  5831. }
  5832. else //xzx
  5833. {
  5834. y1 = clamp(y1, -1f, 1f);
  5835. var abcd = float4(d2.z, d1.y, d2.x, d1.z);
  5836. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  5837. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  5838. euler = float3(atan2(x1, x2), -asin(y1), 0f);
  5839. }
  5840. return euler;
  5841. }
  5842. /// <summary>
  5843. /// Returns the Euler angle representation of the quaternion following the XZY rotation order.
  5844. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5845. /// </summary>
  5846. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5847. /// <returns>The Euler angle representation of the quaternion in XZY order.</returns>
  5848. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5849. public static float3 EulerXZY(quaternion q)
  5850. {
  5851. const float epsilon = 1e-6f;
  5852. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5853. // prepare the data
  5854. var qv = q.value;
  5855. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5856. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  5857. var d3 = qv * qv;
  5858. var euler = Unity.Mathematics.float3.zero;
  5859. var y1 = d2.x + d1.z;
  5860. if (y1 * y1 < cutoff)
  5861. {
  5862. var x1 = -d2.y + d1.x;
  5863. var x2 = d3.y + d3.w - d3.z - d3.x;
  5864. var z1 = -d2.z + d1.y;
  5865. var z2 = d3.x + d3.w - d3.y - d3.z;
  5866. euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2));
  5867. }
  5868. else //xyx
  5869. {
  5870. y1 = clamp(y1, -1f, 1f);
  5871. var abcd = float4(d2.x, d1.z, d2.z, d1.y);
  5872. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  5873. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  5874. euler = float3(atan2(x1, x2), asin(y1), 0f);
  5875. }
  5876. return euler.xzy;
  5877. }
  5878. /// <summary>
  5879. /// Returns the Euler angle representation of the quaternion following the YXZ rotation order.
  5880. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5881. /// </summary>
  5882. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5883. /// <returns>The Euler angle representation of the quaternion in YXZ order.</returns>
  5884. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5885. public static float3 EulerYXZ(quaternion q)
  5886. {
  5887. const float epsilon = 1e-6f;
  5888. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5889. // prepare the data
  5890. var qv = q.value;
  5891. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5892. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  5893. var d3 = qv * qv;
  5894. var euler = Unity.Mathematics.float3.zero;
  5895. var y1 = d2.y + d1.x;
  5896. if (y1 * y1 < cutoff)
  5897. {
  5898. var x1 = -d2.z + d1.y;
  5899. var x2 = d3.z + d3.w - d3.x - d3.y;
  5900. var z1 = -d2.x + d1.z;
  5901. var z2 = d3.y + d3.w - d3.z - d3.x;
  5902. euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2));
  5903. }
  5904. else //yzy
  5905. {
  5906. y1 = clamp(y1, -1f, 1f);
  5907. var abcd = float4(d2.x, d1.z, d2.y, d1.x);
  5908. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  5909. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  5910. euler = float3(atan2(x1, x2), asin(y1), 0f);
  5911. }
  5912. return euler.yxz;
  5913. }
  5914. /// <summary>
  5915. /// Returns the Euler angle representation of the quaternion following the YZX rotation order.
  5916. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5917. /// </summary>
  5918. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5919. /// <returns>The Euler angle representation of the quaternion in YZX order.</returns>
  5920. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5921. public static float3 EulerYZX(quaternion q)
  5922. {
  5923. const float epsilon = 1e-6f;
  5924. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5925. // prepare the data
  5926. var qv = q.value;
  5927. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5928. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  5929. var d3 = qv * qv;
  5930. var euler = Unity.Mathematics.float3.zero;
  5931. var y1 = d2.x - d1.z;
  5932. if (y1 * y1 < cutoff)
  5933. {
  5934. var x1 = d2.z + d1.y;
  5935. var x2 = d3.x + d3.w - d3.z - d3.y;
  5936. var z1 = d2.y + d1.x;
  5937. var z2 = d3.y + d3.w - d3.x - d3.z;
  5938. euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2));
  5939. }
  5940. else //yxy
  5941. {
  5942. y1 = clamp(y1, -1f, 1f);
  5943. var abcd = float4(d2.x, d1.z, d2.y, d1.x);
  5944. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  5945. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  5946. euler = float3(atan2(x1, x2), -asin(y1), 0f);
  5947. }
  5948. return euler.zxy;
  5949. }
  5950. /// <summary>
  5951. /// Returns the Euler angle representation of the quaternion following the ZXY rotation order.
  5952. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5953. /// </summary>
  5954. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5955. /// <returns>The Euler angle representation of the quaternion in ZXY order.</returns>
  5956. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5957. public static float3 EulerZXY(quaternion q)
  5958. {
  5959. const float epsilon = 1e-6f;
  5960. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5961. // prepare the data
  5962. var qv = q.value;
  5963. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5964. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  5965. var d3 = qv * qv;
  5966. var euler = Unity.Mathematics.float3.zero;
  5967. var y1 = d2.y - d1.x;
  5968. if (y1 * y1 < cutoff)
  5969. {
  5970. var x1 = d2.x + d1.z;
  5971. var x2 = d3.y + d3.w - d3.x - d3.z;
  5972. var z1 = d2.z + d1.y;
  5973. var z2 = d3.z + d3.w - d3.x - d3.y;
  5974. euler = float3(atan2(x1, x2), -asin(y1), atan2(z1, z2));
  5975. }
  5976. else //zxz
  5977. {
  5978. y1 = clamp(y1, -1f, 1f);
  5979. var abcd = float4(d2.z, d1.y, d2.y, d1.x);
  5980. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  5981. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  5982. euler = float3(atan2(x1, x2), -asin(y1), 0f);
  5983. }
  5984. return euler.yzx;
  5985. }
  5986. /// <summary>
  5987. /// Returns the Euler angle representation of the quaternion following the ZYX rotation order.
  5988. /// All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
  5989. /// </summary>
  5990. /// <param name="q">The quaternion to convert to Euler angles.</param>
  5991. /// <returns>The Euler angle representation of the quaternion in ZYX order.</returns>
  5992. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  5993. public static float3 EulerZYX(quaternion q)
  5994. {
  5995. const float epsilon = 1e-6f;
  5996. const float cutoff = (1f - 2f * epsilon) * (1f - 2f * epsilon);
  5997. var qv = q.value;
  5998. var d1 = qv * qv.wwww * float4(2f); //xw, yw, zw, ww
  5999. var d2 = qv * qv.yzxw * float4(2f); //xy, yz, zx, ww
  6000. var d3 = qv * qv;
  6001. var euler = Unity.Mathematics.float3.zero;
  6002. var y1 = d2.z + d1.y;
  6003. if (y1 * y1 < cutoff)
  6004. {
  6005. var x1 = -d2.x + d1.z;
  6006. var x2 = d3.x + d3.w - d3.y - d3.z;
  6007. var z1 = -d2.y + d1.x;
  6008. var z2 = d3.z + d3.w - d3.y - d3.x;
  6009. euler = float3(atan2(x1, x2), asin(y1), atan2(z1, z2));
  6010. }
  6011. else //zxz
  6012. {
  6013. y1 = clamp(y1, -1f, 1f);
  6014. var abcd = float4(d2.z, d1.y, d2.y, d1.x);
  6015. var x1 = 2f * (abcd.x * abcd.w + abcd.y * abcd.z); //2(ad+bc)
  6016. var x2 = csum(abcd * abcd * float4(-1f, 1f, -1f, 1f));
  6017. euler = float3(atan2(x1, x2), asin(y1), 0f);
  6018. }
  6019. return euler.zyx;
  6020. }
  6021. /// <summary>
  6022. /// Returns the Euler angle representation of the quaternion. The returned angles depend on the specified order to apply the
  6023. /// three rotations around the principal axes. All rotation angles are in radians and clockwise when looking along the
  6024. /// rotation axis towards the origin.
  6025. /// When the rotation order is known at compile time, to get the best performance you should use the specific
  6026. /// Euler rotation constructors such as EulerZXY(...).
  6027. /// </summary>
  6028. /// <param name="q">The quaternion to convert to Euler angles.</param>
  6029. /// <param name="order">The order in which the rotations are applied.</param>
  6030. /// <returns>The Euler angle representation of the quaternion in the specified order.</returns>
  6031. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6032. public static float3 Euler(quaternion q, math.RotationOrder order = math.RotationOrder.Default)
  6033. {
  6034. switch (order)
  6035. {
  6036. case math.RotationOrder.XYZ:
  6037. return EulerXYZ(q);
  6038. case math.RotationOrder.XZY:
  6039. return EulerXZY(q);
  6040. case math.RotationOrder.YXZ:
  6041. return EulerYXZ(q);
  6042. case math.RotationOrder.YZX:
  6043. return EulerYZX(q);
  6044. case math.RotationOrder.ZXY:
  6045. return EulerZXY(q);
  6046. case math.RotationOrder.ZYX:
  6047. return EulerZYX(q);
  6048. default:
  6049. return Unity.Mathematics.float3.zero;
  6050. }
  6051. }
  6052. /// <summary>
  6053. /// Matrix columns multiplied by scale components
  6054. /// m.c0.x * s.x | m.c1.x * s.y | m.c2.x * s.z
  6055. /// m.c0.y * s.x | m.c1.y * s.y | m.c2.y * s.z
  6056. /// m.c0.z * s.x | m.c1.z * s.y | m.c2.z * s.z
  6057. /// </summary>
  6058. /// <param name="m">Matrix to scale.</param>
  6059. /// <param name="s">Scaling coefficients for each column.</param>
  6060. /// <returns>The scaled matrix.</returns>
  6061. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6062. public static float3x3 mulScale(float3x3 m, float3 s) => new float3x3(m.c0 * s.x, m.c1 * s.y, m.c2 * s.z);
  6063. /// <summary>
  6064. /// Matrix rows multiplied by scale components
  6065. /// m.c0.x * s.x | m.c1.x * s.x | m.c2.x * s.x
  6066. /// m.c0.y * s.y | m.c1.y * s.y | m.c2.y * s.y
  6067. /// m.c0.z * s.z | m.c1.z * s.z | m.c2.z * s.z
  6068. /// </summary>
  6069. /// <param name="s">Scaling coefficients for each row.</param>
  6070. /// <param name="m">Matrix to scale.</param>
  6071. /// <returns>The scaled matrix.</returns>
  6072. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6073. public static float3x3 scaleMul(float3 s, float3x3 m) => new float3x3(m.c0 * s, m.c1 * s, m.c2 * s);
  6074. // Internal
  6075. // SSE shuffles
  6076. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6077. internal static float4 unpacklo(float4 a, float4 b)
  6078. {
  6079. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  6080. }
  6081. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6082. internal static double4 unpacklo(double4 a, double4 b)
  6083. {
  6084. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY);
  6085. }
  6086. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6087. internal static float4 unpackhi(float4 a, float4 b)
  6088. {
  6089. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  6090. }
  6091. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6092. internal static double4 unpackhi(double4 a, double4 b)
  6093. {
  6094. return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW);
  6095. }
  6096. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6097. internal static float4 movelh(float4 a, float4 b)
  6098. {
  6099. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  6100. }
  6101. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6102. internal static double4 movelh(double4 a, double4 b)
  6103. {
  6104. return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY);
  6105. }
  6106. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6107. internal static float4 movehl(float4 a, float4 b)
  6108. {
  6109. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  6110. }
  6111. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6112. internal static double4 movehl(double4 a, double4 b)
  6113. {
  6114. return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW);
  6115. }
  6116. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6117. internal static uint fold_to_uint(double x) // utility for double hashing
  6118. {
  6119. LongDoubleUnion u;
  6120. u.longValue = 0;
  6121. u.doubleValue = x;
  6122. return (uint)(u.longValue >> 32) ^ (uint)u.longValue;
  6123. }
  6124. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6125. internal static uint2 fold_to_uint(double2 x) { return uint2(fold_to_uint(x.x), fold_to_uint(x.y)); }
  6126. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6127. 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)); }
  6128. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  6129. 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)); }
  6130. [StructLayout(LayoutKind.Explicit)]
  6131. internal struct LongDoubleUnion
  6132. {
  6133. [FieldOffset(0)]
  6134. public long longValue;
  6135. [FieldOffset(0)]
  6136. public double doubleValue;
  6137. }
  6138. }
  6139. }