Skip to content

Commit 9c29b4c

Browse files
committed
Use constants where available
1 parent 3507015 commit 9c29b4c

8 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/Numerics.Tests/SpecialFunctionsTests/GammaTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class GammaTests
5252
[TestCase(1.0, 1.0, 15)]
5353
[TestCase(1.0 + 1.0e-14, 0.99999999999999422784335098477029953441189552403615306268023, 14)]
5454
[TestCase(1.5, 0.886226925452758013649083741670572591398774728061193564106903, 13)]
55-
[TestCase(Constants.Pi/2, 0.890560890381539328010659635359121005933541962884758999762766, 14)]
55+
[TestCase(Constants.PiOver2, 0.890560890381539328010659635359121005933541962884758999762766, 14)]
5656
[TestCase(2.0, 1.0, 16)]
5757
[TestCase(2.5, 1.329340388179137020473625612505858887098162092091790346160355, 14)]
5858
[TestCase(3.0, 2.0, 13)]
@@ -81,7 +81,7 @@ public void Gamma(double z, double expected, int decimalPlaces)
8181
[TestCase(1.0, 0.0, 14)]
8282
[TestCase(1.0 + 1.0e-14, -5.77215664901524635936177848990288632404978978079827014e-15, 0)]
8383
[TestCase(1.5, -0.12078223763524522234551844578164721225185272790259946836386, 13)]
84-
[TestCase(Constants.Pi/2, -0.11590380084550241329912089415904874214542604767006895, 13)]
84+
[TestCase(Constants.PiOver2, -0.11590380084550241329912089415904874214542604767006895, 13)]
8585
[TestCase(2.0, 0.0, 14)]
8686
[TestCase(2.5, 0.284682870472919159632494669682701924320137695559894729250145, 13)]
8787
[TestCase(3.0, 0.693147180559945309417232121458176568075500134360255254120680, 13)]

src/Numerics.Tests/SpecialFunctionsTests/SpecialFunctionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class SpecialFunctionsTests
4949
[TestCase(0.1, -10.423754940411076232100295314502760886768558023951363)]
5050
[TestCase(1.0, -0.57721566490153286060651209008240243104215933593992359)]
5151
[TestCase(1.5, 0.036489973978576520559023667001244432806840395339565888)]
52-
[TestCase(Constants.Pi / 2, 0.10067337642740238636795561404029690452798358068944001)]
52+
[TestCase(Constants.PiOver2, 0.10067337642740238636795561404029690452798358068944001)]
5353
[TestCase(2.0, 0.42278433509846713939348790991759756895784066406007641)]
5454
[TestCase(2.5, 0.70315664064524318722569033366791109947350706200623255)]
5555
[TestCase(3.0, 0.92278433509846713939348790991759756895784066406007641)]
@@ -75,7 +75,7 @@ public void DiGamma(double x, double f)
7575
[TestCase(0.1, -10.423754940411076232100295314502760886768558023951363)]
7676
[TestCase(1.0, -0.57721566490153286060651209008240243104215933593992359)]
7777
[TestCase(1.5, 0.036489973978576520559023667001244432806840395339565888)]
78-
[TestCase(Constants.Pi / 2, 0.10067337642740238636795561404029690452798358068944001)]
78+
[TestCase(Constants.PiOver2, 0.10067337642740238636795561404029690452798358068944001)]
7979
[TestCase(2.0, 0.42278433509846713939348790991759756895784066406007641)]
8080
[TestCase(2.5, 0.70315664064524318722569033366791109947350706200623255)]
8181
[TestCase(3.0, 0.92278433509846713939348790991759756895784066406007641)]

src/Numerics.Tests/StatisticsTests/CorrelationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void AutoCorrelationTest2()
9292
var tol = 1e-14;
9393
var n = 10;
9494
// make some dummy data
95-
var a = Generate.LinearSpacedMap(n, 0, 2*Constants.Pi, Math.Sin);
95+
var a = Generate.LinearSpacedMap(n, 0, Constants.Pi2, Math.Sin);
9696

9797
var idxs = new int[] { 2, 1, 7 };
9898

src/Numerics/Distributions/Cauchy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public double DensityLn(double x)
203203
/// <seealso cref="CDF"/>
204204
public double CumulativeDistribution(double x)
205205
{
206-
return ((1.0/Constants.Pi)*Math.Atan((x - _location)/_scale)) + 0.5;
206+
return Constants.InvPi*Math.Atan((x - _location)/_scale) + 0.5;
207207
}
208208

209209
/// <summary>

src/Numerics/Distributions/MatrixNormal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public double Density(Matrix<double> x)
195195
var cholK = _k.Cholesky();
196196

197197
return Math.Exp(-0.5*cholK.Solve(a.Transpose()*cholV.Solve(a)).Trace())
198-
/Math.Pow(2.0*Constants.Pi, x.RowCount*x.ColumnCount/2.0)
198+
/Math.Pow(Constants.Pi2, x.RowCount*x.ColumnCount/2.0)
199199
/Math.Pow(cholK.Determinant, x.RowCount/2.0)
200200
/Math.Pow(cholV.Determinant, x.ColumnCount/2.0);
201201
}

src/Numerics/Distributions/Poisson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public System.Random RandomSource
133133
/// Gets the entropy of the distribution.
134134
/// </summary>
135135
/// <remarks>Approximation, see Wikipedia <a href="http://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a></remarks>
136-
public double Entropy => (0.5*Math.Log(2*Constants.Pi*Constants.E*_lambda)) - (1.0/(12.0*_lambda)) - (1.0/(24.0*_lambda*_lambda)) - (19.0/(360.0*_lambda*_lambda*_lambda));
136+
public double Entropy => (0.5*Math.Log(Constants.Pi2*Constants.E*_lambda)) - (1.0/(12.0*_lambda)) - (1.0/(24.0*_lambda*_lambda)) - (19.0/(360.0*_lambda*_lambda*_lambda));
137137

138138
/// <summary>
139139
/// Gets the skewness of the distribution.

src/Numerics/Distributions/SkewedGeneralizedError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static double AdjustX(double x, double scale, double skew, double p)
212212
static double AdjustAddend(double scale, double skew, double p)
213213
{
214214
return (Math.Pow(2.0, 2.0 / p) * scale * skew * SpecialFunctions.Gamma(1.0 / 2.0 + 1.0 / p)) /
215-
Math.Sqrt(Constants.Pi);
215+
Constants.SqrtPi;
216216
}
217217

218218
public static double PDF(double location, double scale, double skew, double p, double x)

src/Numerics/RootFinding/Cubic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public static Tuple<double, double, double> RealRoots(double a0, double a1, doub
9494
// 3 real roots, use eqn (70)-(73) to calculate the real roots
9595
double theta = Math.Acos(R/Math.Sqrt(-Q3));
9696
x1 = 2d*Math.Sqrt(-Q)*Math.Cos(theta/3.0) + shift;
97-
x2 = 2d*Math.Sqrt(-Q)*Math.Cos((theta + 2.0*Constants.Pi)/3d) + shift;
98-
x3 = 2d*Math.Sqrt(-Q)*Math.Cos((theta - 2.0*Constants.Pi)/3d) + shift;
97+
x2 = 2d*Math.Sqrt(-Q)*Math.Cos((theta + Constants.Pi2)/3d) + shift;
98+
x3 = 2d*Math.Sqrt(-Q)*Math.Cos((theta - Constants.Pi2)/3d) + shift;
9999
}
100100

101101
return new Tuple<double, double, double>(x1, x2, x3);

0 commit comments

Comments
 (0)