using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; namespace Unity.Mathematics { public static partial class math { /// Extrinsic rotation order. Specifies in which order rotations around the principal axes (x, y and z) are to be applied. public enum RotationOrder : byte { /// Extrinsic rotation around the x axis, then around the y axis and finally around the z axis. XYZ, /// Extrinsic rotation around the x axis, then around the z axis and finally around the y axis. XZY, /// Extrinsic rotation around the y axis, then around the x axis and finally around the z axis. YXZ, /// Extrinsic rotation around the y axis, then around the z axis and finally around the x axis. YZX, /// Extrinsic rotation around the z axis, then around the x axis and finally around the y axis. ZXY, /// Extrinsic rotation around the z axis, then around the y axis and finally around the x axis. ZYX, /// Unity default rotation order. Extrinsic Rotation around the z axis, then around the x axis and finally around the y axis. Default = ZXY }; /// Specifies a shuffle component. public enum ShuffleComponent : byte { /// Specified the x component of the left vector. LeftX, /// Specified the y component of the left vector. LeftY, /// Specified the z component of the left vector. LeftZ, /// Specified the w component of the left vector. LeftW, /// Specified the x component of the right vector. RightX, /// Specified the y component of the right vector. RightY, /// Specified the z component of the right vector. RightZ, /// Specified the w component of the right vector. RightW }; /// The mathematical constant e also known as Euler's number. Approximately 2.72. This is a f64/double precision constant. public const double E_DBL = 2.71828182845904523536; /// The base 2 logarithm of e. Approximately 1.44. This is a f64/double precision constant. public const double LOG2E_DBL = 1.44269504088896340736; /// The base 10 logarithm of e. Approximately 0.43. This is a f64/double precision constant. public const double LOG10E_DBL = 0.434294481903251827651; /// The natural logarithm of 2. Approximately 0.69. This is a f64/double precision constant. public const double LN2_DBL = 0.693147180559945309417; /// The natural logarithm of 10. Approximately 2.30. This is a f64/double precision constant. public const double LN10_DBL = 2.30258509299404568402; /// The mathematical constant pi. Approximately 3.14. This is a f64/double precision constant. public const double PI_DBL = 3.14159265358979323846; /// The square root 2. Approximately 1.41. This is a f64/double precision constant. public const double SQRT2_DBL = 1.41421356237309504880; /// The smallest positive normal number representable in a float. public const float FLT_MIN_NORMAL = 1.175494351e-38F; /// The smallest positive normal number representable in a double. This is a f64/double precision constant. public const double DBL_MIN_NORMAL = 2.2250738585072014e-308; /// The mathematical constant e also known as Euler's number. Approximately 2.72. public const float E = (float)E_DBL; /// The base 2 logarithm of e. Approximately 1.44. public const float LOG2E = (float)LOG2E_DBL; /// The base 10 logarithm of e. Approximately 0.43. public const float LOG10E = (float)LOG10E_DBL; /// The natural logarithm of 2. Approximately 0.69. public const float LN2 = (float)LN2_DBL; /// The natural logarithm of 10. Approximately 2.30. public const float LN10 = (float)LN10_DBL; /// The mathematical constant pi. Approximately 3.14. public const float PI = (float)PI_DBL; /// The square root 2. Approximately 1.41. public const float SQRT2 = (float)SQRT2_DBL; /// Returns the bit pattern of a uint as an int. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int asint(uint x) { return (int)x; } /// Returns the bit pattern of a uint2 as an int2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 asint(uint2 x) { return int2((int)x.x, (int)x.y); } /// Returns the bit pattern of a uint3 as an int3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 asint(uint3 x) { return int3((int)x.x, (int)x.y, (int)x.z); } /// Returns the bit pattern of a uint4 as an int4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 asint(uint4 x) { return int4((int)x.x, (int)x.y, (int)x.z, (int)x.w); } /// Returns the bit pattern of a float as an int. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int asint(float x) { IntFloatUnion u; u.intValue = 0; u.floatValue = x; return u.intValue; } /// Returns the bit pattern of a float2 as an int2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 asint(float2 x) { return int2(asint(x.x), asint(x.y)); } /// Returns the bit pattern of a float3 as an int3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 asint(float3 x) { return int3(asint(x.x), asint(x.y), asint(x.z)); } /// Returns the bit pattern of a float4 as an int4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 asint(float4 x) { return int4(asint(x.x), asint(x.y), asint(x.z), asint(x.w)); } /// Returns the bit pattern of an int as a uint. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint asuint(int x) { return (uint)x; } /// Returns the bit pattern of an int2 as a uint2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 asuint(int2 x) { return uint2((uint)x.x, (uint)x.y); } /// Returns the bit pattern of an int3 as a uint3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 asuint(int3 x) { return uint3((uint)x.x, (uint)x.y, (uint)x.z); } /// Returns the bit pattern of an int4 as a uint4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 asuint(int4 x) { return uint4((uint)x.x, (uint)x.y, (uint)x.z, (uint)x.w); } /// Returns the bit pattern of a float as a uint. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint asuint(float x) { return (uint)asint(x); } /// Returns the bit pattern of a float2 as a uint2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 asuint(float2 x) { return uint2(asuint(x.x), asuint(x.y)); } /// Returns the bit pattern of a float3 as a uint3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 asuint(float3 x) { return uint3(asuint(x.x), asuint(x.y), asuint(x.z)); } /// Returns the bit pattern of a float4 as a uint4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 asuint(float4 x) { return uint4(asuint(x.x), asuint(x.y), asuint(x.z), asuint(x.w)); } /// Returns the bit pattern of a ulong as a long. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long aslong(ulong x) { return (long)x; } /// Returns the bit pattern of a double as a long. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long aslong(double x) { LongDoubleUnion u; u.longValue = 0; u.doubleValue = x; return u.longValue; } /// Returns the bit pattern of a long as a ulong. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong asulong(long x) { return (ulong)x; } /// Returns the bit pattern of a double as a ulong. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong asulong(double x) { return (ulong) aslong(x); } /// Returns the bit pattern of an int as a float. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float asfloat(int x) { IntFloatUnion u; u.floatValue = 0; u.intValue = x; return u.floatValue; } /// Returns the bit pattern of an int2 as a float2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 asfloat(int2 x) { return float2(asfloat(x.x), asfloat(x.y)); } /// Returns the bit pattern of an int3 as a float3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 asfloat(int3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); } /// Returns the bit pattern of an int4 as a float4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 asfloat(int4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); } /// Returns the bit pattern of a uint as a float. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float asfloat(uint x) { return asfloat((int)x); } /// Returns the bit pattern of a uint2 as a float2. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 asfloat(uint2 x) { return float2(asfloat(x.x), asfloat(x.y)); } /// Returns the bit pattern of a uint3 as a float3. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 asfloat(uint3 x) { return float3(asfloat(x.x), asfloat(x.y), asfloat(x.z)); } /// Returns the bit pattern of a uint4 as a float4. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 asfloat(uint4 x) { return float4(asfloat(x.x), asfloat(x.y), asfloat(x.z), asfloat(x.w)); } /// /// Returns a bitmask representation of a bool4. Storing one 1 bit per component /// in LSB order, from lower to higher bits (so 4 bits in total). /// The component x is stored at bit 0, /// The component y is stored at bit 1, /// The component z is stored at bit 2, /// The component w is stored at bit 3 /// The bool4(x = true, y = true, z = false, w = true) would produce the value 1011 = 0xB /// /// The input bool4 to calculate the bitmask for /// A bitmask representation of the bool4, in LSB order public static int bitmask(bool4 value) { int mask = 0; if (value.x) mask |= 0x01; if (value.y) mask |= 0x02; if (value.z) mask |= 0x04; if (value.w) mask |= 0x08; return mask; } /// Returns the bit pattern of a long as a double. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double asdouble(long x) { LongDoubleUnion u; u.doubleValue = 0; u.longValue = x; return u.doubleValue; } /// Returns the bit pattern of a ulong as a double. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double asdouble(ulong x) { return asdouble((long)x); } /// Returns true if the input float is a finite floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isfinite(float x) { return abs(x) < float.PositiveInfinity; } /// Returns a bool2 indicating for each component of a float2 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isfinite(float2 x) { return abs(x) < float.PositiveInfinity; } /// Returns a bool3 indicating for each component of a float3 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isfinite(float3 x) { return abs(x) < float.PositiveInfinity; } /// Returns a bool4 indicating for each component of a float4 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isfinite(float4 x) { return abs(x) < float.PositiveInfinity; } /// Returns true if the input double is a finite floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isfinite(double x) { return abs(x) < double.PositiveInfinity; } /// Returns a bool2 indicating for each component of a double2 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isfinite(double2 x) { return abs(x) < double.PositiveInfinity; } /// Returns a bool3 indicating for each component of a double3 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isfinite(double3 x) { return abs(x) < double.PositiveInfinity; } /// Returns a bool4 indicating for each component of a double4 whether it is a finite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isfinite(double4 x) { return abs(x) < double.PositiveInfinity; } /// Returns true if the input float is an infinite floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isinf(float x) { return abs(x) == float.PositiveInfinity; } /// Returns a bool2 indicating for each component of a float2 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isinf(float2 x) { return abs(x) == float.PositiveInfinity; } /// Returns a bool3 indicating for each component of a float3 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isinf(float3 x) { return abs(x) == float.PositiveInfinity; } /// Returns a bool4 indicating for each component of a float4 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isinf(float4 x) { return abs(x) == float.PositiveInfinity; } /// Returns true if the input double is an infinite floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isinf(double x) { return abs(x) == double.PositiveInfinity; } /// Returns a bool2 indicating for each component of a double2 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isinf(double2 x) { return abs(x) == double.PositiveInfinity; } /// Returns a bool3 indicating for each component of a double3 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isinf(double3 x) { return abs(x) == double.PositiveInfinity; } /// Returns a bool4 indicating for each component of a double4 whether it is an infinite floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isinf(double4 x) { return abs(x) == double.PositiveInfinity; } /// Returns true if the input float is a NaN (not a number) floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isnan(float x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; } /// Returns a bool2 indicating for each component of a float2 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isnan(float2 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; } /// Returns a bool3 indicating for each component of a float3 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isnan(float3 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; } /// Returns a bool4 indicating for each component of a float4 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isnan(float4 x) { return (asuint(x) & 0x7FFFFFFF) > 0x7F800000; } /// Returns true if the input double is a NaN (not a number) floating point value, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool isnan(double x) { return (asulong(x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000; } /// Returns a bool2 indicating for each component of a double2 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool2 isnan(double2 x) { return bool2((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000); } /// Returns a bool3 indicating for each component of a double3 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool3 isnan(double3 x) { return bool3((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000); } /// Returns a bool4 indicating for each component of a double4 whether it is a NaN (not a number) floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool4 isnan(double4 x) { return bool4((asulong(x.x) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.y) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.z) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000, (asulong(x.w) & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000); } /// Returns the minimum of two int values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int min(int x, int y) { return x < y ? x : y; } /// Returns the componentwise minimum of two int2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 min(int2 x, int2 y) { return new int2(min(x.x, y.x), min(x.y, y.y)); } /// Returns the componentwise minimum of two int3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise minimum of two int4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the minimum of two uint values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint min(uint x, uint y) { return x < y ? x : y; } /// Returns the componentwise minimum of two uint2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 min(uint2 x, uint2 y) { return new uint2(min(x.x, y.x), min(x.y, y.y)); } /// Returns the componentwise minimum of two uint3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise minimum of two uint4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the minimum of two long values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long min(long x, long y) { return x < y ? x : y; } /// Returns the minimum of two ulong values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong min(ulong x, ulong y) { return x < y ? x : y; } /// Returns the minimum of two float values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float min(float x, float y) { return float.IsNaN(y) || x < y ? x : y; } /// Returns the componentwise minimum of two float2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 min(float2 x, float2 y) { return new float2(min(x.x, y.x), min(x.y, y.y)); } /// Returns the componentwise minimum of two float3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise minimum of two float4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the minimum of two double values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double min(double x, double y) { return double.IsNaN(y) || x < y ? x : y; } /// Returns the componentwise minimum of two double2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 min(double2 x, double2 y) { return new double2(min(x.x, y.x), min(x.y, y.y)); } /// Returns the componentwise minimum of two double3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise minimum of two double4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the maximum of two int values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int max(int x, int y) { return x > y ? x : y; } /// Returns the componentwise maximum of two int2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 max(int2 x, int2 y) { return new int2(max(x.x, y.x), max(x.y, y.y)); } /// Returns the componentwise maximum of two int3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise maximum of two int4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the maximum of two uint values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint max(uint x, uint y) { return x > y ? x : y; } /// Returns the componentwise maximum of two uint2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 max(uint2 x, uint2 y) { return new uint2(max(x.x, y.x), max(x.y, y.y)); } /// Returns the componentwise maximum of two uint3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise maximum of two uint4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the maximum of two long values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long max(long x, long y) { return x > y ? x : y; } /// Returns the maximum of two ulong values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong max(ulong x, ulong y) { return x > y ? x : y; } /// Returns the maximum of two float values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float max(float x, float y) { return float.IsNaN(y) || x > y ? x : y; } /// Returns the componentwise maximum of two float2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 max(float2 x, float2 y) { return new float2(max(x.x, y.x), max(x.y, y.y)); } /// Returns the componentwise maximum of two float3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise maximum of two float4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the maximum of two double values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double max(double x, double y) { return double.IsNaN(y) || x > y ? x : y; } /// Returns the componentwise maximum of two double2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 max(double2 x, double2 y) { return new double2(max(x.x, y.x), max(x.y, y.y)); } /// Returns the componentwise maximum of two double3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the componentwise maximum of two double4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the result of linearly interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float lerp(float x, float y, float s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 lerp(float2 x, float2 y, float s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 lerp(float3 x, float3 y, float s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 lerp(float4 x, float4 y, float s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 lerp(float2 x, float2 y, float2 s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 lerp(float3 x, float3 y, float3 s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 lerp(float4 x, float4 y, float4 s) { return x + s * (y - x); } /// Returns the result of linearly interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double lerp(double x, double y, double s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 lerp(double2 x, double2 y, double s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 lerp(double3 x, double3 y, double s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 lerp(double4 x, double4 y, double s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 lerp(double2 x, double2 y, double2 s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 lerp(double3 x, double3 y, double3 s) { return x + s * (y - x); } /// Returns the result of a componentwise linear interpolating from x to y using the corresponding components of the interpolation parameter s. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 lerp(double4 x, double4 y, double4 s) { return x + s * (y - x); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float unlerp(float a, float b, float x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 unlerp(float2 a, float2 b, float2 x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 unlerp(float3 a, float3 b, float3 x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 unlerp(float4 a, float4 b, float4 x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double unlerp(double a, double b, double x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 unlerp(double2 a, double2 b, double2 x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 unlerp(double3 a, double3 b, double3 x) { return (x - a) / (b - a); } /// 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). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 unlerp(double4 a, double4 b, double4 x) { return (x - a) / (b - a); } /// Returns the result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float remap(float a, float b, float c, float d, float x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 remap(float2 a, float2 b, float2 c, float2 d, float2 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 remap(float3 a, float3 b, float3 c, float3 d, float3 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 remap(float4 a, float4 b, float4 c, float4 d, float4 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double remap(double a, double b, double c, double d, double x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 remap(double2 a, double2 b, double2 c, double2 d, double2 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 remap(double3 a, double3 b, double3 c, double3 d, double3 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the componentwise result of a non-clamping linear remapping of a value x from [a, b] to [c, d]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 remap(double4 a, double4 b, double4 c, double4 d, double4 x) { return lerp(c, d, unlerp(a, b, x)); } /// Returns the result of a multiply-add operation (a * b + c) on 3 int values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int mad(int a, int b, int c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 mad(int2 a, int2 b, int2 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 mad(int3 a, int3 b, int3 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 int4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 mad(int4 a, int4 b, int4 c) { return a * b + c; } /// Returns the result of a multiply-add operation (a * b + c) on 3 uint values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint mad(uint a, uint b, uint c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 mad(uint2 a, uint2 b, uint2 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 mad(uint3 a, uint3 b, uint3 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 uint4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 mad(uint4 a, uint4 b, uint4 c) { return a * b + c; } /// Returns the result of a multiply-add operation (a * b + c) on 3 long values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long mad(long a, long b, long c) { return a * b + c; } /// Returns the result of a multiply-add operation (a * b + c) on 3 ulong values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong mad(ulong a, ulong b, ulong c) { return a * b + c; } /// Returns the result of a multiply-add operation (a * b + c) on 3 float values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float mad(float a, float b, float c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 mad(float2 a, float2 b, float2 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 mad(float3 a, float3 b, float3 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 float4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 mad(float4 a, float4 b, float4 c) { return a * b + c; } /// Returns the result of a multiply-add operation (a * b + c) on 3 double values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double mad(double a, double b, double c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 mad(double2 a, double2 b, double2 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 mad(double3 a, double3 b, double3 c) { return a * b + c; } /// Returns the result of a componentwise multiply-add operation (a * b + c) on 3 double4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 mad(double4 a, double4 b, double4 c) { return a * b + c; } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are int values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int clamp(int x, int a, int b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the int2 x into the interval [a, b], where a and b are int2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 clamp(int2 x, int2 a, int2 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the int3 x into the interval [a, b], where x, a and b are int3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 clamp(int3 x, int3 a, int3 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are int4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 clamp(int4 x, int4 a, int4 b) { return max(a, min(b, x)); } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are uint values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint clamp(uint x, uint a, uint b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 clamp(uint2 x, uint2 a, uint2 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 clamp(uint3 x, uint3 a, uint3 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are uint4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 clamp(uint4 x, uint4 a, uint4 b) { return max(a, min(b, x)); } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are long values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long clamp(long x, long a, long b) { return max(a, min(b, x)); } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are ulong values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong clamp(ulong x, ulong a, ulong b) { return max(a, min(b, x)); } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are float values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float clamp(float x, float a, float b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 clamp(float2 x, float2 a, float2 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 clamp(float3 x, float3 a, float3 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are float4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 clamp(float4 x, float4 a, float4 b) { return max(a, min(b, x)); } /// Returns the result of clamping the value x into the interval [a, b], where x, a and b are double values. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double clamp(double x, double a, double b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 clamp(double2 x, double2 a, double2 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 clamp(double3 x, double3 a, double3 b) { return max(a, min(b, x)); } /// Returns the result of a componentwise clamping of the value x into the interval [a, b], where x, a and b are double4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 clamp(double4 x, double4 a, double4 b) { return max(a, min(b, x)); } /// Returns the result of clamping the float value x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float saturate(float x) { return clamp(x, 0.0f, 1.0f); } /// Returns the result of a componentwise clamping of the float2 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 saturate(float2 x) { return clamp(x, new float2(0.0f), new float2(1.0f)); } /// Returns the result of a componentwise clamping of the float3 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 saturate(float3 x) { return clamp(x, new float3(0.0f), new float3(1.0f)); } /// Returns the result of a componentwise clamping of the float4 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 saturate(float4 x) { return clamp(x, new float4(0.0f), new float4(1.0f)); } /// Returns the result of clamping the double value x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double saturate(double x) { return clamp(x, 0.0, 1.0); } /// Returns the result of a componentwise clamping of the double2 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 saturate(double2 x) { return clamp(x, new double2(0.0), new double2(1.0)); } /// Returns the result of a componentwise clamping of the double3 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 saturate(double3 x) { return clamp(x, new double3(0.0), new double3(1.0)); } /// Returns the result of a componentwise clamping of the double4 vector x into the interval [0, 1]. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 saturate(double4 x) { return clamp(x, new double4(0.0), new double4(1.0)); } /// Returns the absolute value of a int value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int abs(int x) { return max(-x, x); } /// Returns the componentwise absolute value of a int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 abs(int2 x) { return max(-x, x); } /// Returns the componentwise absolute value of a int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 abs(int3 x) { return max(-x, x); } /// Returns the componentwise absolute value of a int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 abs(int4 x) { return max(-x, x); } /// Returns the absolute value of a long value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long abs(long x) { return max(-x, x); } /// Returns the absolute value of a float value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float abs(float x) { return asfloat(asuint(x) & 0x7FFFFFFF); } /// Returns the componentwise absolute value of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 abs(float2 x) { return asfloat(asuint(x) & 0x7FFFFFFF); } /// Returns the componentwise absolute value of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 abs(float3 x) { return asfloat(asuint(x) & 0x7FFFFFFF); } /// Returns the componentwise absolute value of a float4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 abs(float4 x) { return asfloat(asuint(x) & 0x7FFFFFFF); } /// Returns the absolute value of a double value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double abs(double x) { return asdouble(asulong(x) & 0x7FFFFFFFFFFFFFFF); } /// Returns the componentwise absolute value of a double2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 abs(double2 x) { return double2(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF)); } /// Returns the componentwise absolute value of a double3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 abs(double3 x) { return double3(asdouble(asulong(x.x) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.y) & 0x7FFFFFFFFFFFFFFF), asdouble(asulong(x.z) & 0x7FFFFFFFFFFFFFFF)); } /// Returns the componentwise absolute value of a double4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } /// Returns the dot product of two int values. Equivalent to multiplication. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int dot(int x, int y) { return x * y; } /// Returns the dot product of two int2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int dot(int2 x, int2 y) { return x.x * y.x + x.y * y.y; } /// Returns the dot product of two int3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int dot(int3 x, int3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; } /// Returns the dot product of two int4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } /// Returns the dot product of two uint values. Equivalent to multiplication. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint dot(uint x, uint y) { return x * y; } /// Returns the dot product of two uint2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint dot(uint2 x, uint2 y) { return x.x * y.x + x.y * y.y; } /// Returns the dot product of two uint3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint dot(uint3 x, uint3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; } /// Returns the dot product of two uint4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } /// Returns the dot product of two float values. Equivalent to multiplication. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float dot(float x, float y) { return x * y; } /// Returns the dot product of two float2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float dot(float2 x, float2 y) { return x.x * y.x + x.y * y.y; } /// Returns the dot product of two float3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float dot(float3 x, float3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; } /// Returns the dot product of two float4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } /// Returns the dot product of two double values. Equivalent to multiplication. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double dot(double x, double y) { return x * y; } /// Returns the dot product of two double2 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double dot(double2 x, double2 y) { return x.x * y.x + x.y * y.y; } /// Returns the dot product of two double3 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double dot(double3 x, double3 y) { return x.x * y.x + x.y * y.y + x.z * y.z; } /// Returns the dot product of two double4 vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } /// Returns the tangent of a float value. public static float tan(float x) { return (float)System.Math.Tan(x); } /// Returns the componentwise tangent of a float2 vector. public static float2 tan(float2 x) { return new float2(tan(x.x), tan(x.y)); } /// Returns the componentwise tangent of a float3 vector. public static float3 tan(float3 x) { return new float3(tan(x.x), tan(x.y), tan(x.z)); } /// Returns the componentwise tangent of a float4 vector. public static float4 tan(float4 x) { return new float4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); } /// Returns the tangent of a double value. public static double tan(double x) { return System.Math.Tan(x); } /// Returns the componentwise tangent of a double2 vector. public static double2 tan(double2 x) { return new double2(tan(x.x), tan(x.y)); } /// Returns the componentwise tangent of a double3 vector. public static double3 tan(double3 x) { return new double3(tan(x.x), tan(x.y), tan(x.z)); } /// Returns the componentwise tangent of a double4 vector. public static double4 tan(double4 x) { return new double4(tan(x.x), tan(x.y), tan(x.z), tan(x.w)); } /// Returns the hyperbolic tangent of a float value. public static float tanh(float x) { return (float)System.Math.Tanh(x); } /// Returns the componentwise hyperbolic tangent of a float2 vector. public static float2 tanh(float2 x) { return new float2(tanh(x.x), tanh(x.y)); } /// Returns the componentwise hyperbolic tangent of a float3 vector. public static float3 tanh(float3 x) { return new float3(tanh(x.x), tanh(x.y), tanh(x.z)); } /// Returns the componentwise hyperbolic tangent of a float4 vector. public static float4 tanh(float4 x) { return new float4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); } /// Returns the hyperbolic tangent of a double value. public static double tanh(double x) { return System.Math.Tanh(x); } /// Returns the componentwise hyperbolic tangent of a double2 vector. public static double2 tanh(double2 x) { return new double2(tanh(x.x), tanh(x.y)); } /// Returns the componentwise hyperbolic tangent of a double3 vector. public static double3 tanh(double3 x) { return new double3(tanh(x.x), tanh(x.y), tanh(x.z)); } /// Returns the componentwise hyperbolic tangent of a double4 vector. public static double4 tanh(double4 x) { return new double4(tanh(x.x), tanh(x.y), tanh(x.z), tanh(x.w)); } /// Returns the arctangent of a float value. public static float atan(float x) { return (float)System.Math.Atan(x); } /// Returns the componentwise arctangent of a float2 vector. public static float2 atan(float2 x) { return new float2(atan(x.x), atan(x.y)); } /// Returns the componentwise arctangent of a float3 vector. public static float3 atan(float3 x) { return new float3(atan(x.x), atan(x.y), atan(x.z)); } /// Returns the componentwise arctangent of a float4 vector. public static float4 atan(float4 x) { return new float4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); } /// Returns the arctangent of a double value. public static double atan(double x) { return System.Math.Atan(x); } /// Returns the componentwise arctangent of a double2 vector. public static double2 atan(double2 x) { return new double2(atan(x.x), atan(x.y)); } /// Returns the componentwise arctangent of a double3 vector. public static double3 atan(double3 x) { return new double3(atan(x.x), atan(x.y), atan(x.z)); } /// Returns the componentwise arctangent of a double4 vector. public static double4 atan(double4 x) { return new double4(atan(x.x), atan(x.y), atan(x.z), atan(x.w)); } /// Returns the 2-argument arctangent of a pair of float values. public static float atan2(float y, float x) { return (float)System.Math.Atan2(y, x); } /// Returns the componentwise 2-argument arctangent of a pair of floats2 vectors. public static float2 atan2(float2 y, float2 x) { return new float2(atan2(y.x, x.x), atan2(y.y, x.y)); } /// Returns the componentwise 2-argument arctangent of a pair of floats3 vectors. 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)); } /// Returns the componentwise 2-argument arctangent of a pair of floats4 vectors. 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)); } /// Returns the 2-argument arctangent of a pair of double values. public static double atan2(double y, double x) { return System.Math.Atan2(y, x); } /// Returns the 2-argument arctangent of a pair of double2 vectors. public static double2 atan2(double2 y, double2 x) { return new double2(atan2(y.x, x.x), atan2(y.y, x.y)); } /// Returns the 2-argument arctangent of a pair of double3 vectors. 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)); } /// Returns the 2-argument arctangent of a pair of double4 vectors. 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)); } /// Returns the cosine of a float value. public static float cos(float x) { return (float)System.Math.Cos(x); } /// Returns the componentwise cosine of a float2 vector. public static float2 cos(float2 x) { return new float2(cos(x.x), cos(x.y)); } /// Returns the componentwise cosine of a float3 vector. public static float3 cos(float3 x) { return new float3(cos(x.x), cos(x.y), cos(x.z)); } /// Returns the componentwise cosine of a float4 vector. public static float4 cos(float4 x) { return new float4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); } /// Returns the cosine of a double value. public static double cos(double x) { return System.Math.Cos(x); } /// Returns the componentwise cosine of a double2 vector. public static double2 cos(double2 x) { return new double2(cos(x.x), cos(x.y)); } /// Returns the componentwise cosine of a double3 vector. public static double3 cos(double3 x) { return new double3(cos(x.x), cos(x.y), cos(x.z)); } /// Returns the componentwise cosine of a double4 vector. public static double4 cos(double4 x) { return new double4(cos(x.x), cos(x.y), cos(x.z), cos(x.w)); } /// Returns the hyperbolic cosine of a float value. public static float cosh(float x) { return (float)System.Math.Cosh(x); } /// Returns the componentwise hyperbolic cosine of a float2 vector. public static float2 cosh(float2 x) { return new float2(cosh(x.x), cosh(x.y)); } /// Returns the componentwise hyperbolic cosine of a float3 vector. public static float3 cosh(float3 x) { return new float3(cosh(x.x), cosh(x.y), cosh(x.z)); } /// Returns the componentwise hyperbolic cosine of a float4 vector. public static float4 cosh(float4 x) { return new float4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); } /// Returns the hyperbolic cosine of a double value. public static double cosh(double x) { return System.Math.Cosh(x); } /// Returns the componentwise hyperbolic cosine of a double2 vector. public static double2 cosh(double2 x) { return new double2(cosh(x.x), cosh(x.y)); } /// Returns the componentwise hyperbolic cosine of a double3 vector. public static double3 cosh(double3 x) { return new double3(cosh(x.x), cosh(x.y), cosh(x.z)); } /// Returns the componentwise hyperbolic cosine of a double4 vector. public static double4 cosh(double4 x) { return new double4(cosh(x.x), cosh(x.y), cosh(x.z), cosh(x.w)); } /// Returns the arccosine of a float value. public static float acos(float x) { return (float)System.Math.Acos((float)x); } /// Returns the componentwise arccosine of a float2 vector. public static float2 acos(float2 x) { return new float2(acos(x.x), acos(x.y)); } /// Returns the componentwise arccosine of a float3 vector. public static float3 acos(float3 x) { return new float3(acos(x.x), acos(x.y), acos(x.z)); } /// Returns the componentwise arccosine of a float4 vector. public static float4 acos(float4 x) { return new float4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); } /// Returns the arccosine of a double value. public static double acos(double x) { return System.Math.Acos(x); } /// Returns the componentwise arccosine of a double2 vector. public static double2 acos(double2 x) { return new double2(acos(x.x), acos(x.y)); } /// Returns the componentwise arccosine of a double3 vector. public static double3 acos(double3 x) { return new double3(acos(x.x), acos(x.y), acos(x.z)); } /// Returns the componentwise arccosine of a double4 vector. public static double4 acos(double4 x) { return new double4(acos(x.x), acos(x.y), acos(x.z), acos(x.w)); } /// Returns the sine of a float value. public static float sin(float x) { return (float)System.Math.Sin((float)x); } /// Returns the componentwise sine of a float2 vector. public static float2 sin(float2 x) { return new float2(sin(x.x), sin(x.y)); } /// Returns the componentwise sine of a float3 vector. public static float3 sin(float3 x) { return new float3(sin(x.x), sin(x.y), sin(x.z)); } /// Returns the componentwise sine of a float4 vector. public static float4 sin(float4 x) { return new float4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); } /// Returns the sine of a double value. public static double sin(double x) { return System.Math.Sin(x); } /// Returns the componentwise sine of a double2 vector. public static double2 sin(double2 x) { return new double2(sin(x.x), sin(x.y)); } /// Returns the componentwise sine of a double3 vector. public static double3 sin(double3 x) { return new double3(sin(x.x), sin(x.y), sin(x.z)); } /// Returns the componentwise sine of a double4 vector. public static double4 sin(double4 x) { return new double4(sin(x.x), sin(x.y), sin(x.z), sin(x.w)); } /// Returns the hyperbolic sine of a float value. public static float sinh(float x) { return (float)System.Math.Sinh((float)x); } /// Returns the componentwise hyperbolic sine of a float2 vector. public static float2 sinh(float2 x) { return new float2(sinh(x.x), sinh(x.y)); } /// Returns the componentwise hyperbolic sine of a float3 vector. public static float3 sinh(float3 x) { return new float3(sinh(x.x), sinh(x.y), sinh(x.z)); } /// Returns the componentwise hyperbolic sine of a float4 vector. public static float4 sinh(float4 x) { return new float4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); } /// Returns the hyperbolic sine of a double value. public static double sinh(double x) { return System.Math.Sinh(x); } /// Returns the componentwise hyperbolic sine of a double2 vector. public static double2 sinh(double2 x) { return new double2(sinh(x.x), sinh(x.y)); } /// Returns the componentwise hyperbolic sine of a double3 vector. public static double3 sinh(double3 x) { return new double3(sinh(x.x), sinh(x.y), sinh(x.z)); } /// Returns the componentwise hyperbolic sine of a double4 vector. public static double4 sinh(double4 x) { return new double4(sinh(x.x), sinh(x.y), sinh(x.z), sinh(x.w)); } /// Returns the arcsine of a float value. public static float asin(float x) { return (float)System.Math.Asin((float)x); } /// Returns the componentwise arcsine of a float2 vector. public static float2 asin(float2 x) { return new float2(asin(x.x), asin(x.y)); } /// Returns the componentwise arcsine of a float3 vector. public static float3 asin(float3 x) { return new float3(asin(x.x), asin(x.y), asin(x.z)); } /// Returns the componentwise arcsine of a float4 vector. public static float4 asin(float4 x) { return new float4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); } /// Returns the arcsine of a double value. public static double asin(double x) { return System.Math.Asin(x); } /// Returns the componentwise arcsine of a double2 vector. public static double2 asin(double2 x) { return new double2(asin(x.x), asin(x.y)); } /// Returns the componentwise arcsine of a double3 vector. public static double3 asin(double3 x) { return new double3(asin(x.x), asin(x.y), asin(x.z)); } /// Returns the componentwise arcsine of a double4 vector. public static double4 asin(double4 x) { return new double4(asin(x.x), asin(x.y), asin(x.z), asin(x.w)); } /// Returns the result of rounding a float value up to the nearest integral value less or equal to the original value. public static float floor(float x) { return (float)System.Math.Floor((float)x); } /// Returns the result of rounding each component of a float2 vector value down to the nearest value less or equal to the original value. public static float2 floor(float2 x) { return new float2(floor(x.x), floor(x.y)); } /// Returns the result of rounding each component of a float3 vector value down to the nearest value less or equal to the original value. public static float3 floor(float3 x) { return new float3(floor(x.x), floor(x.y), floor(x.z)); } /// Returns the result of rounding each component of a float4 vector value down to the nearest value less or equal to the original value. public static float4 floor(float4 x) { return new float4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); } /// Returns the result of rounding a double value up to the nearest integral value less or equal to the original value. public static double floor(double x) { return System.Math.Floor(x); } /// Returns the result of rounding each component of a double2 vector value down to the nearest value less or equal to the original value. public static double2 floor(double2 x) { return new double2(floor(x.x), floor(x.y)); } /// Returns the result of rounding each component of a double3 vector value down to the nearest value less or equal to the original value. public static double3 floor(double3 x) { return new double3(floor(x.x), floor(x.y), floor(x.z)); } /// Returns the result of rounding each component of a double4 vector value down to the nearest value less or equal to the original value. public static double4 floor(double4 x) { return new double4(floor(x.x), floor(x.y), floor(x.z), floor(x.w)); } /// Returns the result of rounding a float value up to the nearest integral value greater or equal to the original value. public static float ceil(float x) { return (float)System.Math.Ceiling((float)x); } /// Returns the result of rounding each component of a float2 vector value up to the nearest value greater or equal to the original value. public static float2 ceil(float2 x) { return new float2(ceil(x.x), ceil(x.y)); } /// Returns the result of rounding each component of a float3 vector value up to the nearest value greater or equal to the original value. public static float3 ceil(float3 x) { return new float3(ceil(x.x), ceil(x.y), ceil(x.z)); } /// Returns the result of rounding each component of a float4 vector value up to the nearest value greater or equal to the original value. public static float4 ceil(float4 x) { return new float4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); } /// Returns the result of rounding a double value up to the nearest greater integral value greater or equal to the original value. public static double ceil(double x) { return System.Math.Ceiling(x); } /// 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. public static double2 ceil(double2 x) { return new double2(ceil(x.x), ceil(x.y)); } /// 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.. public static double3 ceil(double3 x) { return new double3(ceil(x.x), ceil(x.y), ceil(x.z)); } /// 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. public static double4 ceil(double4 x) { return new double4(ceil(x.x), ceil(x.y), ceil(x.z), ceil(x.w)); } /// Returns the result of rounding a float value to the nearest integral value. public static float round(float x) { return (float)System.Math.Round((float)x); } /// Returns the result of rounding each component of a float2 vector value to the nearest integral value. public static float2 round(float2 x) { return new float2(round(x.x), round(x.y)); } /// Returns the result of rounding each component of a float3 vector value to the nearest integral value. public static float3 round(float3 x) { return new float3(round(x.x), round(x.y), round(x.z)); } /// Returns the result of rounding each component of a float4 vector value to the nearest integral value. public static float4 round(float4 x) { return new float4(round(x.x), round(x.y), round(x.z), round(x.w)); } /// Returns the result of rounding a double value to the nearest integral value. public static double round(double x) { return System.Math.Round(x); } /// Returns the result of rounding each component of a double2 vector value to the nearest integral value. public static double2 round(double2 x) { return new double2(round(x.x), round(x.y)); } /// Returns the result of rounding each component of a double3 vector value to the nearest integral value. public static double3 round(double3 x) { return new double3(round(x.x), round(x.y), round(x.z)); } /// Returns the result of rounding each component of a double4 vector value to the nearest integral value. public static double4 round(double4 x) { return new double4(round(x.x), round(x.y), round(x.z), round(x.w)); } /// Returns the result of truncating a float value to an integral float value. public static float trunc(float x) { return (float)System.Math.Truncate((float)x); } /// Returns the result of a componentwise truncation of a float2 value to an integral float2 value. public static float2 trunc(float2 x) { return new float2(trunc(x.x), trunc(x.y)); } /// Returns the result of a componentwise truncation of a float3 value to an integral float3 value. public static float3 trunc(float3 x) { return new float3(trunc(x.x), trunc(x.y), trunc(x.z)); } /// Returns the result of a componentwise truncation of a float4 value to an integral float4 value. public static float4 trunc(float4 x) { return new float4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); } /// Returns the result of truncating a double value to an integral double value. public static double trunc(double x) { return System.Math.Truncate(x); } /// Returns the result of a componentwise truncation of a double2 value to an integral double2 value. public static double2 trunc(double2 x) { return new double2(trunc(x.x), trunc(x.y)); } /// Returns the result of a componentwise truncation of a double3 value to an integral double3 value. public static double3 trunc(double3 x) { return new double3(trunc(x.x), trunc(x.y), trunc(x.z)); } /// Returns the result of a componentwise truncation of a double4 value to an integral double4 value. public static double4 trunc(double4 x) { return new double4(trunc(x.x), trunc(x.y), trunc(x.z), trunc(x.w)); } /// Returns the fractional part of a float value. public static float frac(float x) { return x - floor(x); } /// Returns the componentwise fractional parts of a float2 vector. public static float2 frac(float2 x) { return x - floor(x); } /// Returns the componentwise fractional parts of a float3 vector. public static float3 frac(float3 x) { return x - floor(x); } /// Returns the componentwise fractional parts of a float4 vector. public static float4 frac(float4 x) { return x - floor(x); } /// Returns the fractional part of a double value. public static double frac(double x) { return x - floor(x); } /// Returns the componentwise fractional parts of a double2 vector. public static double2 frac(double2 x) { return x - floor(x); } /// Returns the componentwise fractional parts of a double3 vector. public static double3 frac(double3 x) { return x - floor(x); } /// Returns the componentwise fractional parts of a double4 vector. public static double4 frac(double4 x) { return x - floor(x); } /// Returns the reciprocal a float value. public static float rcp(float x) { return 1.0f / x; } /// Returns the componentwise reciprocal a float2 vector. public static float2 rcp(float2 x) { return 1.0f / x; } /// Returns the componentwise reciprocal a float3 vector. public static float3 rcp(float3 x) { return 1.0f / x; } /// Returns the componentwise reciprocal a float4 vector. public static float4 rcp(float4 x) { return 1.0f / x; } /// Returns the reciprocal a double value. public static double rcp(double x) { return 1.0 / x; } /// Returns the componentwise reciprocal a double2 vector. public static double2 rcp(double2 x) { return 1.0 / x; } /// Returns the componentwise reciprocal a double3 vector. public static double3 rcp(double3 x) { return 1.0 / x; } /// Returns the componentwise reciprocal a double4 vector. public static double4 rcp(double4 x) { return 1.0 / x; } /// 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. public static float sign(float x) { return (x > 0.0f ? 1.0f : 0.0f) - (x < 0.0f ? 1.0f : 0.0f); } /// Returns the componentwise sign of a float2 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components. public static float2 sign(float2 x) { return new float2(sign(x.x), sign(x.y)); } /// Returns the componentwise sign of a float3 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components. public static float3 sign(float3 x) { return new float3(sign(x.x), sign(x.y), sign(x.z)); } /// Returns the componentwise sign of a float4 value. 1.0f for positive components, 0.0f for zero components and -1.0f for negative components. public static float4 sign(float4 x) { return new float4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); } /// 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. public static double sign(double x) { return x == 0 ? 0 : (x > 0.0 ? 1.0 : 0.0) - (x < 0.0 ? 1.0 : 0.0); } /// Returns the componentwise sign of a double2 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components. public static double2 sign(double2 x) { return new double2(sign(x.x), sign(x.y)); } /// Returns the componentwise sign of a double3 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components. public static double3 sign(double3 x) { return new double3(sign(x.x), sign(x.y), sign(x.z)); } /// Returns the componentwise sign of a double4 value. 1.0 for positive components, 0.0 for zero components and -1.0 for negative components. public static double4 sign(double4 x) { return new double4(sign(x.x), sign(x.y), sign(x.z), sign(x.w)); } /// Returns x raised to the power y. public static float pow(float x, float y) { return (float)System.Math.Pow((float)x, (float)y); } /// Returns the componentwise result of raising x to the power y. public static float2 pow(float2 x, float2 y) { return new float2(pow(x.x, y.x), pow(x.y, y.y)); } /// Returns the componentwise result of raising x to the power y. 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)); } /// Returns the componentwise result of raising x to the power y. 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)); } /// Returns x raised to the power y. public static double pow(double x, double y) { return System.Math.Pow(x, y); } /// Returns the componentwise result of raising x to the power y. public static double2 pow(double2 x, double2 y) { return new double2(pow(x.x, y.x), pow(x.y, y.y)); } /// Returns the componentwise result of raising x to the power y. 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)); } /// Returns the componentwise result of raising x to the power y. 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)); } /// Returns the base-e exponential of x. public static float exp(float x) { return (float)System.Math.Exp((float)x); } /// Returns the componentwise base-e exponential of x. public static float2 exp(float2 x) { return new float2(exp(x.x), exp(x.y)); } /// Returns the componentwise base-e exponential of x. public static float3 exp(float3 x) { return new float3(exp(x.x), exp(x.y), exp(x.z)); } /// Returns the componentwise base-e exponential of x. public static float4 exp(float4 x) { return new float4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); } /// Returns the base-e exponential of x. public static double exp(double x) { return System.Math.Exp(x); } /// Returns the componentwise base-e exponential of x. public static double2 exp(double2 x) { return new double2(exp(x.x), exp(x.y)); } /// Returns the componentwise base-e exponential of x. public static double3 exp(double3 x) { return new double3(exp(x.x), exp(x.y), exp(x.z)); } /// Returns the componentwise base-e exponential of x. public static double4 exp(double4 x) { return new double4(exp(x.x), exp(x.y), exp(x.z), exp(x.w)); } /// Returns the base-2 exponential of x. public static float exp2(float x) { return (float)System.Math.Exp((float)x * 0.69314718f); } /// Returns the componentwise base-2 exponential of x. public static float2 exp2(float2 x) { return new float2(exp2(x.x), exp2(x.y)); } /// Returns the componentwise base-2 exponential of x. public static float3 exp2(float3 x) { return new float3(exp2(x.x), exp2(x.y), exp2(x.z)); } /// Returns the componentwise base-2 exponential of x. public static float4 exp2(float4 x) { return new float4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); } /// Returns the base-2 exponential of x. public static double exp2(double x) { return System.Math.Exp(x * 0.693147180559945309); } /// Returns the componentwise base-2 exponential of x. public static double2 exp2(double2 x) { return new double2(exp2(x.x), exp2(x.y)); } /// Returns the componentwise base-2 exponential of x. public static double3 exp2(double3 x) { return new double3(exp2(x.x), exp2(x.y), exp2(x.z)); } /// Returns the componentwise base-2 exponential of x. public static double4 exp2(double4 x) { return new double4(exp2(x.x), exp2(x.y), exp2(x.z), exp2(x.w)); } /// Returns the base-10 exponential of x. public static float exp10(float x) { return (float)System.Math.Exp((float)x * 2.30258509f); } /// Returns the componentwise base-10 exponential of x. public static float2 exp10(float2 x) { return new float2(exp10(x.x), exp10(x.y)); } /// Returns the componentwise base-10 exponential of x. public static float3 exp10(float3 x) { return new float3(exp10(x.x), exp10(x.y), exp10(x.z)); } /// Returns the componentwise base-10 exponential of x. public static float4 exp10(float4 x) { return new float4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); } /// Returns the base-10 exponential of x. public static double exp10(double x) { return System.Math.Exp(x * 2.302585092994045684); } /// Returns the componentwise base-10 exponential of x. public static double2 exp10(double2 x) { return new double2(exp10(x.x), exp10(x.y)); } /// Returns the componentwise base-10 exponential of x. public static double3 exp10(double3 x) { return new double3(exp10(x.x), exp10(x.y), exp10(x.z)); } /// Returns the componentwise base-10 exponential of x. public static double4 exp10(double4 x) { return new double4(exp10(x.x), exp10(x.y), exp10(x.z), exp10(x.w)); } /// Returns the natural logarithm of a float value. public static float log(float x) { return (float)System.Math.Log((float)x); } /// Returns the componentwise natural logarithm of a float2 vector. public static float2 log(float2 x) { return new float2(log(x.x), log(x.y)); } /// Returns the componentwise natural logarithm of a float3 vector. public static float3 log(float3 x) { return new float3(log(x.x), log(x.y), log(x.z)); } /// Returns the componentwise natural logarithm of a float4 vector. public static float4 log(float4 x) { return new float4(log(x.x), log(x.y), log(x.z), log(x.w)); } /// Returns the natural logarithm of a double value. public static double log(double x) { return System.Math.Log(x); } /// Returns the componentwise natural logarithm of a double2 vector. public static double2 log(double2 x) { return new double2(log(x.x), log(x.y)); } /// Returns the componentwise natural logarithm of a double3 vector. public static double3 log(double3 x) { return new double3(log(x.x), log(x.y), log(x.z)); } /// Returns the componentwise natural logarithm of a double4 vector. public static double4 log(double4 x) { return new double4(log(x.x), log(x.y), log(x.z), log(x.w)); } /// Returns the base-2 logarithm of a float value. public static float log2(float x) { return (float)System.Math.Log((float)x, 2.0f); } /// Returns the componentwise base-2 logarithm of a float2 vector. public static float2 log2(float2 x) { return new float2(log2(x.x), log2(x.y)); } /// Returns the componentwise base-2 logarithm of a float3 vector. public static float3 log2(float3 x) { return new float3(log2(x.x), log2(x.y), log2(x.z)); } /// Returns the componentwise base-2 logarithm of a float4 vector. public static float4 log2(float4 x) { return new float4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); } /// Returns the base-2 logarithm of a double value. public static double log2(double x) { return System.Math.Log(x, 2.0); } /// Returns the componentwise base-2 logarithm of a double2 vector. public static double2 log2(double2 x) { return new double2(log2(x.x), log2(x.y)); } /// Returns the componentwise base-2 logarithm of a double3 vector. public static double3 log2(double3 x) { return new double3(log2(x.x), log2(x.y), log2(x.z)); } /// Returns the componentwise base-2 logarithm of a double4 vector. public static double4 log2(double4 x) { return new double4(log2(x.x), log2(x.y), log2(x.z), log2(x.w)); } /// Returns the base-10 logarithm of a float value. public static float log10(float x) { return (float)System.Math.Log10((float)x); } /// Returns the componentwise base-10 logarithm of a float2 vector. public static float2 log10(float2 x) { return new float2(log10(x.x), log10(x.y)); } /// Returns the componentwise base-10 logarithm of a float3 vector. public static float3 log10(float3 x) { return new float3(log10(x.x), log10(x.y), log10(x.z)); } /// Returns the componentwise base-10 logarithm of a float4 vector. public static float4 log10(float4 x) { return new float4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); } /// Returns the base-10 logarithm of a double value. public static double log10(double x) { return System.Math.Log10(x); } /// Returns the componentwise base-10 logarithm of a double2 vector. public static double2 log10(double2 x) { return new double2(log10(x.x), log10(x.y)); } /// Returns the componentwise base-10 logarithm of a double3 vector. public static double3 log10(double3 x) { return new double3(log10(x.x), log10(x.y), log10(x.z)); } /// Returns the componentwise base-10 logarithm of a double4 vector. public static double4 log10(double4 x) { return new double4(log10(x.x), log10(x.y), log10(x.z), log10(x.w)); } /// Returns the floating point remainder of x/y. public static float fmod(float x, float y) { return x % y; } /// Returns the componentwise floating point remainder of x/y. public static float2 fmod(float2 x, float2 y) { return new float2(x.x % y.x, x.y % y.y); } /// Returns the componentwise floating point remainder of x/y. public static float3 fmod(float3 x, float3 y) { return new float3(x.x % y.x, x.y % y.y, x.z % y.z); } /// Returns the componentwise floating point remainder of x/y. 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); } /// Returns the double precision floating point remainder of x/y. public static double fmod(double x, double y) { return x % y; } /// Returns the componentwise double precision floating point remainder of x/y. public static double2 fmod(double2 x, double2 y) { return new double2(x.x % y.x, x.y % y.y); } /// Returns the componentwise double precision floating point remainder of x/y. public static double3 fmod(double3 x, double3 y) { return new double3(x.x % y.x, x.y % y.y, x.z % y.z); } /// Returns the componentwise double precision floating point remainder of x/y. 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); } /// Splits a float value into an integral part i and a fractional part that gets returned. Both parts take the sign of the input. public static float modf(float x, out float i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a float2 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static float2 modf(float2 x, out float2 i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a float3 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static float3 modf(float3 x, out float3 i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a float4 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static float4 modf(float4 x, out float4 i) { i = trunc(x); return x - i; } /// Splits a double value into an integral part i and a fractional part that gets returned. Both parts take the sign of the input. public static double modf(double x, out double i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a double2 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static double2 modf(double2 x, out double2 i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a double3 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static double3 modf(double3 x, out double3 i) { i = trunc(x); return x - i; } /// // Performs a componentwise split of a double4 vector into an integral part i and a fractional part that gets returned. // Both parts take the sign of the corresponding input component. // public static double4 modf(double4 x, out double4 i) { i = trunc(x); return x - i; } /// Returns the square root of a float value. public static float sqrt(float x) { return (float)System.Math.Sqrt((float)x); } /// Returns the componentwise square root of a float2 vector. public static float2 sqrt(float2 x) { return new float2(sqrt(x.x), sqrt(x.y)); } /// Returns the componentwise square root of a float3 vector. public static float3 sqrt(float3 x) { return new float3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); } /// Returns the componentwise square root of a float4 vector. public static float4 sqrt(float4 x) { return new float4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); } /// Returns the square root of a double value. public static double sqrt(double x) { return System.Math.Sqrt(x); } /// Returns the componentwise square root of a double2 vector. public static double2 sqrt(double2 x) { return new double2(sqrt(x.x), sqrt(x.y)); } /// Returns the componentwise square root of a double3 vector. public static double3 sqrt(double3 x) { return new double3(sqrt(x.x), sqrt(x.y), sqrt(x.z)); } /// Returns the componentwise square root of a double4 vector. public static double4 sqrt(double4 x) { return new double4(sqrt(x.x), sqrt(x.y), sqrt(x.z), sqrt(x.w)); } /// Returns the reciprocal square root of a float value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float rsqrt(float x) { return 1.0f / sqrt(x); } /// Returns the componentwise reciprocal square root of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 rsqrt(float2 x) { return 1.0f / sqrt(x); } /// Returns the componentwise reciprocal square root of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 rsqrt(float3 x) { return 1.0f / sqrt(x); } /// Returns the componentwise reciprocal square root of a float4 vector [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 rsqrt(float4 x) { return 1.0f / sqrt(x); } /// Returns the reciprocal square root of a double value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double rsqrt(double x) { return 1.0 / sqrt(x); } /// Returns the componentwise reciprocal square root of a double2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 rsqrt(double2 x) { return 1.0 / sqrt(x); } /// Returns the componentwise reciprocal square root of a double3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 rsqrt(double3 x) { return 1.0 / sqrt(x); } /// Returns the componentwise reciprocal square root of a double4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 rsqrt(double4 x) { return 1.0 / sqrt(x); } /// Returns a normalized version of the float2 vector x by scaling it by 1 / length(x). public static float2 normalize(float2 x) { return rsqrt(dot(x, x)) * x; } /// Returns a normalized version of the float3 vector x by scaling it by 1 / length(x). public static float3 normalize(float3 x) { return rsqrt(dot(x, x)) * x; } /// Returns a normalized version of the float4 vector x by scaling it by 1 / length(x). public static float4 normalize(float4 x) { return rsqrt(dot(x, x)) * x; } /// Returns a normalized version of the double2 vector x by scaling it by 1 / length(x). public static double2 normalize(double2 x) { return rsqrt(dot(x, x)) * x; } /// Returns a normalized version of the double3 vector x by scaling it by 1 / length(x). public static double3 normalize(double3 x) { return rsqrt(dot(x, x)) * x; } /// Returns a normalized version of the double4 vector x by scaling it by 1 / length(x). public static double4 normalize(double4 x) { return rsqrt(dot(x, x)) * x; } /// /// Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public float2 normalizesafe(float2 x, float2 defaultvalue = new float2()) { float len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// /// Returns a safe normalized version of the float3 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public float3 normalizesafe(float3 x, float3 defaultvalue = new float3()) { float len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// /// Returns a safe normalized version of the float4 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public float4 normalizesafe(float4 x, float4 defaultvalue = new float4()) { float len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public double2 normalizesafe(double2 x, double2 defaultvalue = new double2()) { double len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public double3 normalizesafe(double3 x, double3 defaultvalue = new double3()) { double len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// /// Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). /// Returns the given default value when 1 / length(x) does not produce a finite number. /// static public double4 normalizesafe(double4 x, double4 defaultvalue = new double4()) { double len = math.dot(x, x); return math.select(defaultvalue, x * math.rsqrt(len), len > FLT_MIN_NORMAL); } /// Returns the length of a float value. Equivalent to the absolute value. public static float length(float x) { return abs(x); } /// Returns the length of a float2 vector. public static float length(float2 x) { return sqrt(dot(x, x)); } /// Returns the length of a float3 vector. public static float length(float3 x) { return sqrt(dot(x, x)); } /// Returns the length of a float4 vector. public static float length(float4 x) { return sqrt(dot(x, x)); } /// Returns the length of a double value. Equivalent to the absolute value. public static double length(double x) { return abs(x); } /// Returns the length of a double2 vector. public static double length(double2 x) { return sqrt(dot(x, x)); } /// Returns the length of a double3 vector. public static double length(double3 x) { return sqrt(dot(x, x)); } /// Returns the length of a double4 vector. public static double length(double4 x) { return sqrt(dot(x, x)); } /// Returns the squared length of a float value. Equivalent to squaring the value. public static float lengthsq(float x) { return x*x; } /// Returns the squared length of a float2 vector. public static float lengthsq(float2 x) { return dot(x, x); } /// Returns the squared length of a float3 vector. public static float lengthsq(float3 x) { return dot(x, x); } /// Returns the squared length of a float4 vector. public static float lengthsq(float4 x) { return dot(x, x); } /// Returns the squared length of a double value. Equivalent to squaring the value. public static double lengthsq(double x) { return x * x; } /// Returns the squared length of a double2 vector. public static double lengthsq(double2 x) { return dot(x, x); } /// Returns the squared length of a double3 vector. public static double lengthsq(double3 x) { return dot(x, x); } /// Returns the squared length of a double4 vector. public static double lengthsq(double4 x) { return dot(x, x); } /// Returns the distance between two float values. public static float distance(float x, float y) { return abs(y - x); } /// Returns the distance between two float2 vectors. public static float distance(float2 x, float2 y) { return length(y - x); } /// Returns the distance between two float3 vectors. public static float distance(float3 x, float3 y) { return length(y - x); } /// Returns the distance between two float4 vectors. public static float distance(float4 x, float4 y) { return length(y - x); } /// Returns the distance between two double values. public static double distance(double x, double y) { return abs(y - x); } /// Returns the distance between two double2 vectors. public static double distance(double2 x, double2 y) { return length(y - x); } /// Returns the distance between two double3 vectors. public static double distance(double3 x, double3 y) { return length(y - x); } /// Returns the distance between two double4 vectors. public static double distance(double4 x, double4 y) { return length(y - x); } /// Returns the distance between two float values. public static float distancesq(float x, float y) { return (y - x) * (y - x); } /// Returns the distance between two float2 vectors. public static float distancesq(float2 x, float2 y) { return lengthsq(y - x); } /// Returns the distance between two float3 vectors. public static float distancesq(float3 x, float3 y) { return lengthsq(y - x); } /// Returns the distance between two float4 vectors. public static float distancesq(float4 x, float4 y) { return lengthsq(y - x); } /// Returns the distance between two double values. public static double distancesq(double x, double y) { return (y - x) * (y - x); } /// Returns the distance between two double2 vectors. public static double distancesq(double2 x, double2 y) { return lengthsq(y - x); } /// Returns the distance between two double3 vectors. public static double distancesq(double3 x, double3 y) { return lengthsq(y - x); } /// Returns the distance between two double4 vectors. public static double distancesq(double4 x, double4 y) { return lengthsq(y - x); } /// Returns the cross product of two float3 vectors. public static float3 cross(float3 x, float3 y) { return (x * y.yzx - x.yzx * y).yzx; } /// Returns the cross product of two double3 vectors. public static double3 cross(double3 x, double3 y) { return (x * y.yzx - x.yzx * y).yzx; } /// Returns a smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. public static float smoothstep(float a, float b, float x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0f - (2.0f * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. public static float2 smoothstep(float2 a, float2 b, float2 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0f - (2.0f * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. public static float3 smoothstep(float3 a, float3 b, float3 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0f - (2.0f * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0f and 1.0f when x is in [a, b]. public static float4 smoothstep(float4 a, float4 b, float4 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0f - (2.0f * t)); } /// Returns a smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. public static double smoothstep(double a, double b, double x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0 - (2.0 * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. public static double2 smoothstep(double2 a, double2 b, double2 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0 - (2.0 * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. public static double3 smoothstep(double3 a, double3 b, double3 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0 - (2.0 * t)); } /// Returns a componentwise smooth Hermite interpolation between 0.0 and 1.0 when x is in [a, b]. public static double4 smoothstep(double4 a, double4 b, double4 x) { var t = saturate((x - a) / (b - a)); return t * t * (3.0 - (2.0 * t)); } /// Returns true if any component of the input bool2 vector is true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(bool2 x) { return x.x || x.y; } /// Returns true if any component of the input bool3 vector is true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(bool3 x) { return x.x || x.y || x.z; } /// Returns true if any components of the input bool4 vector is true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(bool4 x) { return x.x || x.y || x.z || x.w; } /// Returns true if any component of the input int2 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(int2 x) { return x.x != 0 || x.y != 0; } /// Returns true if any component of the input int3 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(int3 x) { return x.x != 0 || x.y != 0 || x.z != 0; } /// Returns true if any components of the input int4 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(int4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; } /// Returns true if any component of the input uint2 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(uint2 x) { return x.x != 0 || x.y != 0; } /// Returns true if any component of the input uint3 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(uint3 x) { return x.x != 0 || x.y != 0 || x.z != 0; } /// Returns true if any components of the input uint4 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(uint4 x) { return x.x != 0 || x.y != 0 || x.z != 0 || x.w != 0; } /// Returns true if any component of the input float2 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(float2 x) { return x.x != 0.0f || x.y != 0.0f; } /// Returns true if any component of the input float3 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(float3 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f; } /// Returns true if any component of the input float4 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(float4 x) { return x.x != 0.0f || x.y != 0.0f || x.z != 0.0f || x.w != 0.0f; } /// Returns true if any component of the input double2 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(double2 x) { return x.x != 0.0 || x.y != 0.0; } /// Returns true if any component of the input double3 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(double3 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0; } /// Returns true if any component of the input double4 vector is non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool any(double4 x) { return x.x != 0.0 || x.y != 0.0 || x.z != 0.0 || x.w != 0.0; } /// Returns true if all components of the input bool2 vector are true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(bool2 x) { return x.x && x.y; } /// Returns true if all components of the input bool3 vector are true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(bool3 x) { return x.x && x.y && x.z; } /// Returns true if all components of the input bool4 vector are true, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(bool4 x) { return x.x && x.y && x.z && x.w; } /// Returns true if all components of the input int2 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(int2 x) { return x.x != 0 && x.y != 0; } /// Returns true if all components of the input int3 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(int3 x) { return x.x != 0 && x.y != 0 && x.z != 0; } /// Returns true if all components of the input int4 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(int4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; } /// Returns true if all components of the input uint2 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(uint2 x) { return x.x != 0 && x.y != 0; } /// Returns true if all components of the input uint3 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(uint3 x) { return x.x != 0 && x.y != 0 && x.z != 0; } /// Returns true if all components of the input uint4 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(uint4 x) { return x.x != 0 && x.y != 0 && x.z != 0 && x.w != 0; } /// Returns true if all components of the input float2 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(float2 x) { return x.x != 0.0f && x.y != 0.0f; } /// Returns true if all components of the input float3 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(float3 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f; } /// Returns true if all components of the input float4 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(float4 x) { return x.x != 0.0f && x.y != 0.0f && x.z != 0.0f && x.w != 0.0f; } /// Returns true if all components of the input double2 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(double2 x) { return x.x != 0.0 && x.y != 0.0; } /// Returns true if all components of the input double3 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(double3 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0; } /// Returns true if all components of the input double4 vector are non-zero, false otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool all(double4 x) { return x.x != 0.0 && x.y != 0.0 && x.z != 0.0 && x.w != 0.0; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int select(int a, int b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 select(int2 a, int2 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 select(int3 a, int3 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 select(int4 a, int4 b, bool c) { return c ? b : a; } /// /// Returns a componentwise selection between two int2 vectors a and b based on a bool2 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 select(int2 a, int2 b, bool2 c) { return new int2(c.x ? b.x : a.x, c.y ? b.y : a.y); } /// /// Returns a componentwise selection between two int3 vectors a and b based on a bool3 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 select(int3 a, int3 b, bool3 c) { return new int3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } /// /// Returns a componentwise selection between two int4 vectors a and b based on a bool4 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 select(int4 a, int4 b, bool4 c) { return new int4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint select(uint a, uint b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 select(uint2 a, uint2 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 select(uint3 a, uint3 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 select(uint4 a, uint4 b, bool c) { return c ? b : a; } /// /// Returns a componentwise selection between two uint2 vectors a and b based on a bool2 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 select(uint2 a, uint2 b, bool2 c) { return new uint2(c.x ? b.x : a.x, c.y ? b.y : a.y); } /// /// Returns a componentwise selection between two uint3 vectors a and b based on a bool3 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 select(uint3 a, uint3 b, bool3 c) { return new uint3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } /// /// Returns a componentwise selection between two uint4 vectors a and b based on a bool4 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 select(uint4 a, uint4 b, bool4 c) { return new uint4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long select(long a, long b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong select(ulong a, ulong b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float select(float a, float b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 select(float2 a, float2 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 select(float3 a, float3 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 select(float4 a, float4 b, bool c) { return c ? b : a; } /// /// Returns a componentwise selection between two float2 vectors a and b based on a bool2 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 select(float2 a, float2 b, bool2 c) { return new float2(c.x ? b.x : a.x, c.y ? b.y : a.y); } /// /// Returns a componentwise selection between two float3 vectors a and b based on a bool3 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 select(float3 a, float3 b, bool3 c) { return new float3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } /// /// Returns a componentwise selection between two float4 vectors a and b based on a bool4 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 select(float4 a, float4 b, bool4 c) { return new float4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double select(double a, double b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 select(double2 a, double2 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 select(double3 a, double3 b, bool c) { return c ? b : a; } /// Returns b if c is true, a otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 select(double4 a, double4 b, bool c) { return c ? b : a; } /// /// Returns a componentwise selection between two double2 vectors a and b based on a bool2 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 select(double2 a, double2 b, bool2 c) { return new double2(c.x ? b.x : a.x, c.y ? b.y : a.y); } /// /// Returns a componentwise selection between two double3 vectors a and b based on a bool3 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 select(double3 a, double3 b, bool3 c) { return new double3(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z); } /// /// Returns a componentwise selection between two double4 vectors a and b based on a bool4 selection mask c. /// Per component, the component from b is selected when c is true, otherwise the component from a is selected. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 select(double4 a, double4 b, bool4 c) { return new double4(c.x ? b.x : a.x, c.y ? b.y : a.y, c.z ? b.z : a.z, c.w ? b.w : a.w); } /// Computes a step function. Returns 1.0f when x >= y, 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float step(float y, float x) { return select(0.0f, 1.0f, x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 step(float2 y, float2 x) { return select(float2(0.0f), float2(1.0f), x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 step(float3 y, float3 x) { return select(float3(0.0f), float3(1.0f), x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 step(float4 y, float4 x) { return select(float4(0.0f), float4(1.0f), x >= y); } /// Computes a step function. Returns 1.0 when x >= y, 0.0 otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double step(double y, double x) { return select(0.0, 1.0, x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 step(double2 y, double2 x) { return select(double2(0.0), double2(1.0), x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 step(double3 y, double3 x) { return select(double3(0.0), double3(1.0), x >= y); } /// Returns the result of a componentwise step function where each component is 1.0f when x >= y and 0.0f otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 step(double4 y, double4 x) { return select(double4(0.0), double4(1.0), x >= y); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 reflect(float2 i, float2 n) { return i - 2f * n * dot(i, n); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 reflect(float3 i, float3 n) { return i - 2f * n * dot(i, n); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0f * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 reflect(float4 i, float4 n) { return i - 2f * n * dot(i, n); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 reflect(double2 i, double2 n) { return i - 2 * n * dot(i, n); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 reflect(double3 i, double3 n) { return i - 2 * n * dot(i, n); } /// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2.0 * dot(i, n) * n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 reflect(double4 i, double4 n) { return i - 2 * n * dot(i, n); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 refract(float2 i, float2 n, float eta) { float ni = dot(n, i); float k = 1.0f - eta * eta * (1.0f - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 refract(float3 i, float3 n, float eta) { float ni = dot(n, i); float k = 1.0f - eta * eta * (1.0f - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 refract(float4 i, float4 n, float eta) { float ni = dot(n, i); float k = 1.0f - eta * eta * (1.0f - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 refract(double2 i, double2 n, double eta) { double ni = dot(n, i); double k = 1.0 - eta * eta * (1.0 - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 refract(double3 i, double3 n, double eta) { double ni = dot(n, i); double k = 1.0 - eta * eta * (1.0 - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Returns the refraction vector given the incident vector i, the normal vector n and the refraction index eta. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 refract(double4 i, double4 n, double eta) { double ni = dot(n, i); double k = 1.0 - eta * eta * (1.0 - ni * ni); return select(0.0f, eta * i - (eta * ni + sqrt(k)) * n, k >= 0); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 faceforward(float2 n, float2 i, float2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 faceforward(float3 n, float3 i, float3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 faceforward(float4 n, float4 i, float4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 faceforward(double2 n, double2 i, double2 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 faceforward(double3 n, double3 i, double3 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Conditionally flips a vector n to face in the direction of i. Returns n if dot(i, ng) < 0, -n otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 faceforward(double4 n, double4 i, double4 ng) { return select(n, -n, dot(ng, i) >= 0.0f); } /// Returns the sine and cosine of the input float value x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(float x, out float s, out float c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input float2 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(float2 x, out float2 s, out float2 c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input float3 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(float3 x, out float3 s, out float3 c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input float4 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(float4 x, out float4 s, out float4 c) { s = sin(x); c = cos(x); } /// Returns the sine and cosine of the input double value x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(double x, out double s, out double c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input double2 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(double2 x, out double2 s, out double2 c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input double3 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(double3 x, out double3 s, out double3 c) { s = sin(x); c = cos(x); } /// Returns the componentwise sine and cosine of the input double4 vector x through the out parameters s and c. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void sincos(double4 x, out double4 s, out double4 c) { s = sin(x); c = cos(x); } /// Returns number of 1-bits in the binary representations of an int value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int countbits(int x) { return countbits((uint)x); } /// Returns componentwise number of 1-bits in the binary representations of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 countbits(int2 x) { return countbits((uint2)x); } /// Returns componentwise number of 1-bits in the binary representations of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 countbits(int3 x) { return countbits((uint3)x); } /// Returns componentwise number of 1-bits in the binary representations of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 countbits(int4 x) { return countbits((uint4)x); } /// Returns number of 1-bits in the binary representations of a uint value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int countbits(uint x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); return (int)((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } /// Returns componentwise number of 1-bits in the binary representations of a uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 countbits(uint2 x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); return int2((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } /// Returns componentwise number of 1-bits in the binary representations of a uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 countbits(uint3 x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); return int3((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } /// Returns componentwise number of 1-bits in the binary representations of a uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 countbits(uint4 x) { x = x - ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); return int4((((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } /// Returns number of 1-bits in the binary representations of a ulong value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int countbits(ulong x) { x = x - ((x >> 1) & 0x5555555555555555); x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); return (int)((((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56); } /// Returns number of 1-bits in the binary representations of a long value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int countbits(long x) { return countbits((ulong)x); } /// Returns the componentwise number of leading zeros in the binary representations of an int vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int lzcnt(int x) { return lzcnt((uint)x); } /// Returns the componentwise number of leading zeros in the binary representations of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 lzcnt(int2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); } /// Returns the componentwise number of leading zeros in the binary representations of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 lzcnt(int3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); } /// Returns the componentwise number of leading zeros in the binary representations of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 lzcnt(int4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); } /// Returns number of leading zeros in the binary representations of a uint value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int lzcnt(uint x) { if (x == 0) return 32; LongDoubleUnion u; u.doubleValue = 0.0; u.longValue = 0x4330000000000000L + x; u.doubleValue -= 4503599627370496.0; return 0x41E - (int)(u.longValue >> 52); } /// Returns the componentwise number of leading zeros in the binary representations of a uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 lzcnt(uint2 x) { return int2(lzcnt(x.x), lzcnt(x.y)); } /// Returns the componentwise number of leading zeros in the binary representations of a uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 lzcnt(uint3 x) { return int3(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z)); } /// Returns the componentwise number of leading zeros in the binary representations of a uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 lzcnt(uint4 x) { return int4(lzcnt(x.x), lzcnt(x.y), lzcnt(x.z), lzcnt(x.w)); } /// Returns number of leading zeros in the binary representations of a long value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int lzcnt(long x) { return lzcnt((ulong)x); } /// Returns number of leading zeros in the binary representations of a ulong value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int lzcnt(ulong x) { if (x == 0) return 64; uint xh = (uint)(x >> 32); uint bits = xh != 0 ? xh : (uint)x; int offset = xh != 0 ? 0x41E : 0x43E; LongDoubleUnion u; u.doubleValue = 0.0; u.longValue = 0x4330000000000000L + bits; u.doubleValue -= 4503599627370496.0; return offset - (int)(u.longValue >> 52); } /// Returns number of trailing zeros in the binary representations of an int value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int tzcnt(int x) { return tzcnt((uint)x); } /// Returns the componentwise number of leading zeros in the binary representations of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 tzcnt(int2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); } /// Returns the componentwise number of leading zeros in the binary representations of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 tzcnt(int3 v) { return int3(tzcnt(v.x), tzcnt(v.y), tzcnt(v.z)); } /// Returns the componentwise number of leading zeros in the binary representations of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 tzcnt(int4 v) { return int4(tzcnt(v.x), tzcnt(v.y), tzcnt(v.z), tzcnt(v.w)); } /// Returns number of trailing zeros in the binary representations of a uint value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int tzcnt(uint x) { if (x == 0) return 32; x &= (uint)-x; LongDoubleUnion u; u.doubleValue = 0.0; u.longValue = 0x4330000000000000L + x; u.doubleValue -= 4503599627370496.0; return (int)(u.longValue >> 52) - 0x3FF; } /// Returns the componentwise number of leading zeros in the binary representations of an uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 tzcnt(uint2 x) { return int2(tzcnt(x.x), tzcnt(x.y)); } /// Returns the componentwise number of leading zeros in the binary representations of an uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 tzcnt(uint3 x) { return int3(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z)); } /// Returns the componentwise number of leading zeros in the binary representations of an uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 tzcnt(uint4 x) { return int4(tzcnt(x.x), tzcnt(x.y), tzcnt(x.z), tzcnt(x.w)); } /// Returns number of trailing zeros in the binary representations of a long value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int tzcnt(long x) { return tzcnt((ulong)x); } /// Returns number of trailing zeros in the binary representations of a ulong value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int tzcnt(ulong x) { if (x == 0) return 64; x = x & (ulong)-(long)x; uint xl = (uint)x; uint bits = xl != 0 ? xl : (uint)(x >> 32); int offset = xl != 0 ? 0x3FF : 0x3DF; LongDoubleUnion u; u.doubleValue = 0.0; u.longValue = 0x4330000000000000L + bits; u.doubleValue -= 4503599627370496.0; return (int)(u.longValue >> 52) - offset; } /// Returns the result of performing a reversal of the bit pattern of an int value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int reversebits(int x) { return (int)reversebits((uint)x); } /// Returns the result of performing a componentwise reversal of the bit pattern of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 reversebits(int2 x) { return (int2)reversebits((uint2)x); } /// Returns the result of performing a componentwise reversal of the bit pattern of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 reversebits(int3 x) { return (int3)reversebits((uint3)x); } /// Returns the result of performing a componentwise reversal of the bit pattern of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 reversebits(int4 x) { return (int4)reversebits((uint4)x); } /// Returns the result of performing a reversal of the bit pattern of a uint value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint reversebits(uint x) { x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); return (x >> 16) | (x << 16); } /// Returns the result of performing a componentwise reversal of the bit pattern of an uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 reversebits(uint2 x) { x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); return (x >> 16) | (x << 16); } /// Returns the result of performing a componentwise reversal of the bit pattern of an uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 reversebits(uint3 x) { x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); return (x >> 16) | (x << 16); } /// Returns the result of performing a componentwise reversal of the bit pattern of an uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 reversebits(uint4 x) { x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); x = ((x >> 4) & 0x0F0F0F0F) | ((x & 0x0F0F0F0F) << 4); x = ((x >> 8) & 0x00FF00FF) | ((x & 0x00FF00FF) << 8); return (x >> 16) | (x << 16); } /// Returns the result of performing a reversal of the bit pattern of a long value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long reversebits(long x) { return (long)reversebits((ulong)x); } /// Returns the result of performing a reversal of the bit pattern of a ulong value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong reversebits(ulong x) { x = ((x >> 1) & 0x5555555555555555ul) | ((x & 0x5555555555555555ul) << 1); x = ((x >> 2) & 0x3333333333333333ul) | ((x & 0x3333333333333333ul) << 2); x = ((x >> 4) & 0x0F0F0F0F0F0F0F0Ful) | ((x & 0x0F0F0F0F0F0F0F0Ful) << 4); x = ((x >> 8) & 0x00FF00FF00FF00FFul) | ((x & 0x00FF00FF00FF00FFul) << 8); x = ((x >> 16) & 0x0000FFFF0000FFFFul) | ((x & 0x0000FFFF0000FFFFul) << 16); return (x >> 32) | (x << 32); } /// Returns the result of rotating the bits of an int left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int rol(int x, int n) { return (int)rol((uint)x, n); } /// Returns the componentwise result of rotating the bits of an int2 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 rol(int2 x, int n) { return (int2)rol((uint2)x, n); } /// Returns the componentwise result of rotating the bits of an int3 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 rol(int3 x, int n) { return (int3)rol((uint3)x, n); } /// Returns the componentwise result of rotating the bits of an int4 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 rol(int4 x, int n) { return (int4)rol((uint4)x, n); } /// Returns the result of rotating the bits of a uint left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint rol(uint x, int n) { return (x << n) | (x >> (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint2 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 rol(uint2 x, int n) { return (x << n) | (x >> (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint3 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 rol(uint3 x, int n) { return (x << n) | (x >> (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint4 left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 rol(uint4 x, int n) { return (x << n) | (x >> (32 - n)); } /// Returns the result of rotating the bits of a long left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long rol(long x, int n) { return (long)rol((ulong)x, n); } /// Returns the result of rotating the bits of a ulong left by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong rol(ulong x, int n) { return (x << n) | (x >> (64 - n)); } /// Returns the result of rotating the bits of an int right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ror(int x, int n) { return (int)ror((uint)x, n); } /// Returns the componentwise result of rotating the bits of an int2 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 ror(int2 x, int n) { return (int2)ror((uint2)x, n); } /// Returns the componentwise result of rotating the bits of an int3 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 ror(int3 x, int n) { return (int3)ror((uint3)x, n); } /// Returns the componentwise result of rotating the bits of an int4 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 ror(int4 x, int n) { return (int4)ror((uint4)x, n); } /// Returns the result of rotating the bits of a uint right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint ror(uint x, int n) { return (x >> n) | (x << (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint2 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 ror(uint2 x, int n) { return (x >> n) | (x << (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint3 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 ror(uint3 x, int n) { return (x >> n) | (x << (32 - n)); } /// Returns the componentwise result of rotating the bits of a uint4 right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 ror(uint4 x, int n) { return (x >> n) | (x << (32 - n)); } /// Returns the result of rotating the bits of a long right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ror(long x, int n) { return (long)ror((ulong)x, n); } /// Returns the result of rotating the bits of a ulong right by bits n. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ror(ulong x, int n) { return (x >> n) | (x << (64 - n)); } /// Returns the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ceilpow2(int x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int2 ceilpow2(int2 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int3 ceilpow2(int3 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int4 ceilpow2(int4 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint ceilpow2(uint x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 ceilpow2(uint2 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 ceilpow2(uint3 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the result of a componentwise calculation of the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 ceilpow2(uint4 x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x + 1; } /// Returns the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ceilpow2(long x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x |= x >> 32; return x + 1; } /// Returns the smallest power of two greater than or equal to the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong ceilpow2(ulong x) { x -= 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x |= x >> 32; return x + 1; } /// Returns the result of converting a float value from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float radians(float x) { return x * 0.0174532925f; } /// Returns the result of a componentwise conversion of a float2 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 radians(float2 x) { return x * 0.0174532925f; } /// Returns the result of a componentwise conversion of a float3 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 radians(float3 x) { return x * 0.0174532925f; } /// Returns the result of a componentwise conversion of a float4 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 radians(float4 x) { return x * 0.0174532925f; } /// Returns the result of converting a float value from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double radians(double x) { return x * 0.017453292519943296; } /// Returns the result of a componentwise conversion of a float2 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 radians(double2 x) { return x * 0.017453292519943296; } /// Returns the result of a componentwise conversion of a float3 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 radians(double3 x) { return x * 0.017453292519943296; } /// Returns the result of a componentwise conversion of a float4 vector from degrees to radians. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 radians(double4 x) { return x * 0.017453292519943296; } /// Returns the result of converting a double value from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float degrees(float x) { return x * 57.295779513f; } /// Returns the result of a componentwise conversion of a double2 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 degrees(float2 x) { return x * 57.295779513f; } /// Returns the result of a componentwise conversion of a double3 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 degrees(float3 x) { return x * 57.295779513f; } /// Returns the result of a componentwise conversion of a double4 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 degrees(float4 x) { return x * 57.295779513f; } /// Returns the result of converting a double value from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double degrees(double x) { return x * 57.29577951308232; } /// Returns the result of a componentwise conversion of a double2 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double2 degrees(double2 x) { return x * 57.29577951308232; } /// Returns the result of a componentwise conversion of a double3 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double3 degrees(double3 x) { return x * 57.29577951308232; } /// Returns the result of a componentwise conversion of a double4 vector from radians to degrees. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double4 degrees(double4 x) { return x * 57.29577951308232; } /// Returns the minimum component of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmin(int2 x) { return min(x.x, x.y); } /// Returns the minimum component of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmin(int3 x) { return min(min(x.x, x.y), x.z); } /// Returns the minimum component of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmin(int4 x) { return min(min(x.x, x.y), min(x.z, x.w)); } /// Returns the minimum component of a uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmin(uint2 x) { return min(x.x, x.y); } /// Returns the minimum component of a uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmin(uint3 x) { return min(min(x.x, x.y), x.z); } /// Returns the minimum component of a uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmin(uint4 x) { return min(min(x.x, x.y), min(x.z, x.w)); } /// Returns the minimum component of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmin(float2 x) { return min(x.x, x.y); } /// Returns the minimum component of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmin(float3 x) { return min(min(x.x, x.y), x.z); } /// Returns the maximum component of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmin(float4 x) { return min(min(x.x, x.y), min(x.z, x.w)); } /// Returns the minimum component of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmin(double2 x) { return min(x.x, x.y); } /// Returns the minimum component of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmin(double3 x) { return min(min(x.x, x.y), x.z); } /// Returns the maximum component of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmin(double4 x) { return min(min(x.x, x.y), min(x.z, x.w)); } /// Returns the maximum component of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmax(int2 x) { return max(x.x, x.y); } /// Returns the maximum component of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmax(int3 x) { return max(max(x.x, x.y), x.z); } /// Returns the maximum component of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int cmax(int4 x) { return max(max(x.x, x.y), max(x.z, x.w)); } /// Returns the maximum component of a uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmax(uint2 x) { return max(x.x, x.y); } /// Returns the maximum component of a uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmax(uint3 x) { return max(max(x.x, x.y), x.z); } /// Returns the maximum component of a uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint cmax(uint4 x) { return max(max(x.x, x.y), max(x.z, x.w)); } /// Returns the maximum component of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmax(float2 x) { return max(x.x, x.y); } /// Returns the maximum component of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmax(float3 x) { return max(max(x.x, x.y), x.z); } /// Returns the maximum component of a float4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float cmax(float4 x) { return max(max(x.x, x.y), max(x.z, x.w)); } /// Returns the maximum component of a double2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmax(double2 x) { return max(x.x, x.y); } /// Returns the maximum component of a double3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmax(double3 x) { return max(max(x.x, x.y), x.z); } /// Returns the maximum component of a double4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double cmax(double4 x) { return max(max(x.x, x.y), max(x.z, x.w)); } /// Returns the horizontal sum of components of an int2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int csum(int2 x) { return x.x + x.y; } /// Returns the horizontal sum of components of an int3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int csum(int3 x) { return x.x + x.y + x.z; } /// Returns the horizontal sum of components of an int4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int csum(int4 x) { return x.x + x.y + x.z + x.w; } /// Returns the horizontal sum of components of a uint2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint csum(uint2 x) { return x.x + x.y; } /// Returns the horizontal sum of components of a uint3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint csum(uint3 x) { return x.x + x.y + x.z; } /// Returns the horizontal sum of components of a uint4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint csum(uint4 x) { return x.x + x.y + x.z + x.w; } /// Returns the horizontal sum of components of a float2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float csum(float2 x) { return x.x + x.y; } /// Returns the horizontal sum of components of a float3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float csum(float3 x) { return x.x + x.y + x.z; } /// Returns the horizontal sum of components of a float4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float csum(float4 x) { return (x.x + x.y) + (x.z + x.w); } /// Returns the horizontal sum of components of a double2 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double csum(double2 x) { return x.x + x.y; } /// Returns the horizontal sum of components of a double3 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double csum(double3 x) { return x.x + x.y + x.z; } /// Returns the horizontal sum of components of a double4 vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double csum(double4 x) { return (x.x + x.y) + (x.z + x.w); } /// /// Packs components with an enabled mask (LSB) to the left /// The value of components after the last packed component are undefined. /// Returns the number of enabled mask bits. (0 ... 4) /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe int compress(int* output, int index, int4 val, bool4 mask) { if (mask.x) output[index++] = val.x; if (mask.y) output[index++] = val.y; if (mask.z) output[index++] = val.z; if (mask.w) output[index++] = val.w; return index; } /// Returns the floating point representation of a half-precision floating point value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float f16tof32(uint x) { const uint shifted_exp = (0x7c00 << 13); uint uf = (x & 0x7fff) << 13; uint e = uf & shifted_exp; uf += (127 - 15) << 23; uf += select(0, (128u - 16u) << 23, e == shifted_exp); uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0); uf |= (x & 0x8000) << 16; return asfloat(uf); } /// Returns the floating point representation of a half-precision floating point vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float2 f16tof32(uint2 x) { const uint shifted_exp = (0x7c00 << 13); uint2 uf = (x & 0x7fff) << 13; uint2 e = uf & shifted_exp; uf += (127 - 15) << 23; uf += select(0, (128u - 16u) << 23, e == shifted_exp); uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0); uf |= (x & 0x8000) << 16; return asfloat(uf); } /// Returns the floating point representation of a half-precision floating point vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 f16tof32(uint3 x) { const uint shifted_exp = (0x7c00 << 13); uint3 uf = (x & 0x7fff) << 13; uint3 e = uf & shifted_exp; uf += (127 - 15) << 23; uf += select(0, (128u - 16u) << 23, e == shifted_exp); uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0); uf |= (x & 0x8000) << 16; return asfloat(uf); } /// Returns the floating point representation of a half-precision floating point vector. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float4 f16tof32(uint4 x) { const uint shifted_exp = (0x7c00 << 13); uint4 uf = (x & 0x7fff) << 13; uint4 e = uf & shifted_exp; uf += (127 - 15) << 23; uf += select(0, (128u - 16u) << 23, e == shifted_exp); uf = select(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0); uf |= (x & 0x8000) << 16; return asfloat(uf); } /// Returns the result converting a float value to its nearest half-precision floating point representation. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint f32tof16(float x) { const int infinity_32 = 255 << 23; const uint msk = 0x7FFFF000u; uint ux = asuint(x); uint uux = ux & msk; uint h = (uint)(asuint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed h = select(h, select(0x7c00u, 0x7e00u, (int)uux > infinity_32), (int)uux >= infinity_32); // NaN->qNaN and Inf->Inf return h | (ux & ~msk) >> 16; } /// Returns the result of a componentwise conversion of a float2 vector to its nearest half-precision floating point representation. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint2 f32tof16(float2 x) { const int infinity_32 = 255 << 23; const uint msk = 0x7FFFF000u; uint2 ux = asuint(x); uint2 uux = ux & msk; uint2 h = (uint2)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed h = select(h, select(0x7c00u, 0x7e00u, (int2)uux > infinity_32), (int2)uux >= infinity_32); // NaN->qNaN and Inf->Inf return h | (ux & ~msk) >> 16; } /// Returns the result of a componentwise conversion of a float3 vector to its nearest half-precision floating point representation. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint3 f32tof16(float3 x) { const int infinity_32 = 255 << 23; const uint msk = 0x7FFFF000u; uint3 ux = asuint(x); uint3 uux = ux & msk; uint3 h = (uint3)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed h = select(h, select(0x7c00u, 0x7e00u, (int3)uux > infinity_32), (int3)uux >= infinity_32); // NaN->qNaN and Inf->Inf return h | (ux & ~msk) >> 16; } /// Returns the result of a componentwise conversion of a float4 vector to its nearest half-precision floating point representation. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint4 f32tof16(float4 x) { const int infinity_32 = 255 << 23; const uint msk = 0x7FFFF000u; uint4 ux = asuint(x); uint4 uux = ux & msk; uint4 h = (uint4)(asint(min(asfloat(uux) * 1.92592994e-34f, 260042752.0f)) + 0x1000) >> 13; // Clamp to signed infinity if overflowed h = select(h, select(0x7c00u, 0x7e00u, (int4)uux > infinity_32), (int4)uux >= infinity_32); // NaN->qNaN and Inf->Inf return h | (ux & ~msk) >> 16; } /// Returns a uint hash from a block of memory using the xxhash32 algorithm. Can only be used in an unsafe context. /// A pointer to the beginning of the data. /// Number of bytes to hash. /// Starting seed value. public static unsafe uint hash(void* pBuffer, int numBytes, uint seed = 0) { unchecked { const uint Prime1 = 2654435761; const uint Prime2 = 2246822519; const uint Prime3 = 3266489917; const uint Prime4 = 668265263; const uint Prime5 = 374761393; uint4* p = (uint4*)pBuffer; uint hash = seed + Prime5; if (numBytes >= 16) { uint4 state = new uint4(Prime1 + Prime2, Prime2, 0, (uint)-Prime1) + seed; int count = numBytes >> 4; for (int i = 0; i < count; ++i) { state += *p++ * Prime2; state = (state << 13) | (state >> 19); state *= Prime1; } hash = rol(state.x, 1) + rol(state.y, 7) + rol(state.z, 12) + rol(state.w, 18); } hash += (uint)numBytes; uint* puint = (uint*)p; for (int i = 0; i < ((numBytes >> 2) & 3); ++i) { hash += *puint++ * Prime3; hash = rol(hash, 17) * Prime4; } byte* pbyte = (byte*)puint; for (int i = 0; i < ((numBytes) & 3); ++i) { hash += (*pbyte++) * Prime5; hash = rol(hash, 11) * Prime1; } hash ^= hash >> 15; hash *= Prime2; hash ^= hash >> 13; hash *= Prime3; hash ^= hash >> 16; return hash; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float3 up() { return new float3(0.0f, 1.0f, 0.0f); } // for compatibility // Internal // SSE shuffles [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static float4 unpacklo(float4 a, float4 b) { return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static double4 unpacklo(double4 a, double4 b) { return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.RightX, ShuffleComponent.LeftY, ShuffleComponent.RightY); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static float4 unpackhi(float4 a, float4 b) { return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static double4 unpackhi(double4 a, double4 b) { return shuffle(a, b, ShuffleComponent.LeftZ, ShuffleComponent.RightZ, ShuffleComponent.LeftW, ShuffleComponent.RightW); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static float4 movelh(float4 a, float4 b) { return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static double4 movelh(double4 a, double4 b) { return shuffle(a, b, ShuffleComponent.LeftX, ShuffleComponent.LeftY, ShuffleComponent.RightX, ShuffleComponent.RightY); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static float4 movehl(float4 a, float4 b) { return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static double4 movehl(double4 a, double4 b) { return shuffle(b, a, ShuffleComponent.LeftZ, ShuffleComponent.LeftW, ShuffleComponent.RightZ, ShuffleComponent.RightW); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static uint fold_to_uint(double x) // utility for double hashing { LongDoubleUnion u; u.longValue = 0; u.doubleValue = x; return (uint)(u.longValue >> 32) ^ (uint)u.longValue; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static uint2 fold_to_uint(double2 x) { return uint2(fold_to_uint(x.x), fold_to_uint(x.y)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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)); } [StructLayout(LayoutKind.Explicit)] internal struct IntFloatUnion { [FieldOffset(0)] public int intValue; [FieldOffset(0)] public float floatValue; } [StructLayout(LayoutKind.Explicit)] internal struct LongDoubleUnion { [FieldOffset(0)] public long longValue; [FieldOffset(0)] public double doubleValue; } } }