Renamed math tools

This commit is contained in:
Thorsten Sommer 2023-07-10 19:26:25 +02:00
parent f39064dc05
commit 36c94be6d0
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
9 changed files with 46 additions and 46 deletions

View File

@ -16,7 +16,7 @@ public sealed class ChiSquareK1<TNum> : Distribution<TNum> where TNum : IFloatin
static ChiSquareK1()
{
var twoToTheKHalf = TNum.Pow(TWO, K_HALF);
var gammaKHalf = FloatingPointMathTools<TNum>.Gamma(K_HALF);
var gammaKHalf = MathToolsFloatingPoint<TNum>.Gamma(K_HALF);
DIVISOR = twoToTheKHalf * gammaKHalf;
}

View File

@ -16,7 +16,7 @@ public sealed class ChiSquareK10<TNum> : Distribution<TNum> where TNum : IFloati
static ChiSquareK10()
{
var twoToTheKHalf = TNum.Pow(TWO, K_HALF);
var gammaKHalf = FloatingPointMathTools<TNum>.Gamma(K_HALF);
var gammaKHalf = MathToolsFloatingPoint<TNum>.Gamma(K_HALF);
DIVISOR = twoToTheKHalf * gammaKHalf;
}

View File

@ -16,7 +16,7 @@ public sealed class ChiSquareK4<TNum> : Distribution<TNum> where TNum : IFloatin
static ChiSquareK4()
{
var twoToTheKHalf = TNum.Pow(TWO, K_HALF);
var gammaKHalf = FloatingPointMathTools<TNum>.Gamma(K_HALF);
var gammaKHalf = MathToolsFloatingPoint<TNum>.Gamma(K_HALF);
DIVISOR = twoToTheKHalf * gammaKHalf;
}

View File

@ -13,7 +13,7 @@ public sealed class GammaA5B15<TNum> : Distribution<TNum> where TNum : IFloating
static GammaA5B15()
{
GAMMA_ALPHA = FloatingPointMathTools<TNum>.Gamma(ALPHA);
GAMMA_ALPHA = MathToolsFloatingPoint<TNum>.Gamma(ALPHA);
BETA_TO_THE_ALPHA = TNum.Pow(BETA, ALPHA);
}

View File

@ -12,7 +12,7 @@ public sealed class InverseGammaA3B05<TNum> : Distribution<TNum> where TNum : IF
static InverseGammaA3B05()
{
var gammaAlpha = FloatingPointMathTools<TNum>.Gamma(ALPHA);
var gammaAlpha = MathToolsFloatingPoint<TNum>.Gamma(ALPHA);
var betaToTheAlpha = TNum.Pow(BETA, ALPHA);
FACTOR_LEFT = CONSTANT * (betaToTheAlpha / gammaAlpha);

View File

@ -17,8 +17,8 @@ public sealed class StudentTNu1<TNum> : Distribution<TNum> where TNum : IFloatin
static StudentTNu1()
{
DIVIDEND = FloatingPointMathTools<TNum>.Gamma((NU + TNum.One) * HALF);
DIVISOR = TNum.Sqrt(NU * TNum.Pi) * FloatingPointMathTools<TNum>.Gamma(NU * HALF);
DIVIDEND = MathToolsFloatingPoint<TNum>.Gamma((NU + TNum.One) * HALF);
DIVISOR = TNum.Sqrt(NU * TNum.Pi) * MathToolsFloatingPoint<TNum>.Gamma(NU * HALF);
EXPONENT = -((NU + TNum.One) * HALF);
}

View File

@ -5,7 +5,7 @@ namespace FastRng;
/// <summary>
/// Provides some mathematical function, which are not available within in .NET itself.
/// </summary>
public static class FloatingPointMathTools<TNum> where TNum : IFloatingPointIeee754<TNum>, IAdditionOperators<TNum, TNum, TNum>
public static class MathToolsFloatingPoint<TNum> where TNum : IFloatingPointIeee754<TNum>, IAdditionOperators<TNum, TNum, TNum>
{
private static readonly TNum SQRT_2 = TNum.Sqrt(TNum.One + TNum.One);
private static readonly TNum SQRT_PI = TNum.Sqrt(TNum.Pi);

View File

@ -5,7 +5,7 @@ namespace FastRng;
/// <summary>
/// Provides some mathematical function, which are not available within in .NET itself.
/// </summary>
public static class IntegerMathTools
public static class MathToolsInteger
{
/// <summary>
/// The mathematical factorial function for integer numbers.

View File

@ -15,7 +15,7 @@ public class MathToolsTests
[Category(TestCategories.NORMAL)]
public void GammaTest01()
{
Assert.That(FloatingPointMathTools<float>.Gamma(-0.5f), Is.EqualTo(-3.544907701811087f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(0.1f), Is.EqualTo(9.51350975f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(0.5f), Is.EqualTo(1.772453850905517f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(1.0f), Is.EqualTo(1.0f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(1.5f), Is.EqualTo(0.8862269254527587f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(2.0f), Is.EqualTo(1.0f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(3.0f), Is.EqualTo(2.0f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(10.0f), Is.EqualTo(362_880.719f).Within(1e-6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Gamma(140.0f), Is.EqualTo(float.NaN));
Assert.That(MathToolsFloatingPoint<float>.Gamma(140.0f), Is.EqualTo(float.NaN));
}
[Test]
@ -87,7 +87,7 @@ public class MathToolsTests
[Category(TestCategories.NORMAL)]
public void GammaTest10()
{
Assert.That(FloatingPointMathTools<float>.Gamma(170.0f), Is.EqualTo(float.NaN));
Assert.That(MathToolsFloatingPoint<float>.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<ArgumentOutOfRangeException>(() => IntegerMathTools.Factorial(21));
Assert.Throws<ArgumentOutOfRangeException>(() => 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<ArgumentOutOfRangeException>(() => IntegerMathTools.Factorial(45_646));
Assert.Throws<ArgumentOutOfRangeException>(() => 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<float>.Factorial(0.5f), Is.EqualTo(0.886226925f).Within(1e6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Factorial(1.5f), Is.EqualTo(1.329340388f).Within(1e6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Factorial(-1.5f), Is.EqualTo(-1.329340388f).Within(1e6f));
Assert.That(MathToolsFloatingPoint<float>.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<float>.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f));
Assert.That(MathToolsFloatingPoint<float>.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f));
}
#endregion