14 public const double E = 2.718281828459045;
16 public const double PI = 3.141592653589793;
18 public const double Tau = Math.PI * 2.0;
22 1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, 10000000.0, 100000000.0, 1000000000.0,
23 10000000000.0, 100000000000.0, 1000000000000.0, 10000000000000.0, 100000000000000.0, 1000000000000000.0
36 public static extern double Acos(
double d);
40 public static extern double Acosh(
double d);
44 public static extern double Asin(
double d);
48 public static extern double Asinh(
double d);
52 public static extern double Atan(
double d);
56 public static extern double Atanh(
double d);
60 public static extern double Atan2(
double y,
double x);
64 public static extern double Cbrt(
double d);
68 public static extern double Ceiling(
double a);
72 public static extern double Cos(
double d);
80 public static extern double Exp(
double d);
84 public static extern double Floor(
double d);
92 public static extern int ILogB(
double x);
96 public static extern double Log(
double d);
100 public static extern double Log2(
double x);
104 public static extern double Log10(
double d);
108 public static extern double Pow(
double x,
double y);
112 public static extern double Sin(
double a);
128 public static extern double Sqrt(
double d);
132 public static extern double Tan(
double a);
139 private unsafe static extern double ModF(
double x,
double* intptr);
142 private unsafe static extern void SinCos(
double x,
double* sin,
double* cos);
201 [CLSCompliant(
false)]
218 return decimal.Abs(in
value);
230 return (
long)a * (long)b;
234 [CLSCompliant(
false)]
247 return SoftwareFallback(a, b, out low);
248 static ulong SoftwareFallback(ulong a, ulong b, out ulong low)
251 uint num3 = (uint)(a >> 32);
253 uint num5 = (uint)(b >> 32);
254 ulong num6 = (ulong)num2 * (ulong)num4;
255 ulong num7 = (ulong)((
long)num3 * (long)num4) + (num6 >> 32);
256 ulong num8 = (ulong)((
long)num2 * (long)num5 + (uint)num7);
257 low = (num8 << 32) | (uint)num6;
258 return (ulong)((long)num3 * (
long)num5 + (long)(num7 >> 32)) + (num8 >> 32);
262 public static long BigMul(
long a,
long b, out
long low)
268 ulong num =
BigMul((ulong)a, (ulong)b, out low2);
270 return (
long)num - ((a >> 63) & b) - ((b >> 63) & a);
276 if (((num >> 32) & 0x7FF00000) >= 2146435072)
278 if (num != 9218868437227405312
L)
282 return double.MaxValue;
288 num += ((num < 0) ? 1 : (-1));
295 if (((num >> 32) & 0x7FF00000) >= 2146435072)
297 if (num != -4503599627370496
L)
301 return double.MinValue;
303 if (num ==
long.MinValue)
305 return double.Epsilon;
307 num += ((num >= 0) ? 1 : (-1));
318 return SoftwareFallback(x, y);
319 static double SoftwareFallback(
double x,
double y)
323 num &= 0x7FFFFFFFFFFFFFFF
L;
324 num2 &=
long.MinValue;
329 public static int DivRem(
int a,
int b, out
int result)
332 result = a - num * b;
336 public static long DivRem(
long a,
long b, out
long result)
339 result = a - num * b;
345 [CLSCompliant(
false)]
348 sbyte b = (sbyte)(left / right);
349 return (
Quotient: b, Remainder: (sbyte)(left - b * right));
356 byte b = (byte)(left / right);
357 return (
Quotient: b, Remainder: (byte)(left - b * right));
364 short num = (
short)(left / right);
365 return (
Quotient: num, Remainder: (
short)(left - num * right));
370 [CLSCompliant(
false)]
371 public static (ushort
Quotient, ushort Remainder)
DivRem(ushort left, ushort right)
373 ushort num = (ushort)(left / right);
374 return (
Quotient: num, Remainder: (ushort)(left - num * right));
381 int num = left / right;
382 return (
Quotient: num, Remainder: left - num * right);
387 [CLSCompliant(
false)]
390 uint num = left / right;
391 return (
Quotient: num, Remainder: left - num * right);
398 long num = left / right;
399 return (
Quotient: num, Remainder: left - num * right);
404 [CLSCompliant(
false)]
407 ulong num = left / right;
408 return (
Quotient: num, Remainder: left - num * right);
415 nint num = left / right;
416 return (
Quotient: num, Remainder: left - num * right);
421 [CLSCompliant(
false)]
424 nuint num = left / right;
425 return (
Quotient: num, Remainder: left - num * right);
431 return decimal.Ceiling(d);
439 ThrowMinMaxException(min, max);
453 public static decimal
Clamp(decimal
value, decimal min, decimal max)
457 ThrowMinMaxException(min, max);
471 public static double Clamp(
double value,
double min,
double max)
475 ThrowMinMaxException(min, max);
493 ThrowMinMaxException(min, max);
511 ThrowMinMaxException(min, max);
529 ThrowMinMaxException(min, max);
547 ThrowMinMaxException(min, max);
561 [CLSCompliant(
false)]
566 ThrowMinMaxException(min, max);
584 ThrowMinMaxException(min, max);
598 [CLSCompliant(
false)]
599 public static ushort
Clamp(ushort
value, ushort min, ushort max)
603 ThrowMinMaxException(min, max);
617 [CLSCompliant(
false)]
622 ThrowMinMaxException(min, max);
636 [CLSCompliant(
false)]
641 ThrowMinMaxException(min, max);
655 [CLSCompliant(
false)]
660 ThrowMinMaxException(min, max);
674 public static decimal
Floor(decimal d)
676 return decimal.Floor(d);
690 if (
double.IsNaN(num))
694 if (num == 0.0 &&
double.IsNegative(x))
698 double num2 = num -
Abs(y) * (double)
Sign(x);
699 if (
Abs(num2) ==
Abs(num))
716 public static double Log(
double a,
double newBase)
722 if (
double.IsNaN(newBase))
730 if (a != 1.0 && (newBase == 0.0 ||
double.IsPositiveInfinity(newBase)))
734 return Log(a) /
Log(newBase);
738 public static byte Max(
byte val1,
byte val2)
748 public static decimal
Max(decimal val1, decimal val2)
750 return decimal.Max(in val1, in val2);
754 public static double Max(
double val1,
double val2)
758 if (!
double.IsNaN(val1))
768 if (!
double.IsNegative(val2))
776 public static short Max(
short val1,
short val2)
786 public static int Max(
int val1,
int val2)
796 public static long Max(
long val1,
long val2)
806 public static nint
Max(nint val1, nint val2)
815 [CLSCompliant(
false)]
817 public static sbyte
Max(sbyte val1, sbyte val2)
827 public static float Max(
float val1,
float val2)
831 if (!
float.IsNaN(val1))
841 if (!
float.IsNegative(val2))
848 [CLSCompliant(
false)]
850 public static ushort
Max(ushort val1, ushort val2)
859 [CLSCompliant(
false)]
861 public static uint
Max(uint val1, uint val2)
870 [CLSCompliant(
false)]
872 public static ulong
Max(ulong val1, ulong val2)
881 [CLSCompliant(
false)]
883 public static nuint
Max(nuint val1, nuint val2)
895 double num2 =
Abs(y);
896 if (num > num2 ||
double.IsNaN(num))
902 if (!
double.IsNegative(x))
912 public static byte Min(
byte val1,
byte val2)
922 public static decimal
Min(decimal val1, decimal val2)
924 return decimal.Min(in val1, in val2);
928 public static double Min(
double val1,
double val2)
930 if (val1 != val2 && !
double.IsNaN(val1))
938 if (!
double.IsNegative(val1))
946 public static short Min(
short val1,
short val2)
956 public static int Min(
int val1,
int val2)
966 public static long Min(
long val1,
long val2)
976 public static nint
Min(nint val1, nint val2)
985 [CLSCompliant(
false)]
987 public static sbyte
Min(sbyte val1, sbyte val2)
997 public static float Min(
float val1,
float val2)
999 if (val1 != val2 && !
float.IsNaN(val1))
1007 if (!
float.IsNegative(val1))
1014 [CLSCompliant(
false)]
1016 public static ushort
Min(ushort val1, ushort val2)
1025 [CLSCompliant(
false)]
1027 public static uint
Min(uint val1, uint val2)
1036 [CLSCompliant(
false)]
1038 public static ulong
Min(ulong val1, ulong val2)
1047 [CLSCompliant(
false)]
1049 public static nuint
Min(nuint val1, nuint val2)
1060 double num =
Abs(x);
1061 double num2 =
Abs(y);
1062 if (num < num2 ||
double.IsNaN(num))
1068 if (!
double.IsNegative(x))
1092 return 1.0 /
Sqrt(d);
1098 return decimal.Round(d, 0);
1102 public static decimal
Round(decimal d,
int decimals)
1104 return decimal.Round(d, decimals);
1110 return decimal.Round(d, 0, mode);
1116 return decimal.Round(d, decimals, mode);
1123 int num2 =
double.ExtractExponentFromBits(num);
1130 double x = ((num2 == 1022 &&
double.ExtractSignificandFromBits(num) != 0
L) ? 1.0 : 0.0);
1137 ulong num3 = (ulong)(1
L << 1075 - num2);
1138 ulong num4 = num3 - 1;
1140 num = (((num & num4) != 0
L) ? (num & ~num4) : (num & ~num3));
1158 if (digits < 0 || digits > 15)
1162 if (mode < MidpointRounding.ToEven || mode >
MidpointRounding.ToPositiveInfinity)
1166 if (
Abs(
value) < 10000000000000000.0)
1178 if (
Abs(value2) >= 0.5)
1204 return decimal.Sign(in
value);
1237 return (
int)((
value >> 63) | (-
value >>> 63));
1242 return (
int)((long)(
value >> 63) | (long)((ulong)(-
value) >> 63));
1246 [CLSCompliant(
false)]
1272 return decimal.Truncate(d);
1292 num *= 8.98846567431158E+307;
1296 num *= 8.98846567431158E+307;
1306 num *= 2.004168360008973E-292;
1310 num *= 2.004168360008973E-292;
static unsafe double Int64BitsToDouble(long value)
static ulong DoubleToUInt64Bits(double value)
static unsafe long DoubleToInt64Bits(double value)
static double UInt64BitsToDouble(ulong value)
static double Atan(double d)
static double Log2(double x)
static sbyte Abs(sbyte value)
static decimal Round(decimal d, int decimals)
static byte Clamp(byte value, byte min, byte max)
static ulong Clamp(ulong value, ulong min, ulong max)
static long long Remainder DivRem(long left, long right)
static double Min(double val1, double val2)
static double Acos(double d)
static unsafe ulong BigMul(ulong a, ulong b, out ulong low)
static uint uint Remainder DivRem(uint left, uint right)
static decimal Truncate(decimal d)
static nint nint Remainder DivRem(nint left, nint right)
static double Cos(double d)
static unsafe double Round(double value, int digits, MidpointRounding mode)
static decimal Max(decimal val1, decimal val2)
static double Exp(double d)
static int Abs(int value)
static double ReciprocalEstimate(double d)
static decimal Round(decimal d, int decimals, MidpointRounding mode)
static double Tanh(double value)
static double Round(double value, int digits)
static short short Remainder DivRem(short left, short right)
static decimal Ceiling(decimal d)
static ulong Min(ulong val1, ulong val2)
static void ThrowMinMaxException< T >(T min, T max)
static nint Abs(nint value)
static float Min(float val1, float val2)
static double Atanh(double d)
static int Sign(float value)
static sbyte Min(sbyte val1, sbyte val2)
static unsafe void SinCos(double x, double *sin, double *cos)
static byte Min(byte val1, byte val2)
static int Sign(sbyte value)
static double ScaleB(double x, int n)
static decimal Round(decimal d, MidpointRounding mode)
static double CopySign(double x, double y)
static ushort Clamp(ushort value, ushort min, ushort max)
static double Tan(double a)
static int int Remainder DivRem(int left, int right)
static nuint nuint Remainder DivRem(nuint left, nuint right)
static short Clamp(short value, short min, short max)
static ushort Max(ushort val1, ushort val2)
static double Atan2(double y, double x)
static byte byte Remainder DivRem(byte left, byte right)
static double Cbrt(double d)
static short Max(short val1, short val2)
static long BigMul(long a, long b, out long low)
static nint Max(nint val1, nint val2)
static decimal Floor(decimal d)
static double Sqrt(double d)
static nuint Clamp(nuint value, nuint min, nuint max)
static double Asin(double d)
static double Pow(double x, double y)
static double MinMagnitude(double x, double y)
static nuint Max(nuint val1, nuint val2)
static long Clamp(long value, long min, long max)
static int Sign(int value)
static short Abs(short value)
static decimal Min(decimal val1, decimal val2)
static decimal Round(decimal d)
static double Ceiling(double a)
static double Asinh(double d)
static long Abs(long value)
static float Abs(float value)
static nuint Min(nuint val1, nuint val2)
static double ReciprocalSqrtEstimate(double d)
static readonly double[] roundPower10Double
static int Min(int val1, int val2)
static sbyte Clamp(sbyte value, sbyte min, sbyte max)
static double IEEERemainder(double x, double y)
static double Max(double val1, double val2)
static uint Min(uint val1, uint val2)
static double Log10(double d)
static int Sign(double value)
static double Clamp(double value, double min, double max)
static float Clamp(float value, float min, float max)
static ushort ushort Remainder DivRem(ushort left, ushort right)
static ushort Min(ushort val1, ushort val2)
static int Clamp(int value, int min, int max)
static double BitDecrement(double x)
static double Log(double a, double newBase)
static double Log(double d)
static long Max(long val1, long val2)
static int Max(int val1, int val2)
static double Acosh(double d)
static double Abs(double value)
static long DivRem(long a, long b, out long result)
static int DivRem(int a, int b, out int result)
static unsafe(double Sin, double Cos) SinCos(double x)
static nint Clamp(nint value, nint min, nint max)
static double Sin(double a)
static float Max(float val1, float val2)
static short Min(short val1, short val2)
static void ThrowAbsOverflow()
static uint Max(uint val1, uint val2)
static double BitIncrement(double x)
static ulong Max(ulong val1, ulong val2)
static double Sinh(double value)
static decimal Clamp(decimal value, decimal min, decimal max)
static long Min(long val1, long val2)
static double Round(double value, MidpointRounding mode)
static ulong ulong Remainder DivRem(ulong left, ulong right)
static int Sign(long value)
static double Floor(double d)
static double Cosh(double value)
static double FusedMultiplyAdd(double x, double y, double z)
static sbyte sbyte Remainder DivRem(sbyte left, sbyte right)
static decimal Abs(decimal value)
static int Sign(short value)
static double Round(double a)
static double MaxMagnitude(double x, double y)
static long BigMul(int a, int b)
static sbyte Max(sbyte val1, sbyte val2)
static uint Clamp(uint value, uint min, uint max)
static int Sign(nint value)
static nint Min(nint val1, nint val2)
static int Sign(decimal value)
static unsafe double ModF(double x, double *intptr)
static unsafe double Truncate(double d)
static byte Max(byte val1, byte val2)
static int ILogB(double x)
static Vector128< float > ConditionalSelectBitwise(Vector128< float > selector, Vector128< float > ifTrue, Vector128< float > ifFalse)
static new bool IsSupported
static new bool IsSupported
static unsafe Vector128< byte > CreateScalarUnsafe(byte value)
static ulong MultiplyNoFlags(ulong left, ulong right)
static new bool IsSupported
static new bool IsSupported
static string Overflow_NegateTwosCompNum
static string Argument_MinMaxValue
static string Format(string resourceFormat, object p1)
static string ArgumentOutOfRange_RoundingDigits
static string Arithmetic_NaN
static string Argument_InvalidEnumValue