From 36c94be6d09ef5b60abe05df17034a57b8d619fb Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Mon, 10 Jul 2023 19:26:25 +0200 Subject: [PATCH] Renamed math tools --- FastRng/Distributions/ChiSquareK1.cs | 2 +- FastRng/Distributions/ChiSquareK10.cs | 2 +- FastRng/Distributions/ChiSquareK4.cs | 2 +- FastRng/Distributions/GammaA5B15.cs | 2 +- FastRng/Distributions/InverseGammaA3B05.cs | 2 +- FastRng/Distributions/StudentTNu1.cs | 4 +- FastRng/MathToolsFloatingPoint.cs | 2 +- ...ntegerMathTools.cs => MathToolsInteger.cs} | 2 +- FastRngTests/MathToolsTests.cs | 74 +++++++++---------- 9 files changed, 46 insertions(+), 46 deletions(-) rename FastRng/{IntegerMathTools.cs => MathToolsInteger.cs} (95%) diff --git a/FastRng/Distributions/ChiSquareK1.cs b/FastRng/Distributions/ChiSquareK1.cs index de626e5..8857f0e 100644 --- a/FastRng/Distributions/ChiSquareK1.cs +++ b/FastRng/Distributions/ChiSquareK1.cs @@ -16,7 +16,7 @@ public sealed class ChiSquareK1 : Distribution where TNum : IFloatin static ChiSquareK1() { var twoToTheKHalf = TNum.Pow(TWO, K_HALF); - var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); + var gammaKHalf = MathToolsFloatingPoint.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } diff --git a/FastRng/Distributions/ChiSquareK10.cs b/FastRng/Distributions/ChiSquareK10.cs index 169651d..155ad9b 100644 --- a/FastRng/Distributions/ChiSquareK10.cs +++ b/FastRng/Distributions/ChiSquareK10.cs @@ -16,7 +16,7 @@ public sealed class ChiSquareK10 : Distribution where TNum : IFloati static ChiSquareK10() { var twoToTheKHalf = TNum.Pow(TWO, K_HALF); - var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); + var gammaKHalf = MathToolsFloatingPoint.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } diff --git a/FastRng/Distributions/ChiSquareK4.cs b/FastRng/Distributions/ChiSquareK4.cs index 263e459..a514063 100644 --- a/FastRng/Distributions/ChiSquareK4.cs +++ b/FastRng/Distributions/ChiSquareK4.cs @@ -16,7 +16,7 @@ public sealed class ChiSquareK4 : Distribution where TNum : IFloatin static ChiSquareK4() { var twoToTheKHalf = TNum.Pow(TWO, K_HALF); - var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); + var gammaKHalf = MathToolsFloatingPoint.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } diff --git a/FastRng/Distributions/GammaA5B15.cs b/FastRng/Distributions/GammaA5B15.cs index 957d409..1aa509e 100644 --- a/FastRng/Distributions/GammaA5B15.cs +++ b/FastRng/Distributions/GammaA5B15.cs @@ -13,7 +13,7 @@ public sealed class GammaA5B15 : Distribution where TNum : IFloating static GammaA5B15() { - GAMMA_ALPHA = FloatingPointMathTools.Gamma(ALPHA); + GAMMA_ALPHA = MathToolsFloatingPoint.Gamma(ALPHA); BETA_TO_THE_ALPHA = TNum.Pow(BETA, ALPHA); } diff --git a/FastRng/Distributions/InverseGammaA3B05.cs b/FastRng/Distributions/InverseGammaA3B05.cs index b00b0e3..56465da 100644 --- a/FastRng/Distributions/InverseGammaA3B05.cs +++ b/FastRng/Distributions/InverseGammaA3B05.cs @@ -12,7 +12,7 @@ public sealed class InverseGammaA3B05 : Distribution where TNum : IF static InverseGammaA3B05() { - var gammaAlpha = FloatingPointMathTools.Gamma(ALPHA); + var gammaAlpha = MathToolsFloatingPoint.Gamma(ALPHA); var betaToTheAlpha = TNum.Pow(BETA, ALPHA); FACTOR_LEFT = CONSTANT * (betaToTheAlpha / gammaAlpha); diff --git a/FastRng/Distributions/StudentTNu1.cs b/FastRng/Distributions/StudentTNu1.cs index d349f10..b9706ae 100644 --- a/FastRng/Distributions/StudentTNu1.cs +++ b/FastRng/Distributions/StudentTNu1.cs @@ -17,8 +17,8 @@ public sealed class StudentTNu1 : Distribution where TNum : IFloatin static StudentTNu1() { - DIVIDEND = FloatingPointMathTools.Gamma((NU + TNum.One) * HALF); - DIVISOR = TNum.Sqrt(NU * TNum.Pi) * FloatingPointMathTools.Gamma(NU * HALF); + DIVIDEND = MathToolsFloatingPoint.Gamma((NU + TNum.One) * HALF); + DIVISOR = TNum.Sqrt(NU * TNum.Pi) * MathToolsFloatingPoint.Gamma(NU * HALF); EXPONENT = -((NU + TNum.One) * HALF); } diff --git a/FastRng/MathToolsFloatingPoint.cs b/FastRng/MathToolsFloatingPoint.cs index 2069bbb..7f2e7bf 100644 --- a/FastRng/MathToolsFloatingPoint.cs +++ b/FastRng/MathToolsFloatingPoint.cs @@ -5,7 +5,7 @@ namespace FastRng; /// /// Provides some mathematical function, which are not available within in .NET itself. /// -public static class FloatingPointMathTools where TNum : IFloatingPointIeee754, IAdditionOperators +public static class MathToolsFloatingPoint where TNum : IFloatingPointIeee754, IAdditionOperators { private static readonly TNum SQRT_2 = TNum.Sqrt(TNum.One + TNum.One); private static readonly TNum SQRT_PI = TNum.Sqrt(TNum.Pi); diff --git a/FastRng/IntegerMathTools.cs b/FastRng/MathToolsInteger.cs similarity index 95% rename from FastRng/IntegerMathTools.cs rename to FastRng/MathToolsInteger.cs index e6cef21..d2db474 100644 --- a/FastRng/IntegerMathTools.cs +++ b/FastRng/MathToolsInteger.cs @@ -5,7 +5,7 @@ namespace FastRng; /// /// Provides some mathematical function, which are not available within in .NET itself. /// -public static class IntegerMathTools +public static class MathToolsInteger { /// /// The mathematical factorial function for integer numbers. diff --git a/FastRngTests/MathToolsTests.cs b/FastRngTests/MathToolsTests.cs index a866df1..3a4e0a3 100644 --- a/FastRngTests/MathToolsTests.cs +++ b/FastRngTests/MathToolsTests.cs @@ -15,7 +15,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest01() { - Assert.That(FloatingPointMathTools.Gamma(-0.5f), Is.EqualTo(-3.544907701811087f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(-0.5f), Is.EqualTo(-3.544907701811087f).Within(1e-6f)); } [Test] @@ -23,7 +23,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest02() { - Assert.That(FloatingPointMathTools.Gamma(0.1f), Is.EqualTo(9.51350975f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(0.1f), Is.EqualTo(9.51350975f).Within(1e-6f)); } [Test] @@ -31,7 +31,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest03() { - Assert.That(FloatingPointMathTools.Gamma(0.5f), Is.EqualTo(1.772453850905517f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(0.5f), Is.EqualTo(1.772453850905517f).Within(1e-6f)); } [Test] @@ -39,7 +39,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest04() { - Assert.That(FloatingPointMathTools.Gamma(1.0f), Is.EqualTo(1.0f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(1.0f), Is.EqualTo(1.0f).Within(1e-6f)); } [Test] @@ -47,7 +47,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest05() { - Assert.That(FloatingPointMathTools.Gamma(1.5f), Is.EqualTo(0.8862269254527587f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(1.5f), Is.EqualTo(0.8862269254527587f).Within(1e-6f)); } [Test] @@ -55,7 +55,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest06() { - Assert.That(FloatingPointMathTools.Gamma(2.0f), Is.EqualTo(1.0f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(2.0f), Is.EqualTo(1.0f).Within(1e-6f)); } [Test] @@ -63,7 +63,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest07() { - Assert.That(FloatingPointMathTools.Gamma(3.0f), Is.EqualTo(2.0f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(3.0f), Is.EqualTo(2.0f).Within(1e-6f)); } [Test] @@ -71,7 +71,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest08() { - Assert.That(FloatingPointMathTools.Gamma(10.0f), Is.EqualTo(362_880.719f).Within(1e-6f)); + Assert.That(MathToolsFloatingPoint.Gamma(10.0f), Is.EqualTo(362_880.719f).Within(1e-6f)); } [Test] @@ -79,7 +79,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest09() { - Assert.That(FloatingPointMathTools.Gamma(140.0f), Is.EqualTo(float.NaN)); + Assert.That(MathToolsFloatingPoint.Gamma(140.0f), Is.EqualTo(float.NaN)); } [Test] @@ -87,7 +87,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest10() { - Assert.That(FloatingPointMathTools.Gamma(170.0f), Is.EqualTo(float.NaN)); + Assert.That(MathToolsFloatingPoint.Gamma(170.0f), Is.EqualTo(float.NaN)); } #endregion @@ -99,7 +99,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger01() { - Assert.That(IntegerMathTools.Factorial(0), Is.EqualTo(1)); + Assert.That(MathToolsInteger.Factorial(0), Is.EqualTo(1)); } [Test] @@ -107,7 +107,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger02() { - Assert.That(IntegerMathTools.Factorial(1), Is.EqualTo(1)); + Assert.That(MathToolsInteger.Factorial(1), Is.EqualTo(1)); } [Test] @@ -115,7 +115,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger03() { - Assert.That(IntegerMathTools.Factorial(2), Is.EqualTo(2)); + Assert.That(MathToolsInteger.Factorial(2), Is.EqualTo(2)); } [Test] @@ -123,7 +123,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger04() { - Assert.That(IntegerMathTools.Factorial(3), Is.EqualTo(6)); + Assert.That(MathToolsInteger.Factorial(3), Is.EqualTo(6)); } [Test] @@ -131,7 +131,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger05() { - Assert.That(IntegerMathTools.Factorial(4), Is.EqualTo(24)); + Assert.That(MathToolsInteger.Factorial(4), Is.EqualTo(24)); } [Test] @@ -139,7 +139,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger06() { - Assert.That(IntegerMathTools.Factorial(5), Is.EqualTo(120)); + Assert.That(MathToolsInteger.Factorial(5), Is.EqualTo(120)); } [Test] @@ -147,7 +147,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger07() { - Assert.That(IntegerMathTools.Factorial(6), Is.EqualTo(720)); + Assert.That(MathToolsInteger.Factorial(6), Is.EqualTo(720)); } [Test] @@ -155,7 +155,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger08() { - Assert.That(IntegerMathTools.Factorial(7), Is.EqualTo(5_040)); + Assert.That(MathToolsInteger.Factorial(7), Is.EqualTo(5_040)); } [Test] @@ -163,7 +163,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger09() { - Assert.That(IntegerMathTools.Factorial(8), Is.EqualTo(40_320)); + Assert.That(MathToolsInteger.Factorial(8), Is.EqualTo(40_320)); } [Test] @@ -171,7 +171,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger10() { - Assert.That(IntegerMathTools.Factorial(9), Is.EqualTo(362_880)); + Assert.That(MathToolsInteger.Factorial(9), Is.EqualTo(362_880)); } [Test] @@ -179,7 +179,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger11() { - Assert.That(IntegerMathTools.Factorial(10), Is.EqualTo(3_628_800)); + Assert.That(MathToolsInteger.Factorial(10), Is.EqualTo(3_628_800)); } [Test] @@ -187,7 +187,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger12() { - Assert.That(IntegerMathTools.Factorial(11), Is.EqualTo(39_916_800)); + Assert.That(MathToolsInteger.Factorial(11), Is.EqualTo(39_916_800)); } [Test] @@ -195,7 +195,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger13() { - Assert.That(IntegerMathTools.Factorial(12), Is.EqualTo(479_001_600)); + Assert.That(MathToolsInteger.Factorial(12), Is.EqualTo(479_001_600)); } [Test] @@ -203,7 +203,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger14() { - Assert.That(IntegerMathTools.Factorial(13), Is.EqualTo(6_227_020_800)); + Assert.That(MathToolsInteger.Factorial(13), Is.EqualTo(6_227_020_800)); } [Test] @@ -211,7 +211,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger15() { - Assert.That(IntegerMathTools.Factorial(14), Is.EqualTo(87_178_291_200)); + Assert.That(MathToolsInteger.Factorial(14), Is.EqualTo(87_178_291_200)); } [Test] @@ -219,7 +219,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger16() { - Assert.That(IntegerMathTools.Factorial(15), Is.EqualTo(1_307_674_368_000)); + Assert.That(MathToolsInteger.Factorial(15), Is.EqualTo(1_307_674_368_000)); } [Test] @@ -227,7 +227,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger17() { - Assert.That(IntegerMathTools.Factorial(16), Is.EqualTo(20_922_789_888_000)); + Assert.That(MathToolsInteger.Factorial(16), Is.EqualTo(20_922_789_888_000)); } [Test] @@ -235,7 +235,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger18() { - Assert.That(IntegerMathTools.Factorial(17), Is.EqualTo(355_687_428_096_000)); + Assert.That(MathToolsInteger.Factorial(17), Is.EqualTo(355_687_428_096_000)); } [Test] @@ -243,7 +243,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger19() { - Assert.That(IntegerMathTools.Factorial(18), Is.EqualTo(6_402_373_705_728_000)); + Assert.That(MathToolsInteger.Factorial(18), Is.EqualTo(6_402_373_705_728_000)); } [Test] @@ -251,7 +251,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger20() { - Assert.That(IntegerMathTools.Factorial(19), Is.EqualTo(121_645_100_408_832_000)); + Assert.That(MathToolsInteger.Factorial(19), Is.EqualTo(121_645_100_408_832_000)); } [Test] @@ -259,7 +259,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger21() { - Assert.That(IntegerMathTools.Factorial(20), Is.EqualTo(2_432_902_008_176_640_000)); + Assert.That(MathToolsInteger.Factorial(20), Is.EqualTo(2_432_902_008_176_640_000)); } [Test] @@ -267,7 +267,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger22() { - Assert.Throws(() => IntegerMathTools.Factorial(21)); + Assert.Throws(() => MathToolsInteger.Factorial(21)); // Note: 21! is not possible in C# until we got 128 bit integers, since: // ulong.max == 18_446_744_073_709_551_615 < 51_090_942_171_709_400_000 @@ -278,7 +278,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger23() { - Assert.Throws(() => IntegerMathTools.Factorial(45_646)); + Assert.Throws(() => MathToolsInteger.Factorial(45_646)); // Note: 45_646! is not possible in C# since: // ulong.max == 18_446_744_073_709_551_615 @@ -293,7 +293,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint01() { - Assert.That(FloatingPointMathTools.Factorial(0.5f), Is.EqualTo(0.886226925f).Within(1e6f)); + Assert.That(MathToolsFloatingPoint.Factorial(0.5f), Is.EqualTo(0.886226925f).Within(1e6f)); } [Test] @@ -301,7 +301,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint02() { - Assert.That(FloatingPointMathTools.Factorial(1.5f), Is.EqualTo(1.329340388f).Within(1e6f)); + Assert.That(MathToolsFloatingPoint.Factorial(1.5f), Is.EqualTo(1.329340388f).Within(1e6f)); } [Test] @@ -309,7 +309,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint03() { - Assert.That(FloatingPointMathTools.Factorial(-1.5f), Is.EqualTo(-1.329340388f).Within(1e6f)); + Assert.That(MathToolsFloatingPoint.Factorial(-1.5f), Is.EqualTo(-1.329340388f).Within(1e6f)); } [Test] @@ -317,7 +317,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint04() { - Assert.That(FloatingPointMathTools.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f)); + Assert.That(MathToolsFloatingPoint.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f)); } #endregion