diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings
index db547745..a97eba6c 100644
--- a/MathNet.Numerics.sln.DotSettings
+++ b/MathNet.Numerics.sln.DotSettings
@@ -63,6 +63,7 @@ OTHER DEALINGS IN THE SOFTWARE.
SAS
SPSS
SSD
+ SVD
TFQMR
WH
<data />
diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs
index 3940d721..9a41fab9 100644
--- a/src/Numerics/Complex32.cs
+++ b/src/Numerics/Complex32.cs
@@ -72,7 +72,7 @@ namespace MathNet.Numerics
///
[Serializable]
[StructLayout(LayoutKind.Sequential)]
- public struct Complex32 : IFormattable, IEquatable, IPrecisionSupport
+ public struct Complex32 : IFormattable, IEquatable
{
///
/// The real component of the complex number.
@@ -792,37 +792,6 @@ namespace MathNet.Numerics
#endregion
- #region IPrecisionSupport
-
- ///
- /// Returns a Norm of a value of this type, which is appropriate for measuring how
- /// close this value is to zero.
- ///
- ///
- /// A norm of this value.
- ///
- double IPrecisionSupport.Norm()
- {
- return MagnitudeSquared;
- }
-
- ///
- /// Returns a Norm of the difference of two values of this type, which is
- /// appropriate for measuring how close together these two values are.
- ///
- ///
- /// The value to compare with.
- ///
- ///
- /// A norm of the difference between this and the other value.
- ///
- double IPrecisionSupport.NormOfDifference(Complex32 otherValue)
- {
- return (this - otherValue).MagnitudeSquared;
- }
-
- #endregion
-
#region Parse Functions
///
diff --git a/src/Numerics/ComplexExtensions.cs b/src/Numerics/ComplexExtensions.cs
index 3cc80638..4808ff67 100644
--- a/src/Numerics/ComplexExtensions.cs
+++ b/src/Numerics/ComplexExtensions.cs
@@ -376,25 +376,38 @@ namespace MathNet.Numerics
/// Returns a Norm of a value of this type, which is appropriate for measuring how
/// close this value is to zero.
///
- /// The number to perfom this operation on.
- /// A norm of this value.
public static double Norm(this Complex complex)
{
return complex.MagnitudeSquared();
}
+ ///
+ /// Returns a Norm of a value of this type, which is appropriate for measuring how
+ /// close this value is to zero.
+ ///
+ public static double Norm(this Complex32 complex)
+ {
+ return complex.MagnitudeSquared;
+ }
+
///
/// Returns a Norm of the difference of two values of this type, which is
/// appropriate for measuring how close together these two values are.
///
- /// The number to perfom this operation on.
- /// The value to compare with.
- /// A norm of the difference between this and the other value.
public static double NormOfDifference(this Complex complex, Complex otherValue)
{
return (complex - otherValue).MagnitudeSquared();
}
+ ///
+ /// Returns a Norm of the difference of two values of this type, which is
+ /// appropriate for measuring how close together these two values are.
+ ///
+ public static double NormOfDifference(this Complex32 complex, Complex32 otherValue)
+ {
+ return (complex - otherValue).MagnitudeSquared;
+ }
+
///
/// Creates a complex number based on a string. The string can be in the
/// following formats (without the quotes): 'n', 'ni', 'n +/- ni',
diff --git a/src/Numerics/Distributions/Dirichlet.cs b/src/Numerics/Distributions/Dirichlet.cs
index 72c9d607..d67da14a 100644
--- a/src/Numerics/Distributions/Dirichlet.cs
+++ b/src/Numerics/Distributions/Dirichlet.cs
@@ -303,7 +303,7 @@ namespace MathNet.Numerics.Distributions
term += (_alpha[_alpha.Length - 1] - 1.0)*Math.Log(1.0 - sumxi) - SpecialFunctions.GammaLn(_alpha[_alpha.Length - 1]);
sumalpha += _alpha[_alpha.Length - 1];
}
- else if (!sumxi.AlmostEqualInDecimalPlaces(1.0, 8))
+ else if (!sumxi.AlmostEqualRelative(1.0, 8))
{
return 0.0;
}
diff --git a/src/Numerics/Integration/NewtonCotesTrapeziumRule.cs b/src/Numerics/Integration/NewtonCotesTrapeziumRule.cs
index 59f18eb4..d02037f5 100644
--- a/src/Numerics/Integration/NewtonCotesTrapeziumRule.cs
+++ b/src/Numerics/Integration/NewtonCotesTrapeziumRule.cs
@@ -124,7 +124,7 @@ namespace MathNet.Numerics.Integration
step *= 0.5;
numberOfPartitions *= 2;
- if (sum.AlmostEqualWithError(midpointsum, targetError))
+ if (sum.AlmostEqualRelative(midpointsum, targetError))
{
break;
}
@@ -222,7 +222,7 @@ namespace MathNet.Numerics.Integration
delta = Math.Sqrt(delta);
}
- if (sum.AlmostEqualWithRelativeError(midpointsum, delta, targetRelativeError))
+ if (sum.AlmostEqualNormRelative(midpointsum, delta, targetRelativeError))
{
break;
}
diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs
index 7c95bf3a..fae5f588 100644
--- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs
@@ -369,7 +369,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
{
test = s[l].Magnitude + s[l + 1].Magnitude;
ztest = test + e[l].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
e[l] = Complex.Zero;
break;
@@ -398,7 +398,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
}
ztest = test + s[ls].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
s[ls] = Complex.Zero;
break;
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs
index b09df01e..8ec28c16 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/BiCgStab.cs
@@ -164,7 +164,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// if (rho_(i-1) == 0) // METHOD FAILS
// If rho is only 1 ULP from zero then we fail.
- if (currentRho.Real.AlmostEqual(0, 1) && currentRho.Imaginary.AlmostEqual(0, 1))
+ if (currentRho.Real.AlmostEqualNumbersBetween(0, 1) && currentRho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// Rho-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
@@ -258,7 +258,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// for continuation it is necessary that omega_i != 0.0
// If omega is only 1 ULP from zero then we fail.
- if (omega.Real.AlmostEqual(0, 1) && omega.Imaginary.AlmostEqual(0, 1))
+ if (omega.Real.AlmostEqualNumbersBetween(0, 1) && omega.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// Omega-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
index 1644b7bc..af1fcd99 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/GpBiCg.cs
@@ -267,7 +267,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// We'll set cDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// c.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (cdot.Real.AlmostEqual(0, 1) && cdot.Imaginary.AlmostEqual(0, 1))
+ if (cdot.Real.AlmostEqualNumbersBetween(0, 1) && cdot.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
cdot = 1.0;
}
@@ -295,7 +295,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// We'll set yDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// y.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (ydot.Real.AlmostEqual(0, 1) && ydot.Imaginary.AlmostEqual(0, 1))
+ if (ydot.Real.AlmostEqualNumbersBetween(0, 1) && ydot.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
ydot = 1.0;
}
@@ -355,7 +355,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// beta_k = alpha_k / sigma_k * (r*_0 * r_(k+1)) / (r*_0 * r_k)
// But first we check if there is a possible NaN. If so just reset beta to zero.
- beta = (!sigma.Real.AlmostEqual(0, 1) || !sigma.Imaginary.AlmostEqual(0, 1)) ? alpha/sigma*rdash.ConjugateDotProduct(residuals)/rdash.ConjugateDotProduct(t0) : 0;
+ beta = (!sigma.Real.AlmostEqualNumbersBetween(0, 1) || !sigma.Imaginary.AlmostEqualNumbersBetween(0, 1)) ? alpha/sigma*rdash.ConjugateDotProduct(residuals)/rdash.ConjugateDotProduct(t0) : 0;
// w_k = c_k + beta_k s_k
s.Multiply(beta, temp2);
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
index 28a992a4..1339c6db 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/MlkBiCgStab.cs
@@ -343,7 +343,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// c_((j-1)k+k) = q^T_1 w_((j-1)k+k)
c[k - 1] = _startingVectors[0].ConjugateDotProduct(w[k - 1]);
- if (c[k - 1].Real.AlmostEqual(0, 1) && c[k - 1].Imaginary.AlmostEqual(0, 1))
+ if (c[k - 1].Real.AlmostEqualNumbersBetween(0, 1) && c[k - 1].Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -366,7 +366,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// If rho is zero then temp is a zero vector and we're probably
// about to have zero residuals (i.e. an exact solution).
// So set rho to 1.0 because in the next step it will turn to zero.
- if (rho.Real.AlmostEqual(0, 1) && rho.Imaginary.AlmostEqual(0, 1))
+ if (rho.Real.AlmostEqualNumbersBetween(0, 1) && rho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
rho = 1.0;
}
@@ -444,7 +444,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
}
beta = rho*c[k - 1];
- if (beta.Real.AlmostEqual(0, 1) && beta.Imaginary.AlmostEqual(0, 1))
+ if (beta.Real.AlmostEqualNumbersBetween(0, 1) && beta.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -496,7 +496,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
// c_(jk+1) = q^T_i+1 d_(jk+i)
c[i] = _startingVectors[i + 1].ConjugateDotProduct(d[i]);
- if (c[i].Real.AlmostEqual(0, 1) && c[i].Imaginary.AlmostEqual(0, 1))
+ if (c[i].Real.AlmostEqualNumbersBetween(0, 1) && c[i].Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs
index 38854692..ee442ea4 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/ResidualStopCriterium.cs
@@ -233,7 +233,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// ||r_i|| <= stop_tol * ||b||
// Stop the calculation if it's clearly smaller than the tolerance
var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1;
- if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude))
+ if (residualNorm.IsSmallerDecimal(stopCriterium, decimalMagnitude))
{
if (_lastIteration <= iterationNumber)
{
diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs
index fe11bb58..0cee1ca4 100644
--- a/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Complex/Solvers/TFQMR.cs
@@ -167,7 +167,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
{
// sigma = (v, r)
var sigma = r.ConjugateDotProduct(v);
- if (sigma.Real.AlmostEqual(0, 1) && sigma.Imaginary.AlmostEqual(0, 1))
+ if (sigma.Real.AlmostEqualNumbersBetween(0, 1) && sigma.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
@@ -240,7 +240,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers
// The odd step
if (!IsEven(iterationNumber))
{
- if (rho.Real.AlmostEqual(0, 1) && rho.Imaginary.AlmostEqual(0, 1))
+ if (rho.Real.AlmostEqualNumbersBetween(0, 1) && rho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs
index 5987de87..b2acf111 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs
@@ -364,7 +364,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
{
test = s[l].Magnitude + s[l + 1].Magnitude;
ztest = test + e[l].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
e[l] = Complex32.Zero;
break;
@@ -393,7 +393,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
}
ztest = test + s[ls].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
s[ls] = Complex32.Zero;
break;
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs
index f6eedb5d..756a076d 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/BiCgStab.cs
@@ -157,7 +157,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// if (rho_(i-1) == 0) // METHOD FAILS
// If rho is only 1 ULP from zero then we fail.
- if (currentRho.Real.AlmostEqual(0, 1) && currentRho.Imaginary.AlmostEqual(0, 1))
+ if (currentRho.Real.AlmostEqualNumbersBetween(0, 1) && currentRho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// Rho-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
@@ -251,7 +251,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// for continuation it is necessary that omega_i != 0.0f
// If omega is only 1 ULP from zero then we fail.
- if (omega.Real.AlmostEqual(0, 1) && omega.Imaginary.AlmostEqual(0, 1))
+ if (omega.Real.AlmostEqualNumbersBetween(0, 1) && omega.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// Omega-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
index 65817d2c..5218ba17 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/GpBiCg.cs
@@ -265,7 +265,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// We'll set cDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// c.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (cdot.Real.AlmostEqual(0, 1) && cdot.Imaginary.AlmostEqual(0, 1))
+ if (cdot.Real.AlmostEqualNumbersBetween(0, 1) && cdot.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
cdot = 1.0f;
}
@@ -293,7 +293,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// We'll set yDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// y.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (ydot.Real.AlmostEqual(0, 1) && ydot.Imaginary.AlmostEqual(0, 1))
+ if (ydot.Real.AlmostEqualNumbersBetween(0, 1) && ydot.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
ydot = 1.0f;
}
@@ -353,7 +353,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// beta_k = alpha_k / sigma_k * (r*_0 * r_(k+1)) / (r*_0 * r_k)
// But first we check if there is a possible NaN. If so just reset beta to zero.
- beta = (!sigma.Real.AlmostEqual(0, 1) || !sigma.Imaginary.AlmostEqual(0, 1)) ? alpha/sigma*rdash.ConjugateDotProduct(residuals)/rdash.ConjugateDotProduct(t0) : 0;
+ beta = (!sigma.Real.AlmostEqualNumbersBetween(0, 1) || !sigma.Imaginary.AlmostEqualNumbersBetween(0, 1)) ? alpha/sigma*rdash.ConjugateDotProduct(residuals)/rdash.ConjugateDotProduct(t0) : 0;
// w_k = c_k + beta_k s_k
s.Multiply(beta, temp2);
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
index 181c50dd..8fba9de9 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/MlkBiCgStab.cs
@@ -341,7 +341,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// c_((j-1)k+k) = q^T_1 w_((j-1)k+k)
c[k - 1] = _startingVectors[0].ConjugateDotProduct(w[k - 1]);
- if (c[k - 1].Real.AlmostEqual(0, 1) && c[k - 1].Imaginary.AlmostEqual(0, 1))
+ if (c[k - 1].Real.AlmostEqualNumbersBetween(0, 1) && c[k - 1].Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -364,7 +364,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// If rho is zero then temp is a zero vector and we're probably
// about to have zero residuals (i.e. an exact solution).
// So set rho to 1.0 because in the next step it will turn to zero.
- if (rho.Real.AlmostEqual(0, 1) && rho.Imaginary.AlmostEqual(0, 1))
+ if (rho.Real.AlmostEqualNumbersBetween(0, 1) && rho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
rho = 1.0f;
}
@@ -442,7 +442,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
}
beta = rho*c[k - 1];
- if (beta.Real.AlmostEqual(0, 1) && beta.Imaginary.AlmostEqual(0, 1))
+ if (beta.Real.AlmostEqualNumbersBetween(0, 1) && beta.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -494,7 +494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
// c_(jk+1) = q^T_i+1 d_(jk+i)
c[i] = _startingVectors[i + 1].ConjugateDotProduct(d[i]);
- if (c[i].Real.AlmostEqual(0, 1) && c[i].Imaginary.AlmostEqual(0, 1))
+ if (c[i].Real.AlmostEqualNumbersBetween(0, 1) && c[i].Imaginary.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs
index d174ce8d..7f402be0 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/ResidualStopCriterium.cs
@@ -228,7 +228,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// ||r_i|| <= stop_tol * ||b||
// Stop the calculation if it's clearly smaller than the tolerance
var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1;
- if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude))
+ if (residualNorm.IsSmallerDecimal(stopCriterium, decimalMagnitude))
{
if (_lastIteration <= iterationNumber)
{
diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs
index 3608f74a..1c77e259 100644
--- a/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/TFQMR.cs
@@ -164,7 +164,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
{
// sigma = (v, r)
var sigma = r.ConjugateDotProduct(v);
- if (sigma.Real.AlmostEqual(0, 1) && sigma.Imaginary.AlmostEqual(0, 1))
+ if (sigma.Real.AlmostEqualNumbersBetween(0, 1) && sigma.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
@@ -237,7 +237,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers
// The odd step
if (!IsEven(iterationNumber))
{
- if (rho.Real.AlmostEqual(0, 1) && rho.Imaginary.AlmostEqual(0, 1))
+ if (rho.Real.AlmostEqualNumbersBetween(0, 1) && rho.Imaginary.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs
index b92b5cf9..186b799d 100644
--- a/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs
+++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs
@@ -348,7 +348,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
test = Math.Abs(s[l]) + Math.Abs(s[l + 1]);
ztest = test + Math.Abs(e[l]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
e[l] = 0.0;
break;
@@ -377,7 +377,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
}
ztest = test + Math.Abs(s[ls]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
s[ls] = 0.0;
break;
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs
index 7443ef50..50ca954c 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/BiCgStab.cs
@@ -157,7 +157,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// if (rho_(i-1) == 0) // METHOD FAILS
// If rho is only 1 ULP from zero then we fail.
- if (currentRho.AlmostEqual(0, 1))
+ if (currentRho.AlmostEqualNumbersBetween(0, 1))
{
// Rho-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
@@ -251,7 +251,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// for continuation it is necessary that omega_i != 0.0
// If omega is only 1 ULP from zero then we fail.
- if (omega.AlmostEqual(0, 1))
+ if (omega.AlmostEqualNumbersBetween(0, 1))
{
// Omega-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
index e5154630..ab7513f0 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/GpBiCg.cs
@@ -271,7 +271,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// We'll set cDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// c.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (cdot.AlmostEqual(0, 1))
+ if (cdot.AlmostEqualNumbersBetween(0, 1))
{
cdot = 1.0;
}
@@ -299,7 +299,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// We'll set yDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// y.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (ydot.AlmostEqual(0, 1))
+ if (ydot.AlmostEqualNumbersBetween(0, 1))
{
ydot = 1.0;
}
@@ -359,7 +359,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// beta_k = alpha_k / sigma_k * (r*_0 * r_(k+1)) / (r*_0 * r_k)
// But first we check if there is a possible NaN. If so just reset beta to zero.
- beta = (!sigma.AlmostEqual(0, 1)) ? alpha/sigma*rdash.DotProduct(residuals)/rdash.DotProduct(t0) : 0;
+ beta = (!sigma.AlmostEqualNumbersBetween(0, 1)) ? alpha/sigma*rdash.DotProduct(residuals)/rdash.DotProduct(t0) : 0;
// w_k = c_k + beta_k s_k
s.Multiply(beta, temp2);
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
index d3e9eb25..446ba02a 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/MlkBiCgStab.cs
@@ -341,7 +341,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// c_((j-1)k+k) = q^T_1 w_((j-1)k+k)
c[k - 1] = _startingVectors[0].DotProduct(w[k - 1]);
- if (c[k - 1].AlmostEqual(0, 1))
+ if (c[k - 1].AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -364,7 +364,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// If rho is zero then temp is a zero vector and we're probably
// about to have zero residuals (i.e. an exact solution).
// So set rho to 1.0 because in the next step it will turn to zero.
- if (rho.AlmostEqual(0, 1))
+ if (rho.AlmostEqualNumbersBetween(0, 1))
{
rho = 1.0;
}
@@ -442,7 +442,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
}
beta = rho*c[k - 1];
- if (beta.AlmostEqual(0, 1))
+ if (beta.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -494,7 +494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
{
// c_(jk+1) = q^T_i+1 d_(jk+i)
c[i] = _startingVectors[i + 1].DotProduct(d[i]);
- if (c[i].AlmostEqual(0, 1))
+ if (c[i].AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Double/Solvers/ResidualStopCriterium.cs
index 02b9f2d8..4ebce201 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/ResidualStopCriterium.cs
@@ -226,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// ||r_i|| <= stop_tol * ||b||
// Stop the calculation if it's clearly smaller than the tolerance
var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1;
- if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude))
+ if (residualNorm.IsSmallerDecimal(stopCriterium, decimalMagnitude))
{
if (_lastIteration <= iterationNumber)
{
diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs
index bf33f8de..6c803d74 100644
--- a/src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Double/Solvers/TFQMR.cs
@@ -164,7 +164,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
{
// sigma = (v, r)
var sigma = v.DotProduct(r);
- if (sigma.AlmostEqual(0, 1))
+ if (sigma.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
@@ -237,7 +237,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers
// The odd step
if (!IsEven(iterationNumber))
{
- if (rho.AlmostEqual(0, 1))
+ if (rho.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs
index ce0753a4..2d8098a2 100644
--- a/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs
+++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs
@@ -348,7 +348,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
test = Math.Abs(s[l]) + Math.Abs(s[l + 1]);
ztest = test + Math.Abs(e[l]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
e[l] = 0.0f;
break;
@@ -377,7 +377,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
}
ztest = test + Math.Abs(s[ls]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
s[ls] = 0.0f;
break;
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs
index 066c300f..5874afc9 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/BiCgStab.cs
@@ -157,7 +157,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// if (rho_(i-1) == 0) // METHOD FAILS
// If rho is only 1 ULP from zero then we fail.
- if (currentRho.AlmostEqual(0, 1))
+ if (currentRho.AlmostEqualNumbersBetween(0, 1))
{
// Rho-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
@@ -251,7 +251,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// for continuation it is necessary that omega_i != 0.0
// If omega is only 1 ULP from zero then we fail.
- if (omega.AlmostEqual(0, 1))
+ if (omega.AlmostEqualNumbersBetween(0, 1))
{
// Omega-type breakdown
throw new Exception("Iterative solver experience a numerical break down");
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs b/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
index 246044fa..ebb486fa 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/GpBiCg.cs
@@ -265,7 +265,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// We'll set cDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// c.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (cdot.AlmostEqual(0, 1))
+ if (cdot.AlmostEqualNumbersBetween(0, 1))
{
cdot = 1.0f;
}
@@ -293,7 +293,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// We'll set yDot to 1 if it is zero to prevent NaN's
// Note that the calculation should continue fine because
// y.DotProduct(t) will be zero and so will c.DotProduct(y)
- if (ydot.AlmostEqual(0, 1))
+ if (ydot.AlmostEqualNumbersBetween(0, 1))
{
ydot = 1.0f;
}
@@ -353,7 +353,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// beta_k = alpha_k / sigma_k * (r*_0 * r_(k+1)) / (r*_0 * r_k)
// But first we check if there is a possible NaN. If so just reset beta to zero.
- beta = (!sigma.AlmostEqual(0, 1)) ? alpha/sigma*rdash.DotProduct(residuals)/rdash.DotProduct(t0) : 0;
+ beta = (!sigma.AlmostEqualNumbersBetween(0, 1)) ? alpha/sigma*rdash.DotProduct(residuals)/rdash.DotProduct(t0) : 0;
// w_k = c_k + beta_k s_k
s.Multiply(beta, temp2);
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
index c0f5555a..25fa5230 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/MlkBiCgStab.cs
@@ -344,7 +344,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// c_((j-1)k+k) = q^T_1 w_((j-1)k+k)
c[k - 1] = _startingVectors[0].DotProduct(w[k - 1]);
- if (c[k - 1].AlmostEqual(0, 1))
+ if (c[k - 1].AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -367,7 +367,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// If rho is zero then temp is a zero vector and we're probably
// about to have zero residuals (i.e. an exact solution).
// So set rho to 1.0 because in the next step it will turn to zero.
- if (rho.AlmostEqual(0, 1))
+ if (rho.AlmostEqualNumbersBetween(0, 1))
{
rho = 1.0f;
}
@@ -445,7 +445,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
}
beta = rho*c[k - 1];
- if (beta.AlmostEqual(0, 1))
+ if (beta.AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
@@ -497,7 +497,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
{
// c_(jk+1) = q^T_i+1 d_(jk+i)
c[i] = _startingVectors[i + 1].DotProduct(d[i]);
- if (c[i].AlmostEqual(0, 1))
+ if (c[i].AlmostEqualNumbersBetween(0, 1))
{
throw new Exception("Iterative solver experience a numerical break down");
}
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs b/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs
index e55391cd..ed3dc421 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/ResidualStopCriterium.cs
@@ -226,7 +226,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// ||r_i|| <= stop_tol * ||b||
// Stop the calculation if it's clearly smaller than the tolerance
var decimalMagnitude = Math.Abs(stopCriterium.Magnitude()) + 1;
- if (residualNorm.IsSmallerWithDecimalPlaces(stopCriterium, decimalMagnitude))
+ if (residualNorm.IsSmallerDecimal(stopCriterium, decimalMagnitude))
{
if (_lastIteration <= iterationNumber)
{
diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs b/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs
index efc774e3..2420bc33 100644
--- a/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs
+++ b/src/Numerics/LinearAlgebra/Single/Solvers/TFQMR.cs
@@ -164,7 +164,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
{
// sigma = (v, r)
var sigma = v.DotProduct(r);
- if (sigma.AlmostEqual(0, 1))
+ if (sigma.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
@@ -237,7 +237,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers
// The odd step
if (!IsEven(iterationNumber))
{
- if (rho.AlmostEqual(0, 1))
+ if (rho.AlmostEqualNumbersBetween(0, 1))
{
// FAIL HERE
iterator.Cancel();
diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj
index c29be0c3..bbd56164 100644
--- a/src/Numerics/Numerics.csproj
+++ b/src/Numerics/Numerics.csproj
@@ -86,6 +86,7 @@
+
diff --git a/src/Numerics/Precision.Equality.cs b/src/Numerics/Precision.Equality.cs
new file mode 100644
index 00000000..c1ed6dfc
--- /dev/null
+++ b/src/Numerics/Precision.Equality.cs
@@ -0,0 +1,1049 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
+// http://mathnetnumerics.codeplex.com
+//
+// Copyright (c) 2009-2010 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+#if PORTABLE
+using System.Runtime.InteropServices;
+#endif
+using MathNet.Numerics.LinearAlgebra;
+
+namespace MathNet.Numerics
+{
+
+#if !NOSYSNUMERICS
+ using Complex = System.Numerics.Complex;
+#endif
+
+ public static partial class Precision
+ {
+ ///
+ /// Compares two doubles and determines if they are equal
+ /// within the specified maximum absolute error.
+ ///
+ /// The norm of the first value (can be negative).
+ /// The norm of the second value (can be negative).
+ /// The norm of the difference of the two values (can be negative).
+ /// The absolute accuracy required for being almost equal.
+ /// True if both doubles are almost equal up to the specified maximum absolute error, false otherwise.
+ public static bool AlmostEqualNorm(this double a, double b, double diff, double maximumAbsoluteError)
+ {
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (double.IsInfinity(a) || double.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (double.IsNaN(a) || double.IsNaN(b))
+ {
+ return false;
+ }
+
+ return Math.Abs(diff) < maximumAbsoluteError;
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal
+ /// within the specified maximum absolute error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The absolute accuracy required for being almost equal.
+ /// True if both doubles are almost equal up to the specified maximum absolute error, false otherwise.
+ public static bool AlmostEqualNorm(this T a, T b, double maximumAbsoluteError)
+ where T : IPrecisionSupport
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal
+ /// within the specified maximum error.
+ ///
+ /// The norm of the first value (can be negative).
+ /// The norm of the second value (can be negative).
+ /// The norm of the difference of the two values (can be negative).
+ /// The accuracy required for being almost equal.
+ /// True if both doubles are almost equal up to the specified maximum error, false otherwise.
+ public static bool AlmostEqualNormRelative(this double a, double b, double diff, double maximumError)
+ {
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (double.IsInfinity(a) || double.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (double.IsNaN(a) || double.IsNaN(b))
+ {
+ return false;
+ }
+
+ // If one is almost zero, fall back to absolute equality
+ if (Math.Abs(a) < DoublePrecision || Math.Abs(b) < DoublePrecision)
+ {
+ return AlmostEqualNorm(a, b, diff, maximumError);
+ }
+
+ if ((a == 0 && Math.Abs(b) < maximumError) || (b == 0 && Math.Abs(a) < maximumError))
+ {
+ return true;
+ }
+
+ return Math.Abs(diff) < maximumError * Math.Max(Math.Abs(a), Math.Abs(b));
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal
+ /// within the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ /// True if both doubles are almost equal up to the specified maximum error, false otherwise.
+ public static bool AlmostEqualNormRelative(this T a, T b, double maximumError)
+ where T : IPrecisionSupport
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumError);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqual(this double a, double b, double maximumAbsoluteError)
+ {
+ return AlmostEqualNorm(a, b, a - b, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqual(this float a, float b, double maximumAbsoluteError)
+ {
+ return AlmostEqualNorm(a, b, a - b, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqual(this Complex a, Complex b, double maximumAbsoluteError)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqual(this Complex32 a, Complex32 b, double maximumAbsoluteError)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqualRelative(this double a, double b, double maximumError)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, maximumError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqualRelative(this float a, float b, double maximumError)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, maximumError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqualRelative(this Complex a, Complex b, double maximumError)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumError);
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqualRelative(this Complex32 a, Complex32 b, double maximumError)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumError);
+ }
+
+ ///
+ /// Checks whether two real numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqual(this double a, double b)
+ {
+ return AlmostEqualNorm(a, b, a - b, DefaultDoubleAccuracy);
+ }
+
+ ///
+ /// Checks whether two real numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqual(this float a, float b)
+ {
+ return AlmostEqualNorm(a, b, a - b, DefaultSingleAccuracy);
+ }
+
+ ///
+ /// Checks whether two Compex numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqual(this Complex a, Complex b)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), DefaultDoubleAccuracy);
+ }
+
+ ///
+ /// Checks whether two Compex numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqual(this Complex32 a, Complex32 b)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), DefaultSingleAccuracy);
+ }
+
+ ///
+ /// Checks whether two real numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqualRelative(this double a, double b)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, DefaultDoubleAccuracy);
+ }
+
+ ///
+ /// Checks whether two real numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqualRelative(this float a, float b)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, DefaultSingleAccuracy);
+ }
+
+ ///
+ /// Checks whether two Compex numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqualRelative(this Complex a, Complex b)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), DefaultDoubleAccuracy);
+ }
+
+ ///
+ /// Checks whether two Compex numbers are almost equal.
+ ///
+ /// The first number
+ /// The second number
+ /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
+ public static bool AlmostEqualRelative(this Complex32 a, Complex32 b)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), DefaultSingleAccuracy);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ ///
+ ///
+ /// The values are equal if the difference between the two numbers is smaller than 0.5e-decimalPlaces. We divide by
+ /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
+ /// 0.005 and 0.015, but not 0.02 and not 0.00
+ ///
+ ///
+ /// The norm of the first value (can be negative).
+ /// The norm of the second value (can be negative).
+ /// The norm of the difference of the two values (can be negative).
+ /// The number of decimal places.
+ public static bool AlmostEqualNorm(this double a, double b, double diff, int decimalPlaces)
+ {
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (double.IsNaN(a) || double.IsNaN(b))
+ {
+ return false;
+ }
+
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (double.IsInfinity(a) || double.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // The values are equal if the difference between the two numbers is smaller than
+ // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
+ // on each side of the numbers, e.g. if decimalPlaces == 2,
+ // then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
+ double decimalPlaceMagnitude = Math.Pow(10, -decimalPlaces) / 2d;
+ return Math.Abs(diff) < decimalPlaceMagnitude;
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ ///
+ ///
+ /// The values are equal if the difference between the two numbers is smaller than 0.5e-decimalPlaces. We divide by
+ /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
+ /// 0.005 and 0.015, but not 0.02 and not 0.00
+ ///
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualNorm(this T a, T b, int decimalPlaces)
+ where T : IPrecisionSupport
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ ///
+ ///
+ /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
+ /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
+ /// 0.005 and 0.015, but not 0.02 and not 0.00
+ ///
+ ///
+ /// The norm of the first value (can be negative).
+ /// The norm of the second value (can be negative).
+ /// The norm of the difference of the two values (can be negative).
+ /// Thrown if is smaller than zero.
+ public static bool AlmostEqualNormRelative(this double a, double b, double diff, int decimalPlaces)
+ {
+ if (decimalPlaces < 0)
+ {
+ // Can't have a negative number of decimal places
+ throw new ArgumentOutOfRangeException("decimalPlaces");
+ }
+
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (double.IsNaN(a) || double.IsNaN(b))
+ {
+ return false;
+ }
+
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (double.IsInfinity(a) || double.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // If both numbers are equal, get out now. This should remove the possibility of both numbers being zero
+ // and any problems associated with that.
+ if (a.Equals(b))
+ {
+ return true;
+ }
+
+ // If one is almost zero, fall back to absolute equality
+ if (Math.Abs(a) < DoublePrecision || Math.Abs(b) < DoublePrecision)
+ {
+ // The values are equal if the difference between the two numbers is smaller than
+ // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
+ // on each side of the numbers, e.g. if decimalPlaces == 2,
+ // then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
+ double decimalPlaceMagnitude = Math.Pow(10, -decimalPlaces) / 2d;
+ return Math.Abs(diff) < decimalPlaceMagnitude;
+ }
+
+ // If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal
+ int magnitudeOfFirst = Magnitude(a);
+ int magnitudeOfSecond = Magnitude(b);
+ int magnitudeOfMax = Math.Max(magnitudeOfFirst, magnitudeOfSecond);
+ if (magnitudeOfMax > (Math.Min(magnitudeOfFirst, magnitudeOfSecond) + 1))
+ {
+ return false;
+ }
+
+ // The values are equal if the difference between the two numbers is smaller than
+ // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
+ // on each side of the numbers, e.g. if decimalPlaces == 2,
+ // then 0.01 will equal between 0.00995 and 0.01005, but not 0.0015 and not 0.0095
+ double decimalPlaceMagnitude1 = Math.Pow(10, magnitudeOfMax - decimalPlaces) / 2d;
+ return Math.Abs(diff) < decimalPlaceMagnitude1;
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ ///
+ ///
+ /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
+ /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
+ /// 0.005 and 0.015, but not 0.02 and not 0.00
+ ///
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualNormRelative(this T a, T b, int decimalPlaces)
+ where T : IPrecisionSupport
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqual(this double a, double b, int decimalPlaces)
+ {
+ return AlmostEqualNorm(a, b, a - b, decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqual(this float a, float b, int decimalPlaces)
+ {
+ return AlmostEqualNorm(a, b, a - b, decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqual(this Complex a, Complex b, int decimalPlaces)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqual(this Complex32 a, Complex32 b, int decimalPlaces)
+ {
+ return AlmostEqualNorm(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualRelative(this double a, double b, int decimalPlaces)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualRelative(this float a, float b, int decimalPlaces)
+ {
+ return AlmostEqualNormRelative(a, b, a - b, decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualRelative(this Complex a, Complex b, int decimalPlaces)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualRelative(this Complex32 a, Complex32 b, int decimalPlaces)
+ {
+ return AlmostEqualNormRelative(a.Norm(), b.Norm(), a.NormOfDifference(b), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
+ ///
+ ///
+ ///
+ /// Determines the 'number' of floating point numbers between two values (i.e. the number of discrete steps
+ /// between the two numbers) and then checks if that is within the specified tolerance. So if a tolerance
+ /// of 1 is passed then the result will be true only if the two numbers have the same binary representation
+ /// OR if they are two adjacent numbers that only differ by one step.
+ ///
+ ///
+ /// The comparison method used is explained in http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm . The article
+ /// at http://www.extremeoptimization.com/resources/Articles/FPDotNetConceptsAndFormats.aspx explains how to transform the C code to
+ /// .NET enabled code without using pointers and unsafe code.
+ ///
+ ///
+ /// The first value.
+ /// The second value.
+ /// The maximum number of floating point values between the two values. Must be 1 or larger.
+ /// Thrown if is smaller than one.
+ public static bool AlmostEqualNumbersBetween(this double a, double b, long maxNumbersBetween)
+ {
+ // Make sure maxNumbersBetween is non-negative and small enough that the
+ // default NAN won't compare as equal to anything.
+ if (maxNumbersBetween < 1)
+ {
+ throw new ArgumentOutOfRangeException("maxNumbersBetween");
+ }
+
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (double.IsInfinity(a) || double.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (double.IsNaN(a) || double.IsNaN(b))
+ {
+ return false;
+ }
+
+ // Get the first double and convert it to an integer value (by using the binary representation)
+ long firstUlong = AsDirectionalInt64(a);
+
+ // Get the second double and convert it to an integer value (by using the binary representation)
+ long secondUlong = AsDirectionalInt64(b);
+
+ // Now compare the values.
+ // Note that this comparison can overflow so we'll approach this differently
+ // Do note that we could overflow this way too. We should probably check that we don't.
+ return (a > b) ? (secondUlong + maxNumbersBetween >= firstUlong) : (firstUlong + maxNumbersBetween >= secondUlong);
+ }
+
+ ///
+ /// Compares two floats and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The maximum number of floating point values between the two values. Must be 1 or larger.
+ /// Thrown if is smaller than one.
+ public static bool AlmostEqualNumbersBetween(this float a, float b, int maxNumbersBetween)
+ {
+ // Make sure maxNumbersBetween is non-negative and small enough that the
+ // default NAN won't compare as equal to anything.
+ if (maxNumbersBetween < 1)
+ {
+ throw new ArgumentOutOfRangeException("maxNumbersBetween");
+ }
+
+ // If A or B are infinity (positive or negative) then
+ // only return true if they are exactly equal to each other -
+ // that is, if they are both infinities of the same sign.
+ if (float.IsInfinity(a) || float.IsInfinity(b))
+ {
+ return a == b;
+ }
+
+ // If A or B are a NAN, return false. NANs are equal to nothing,
+ // not even themselves.
+ if (float.IsNaN(a) || float.IsNaN(b))
+ {
+ return false;
+ }
+
+ // Get the first float and convert it to an integer value (by using the binary representation)
+ int firstUlong = AsDirectionalInt32(a);
+
+ // Get the second float and convert it to an integer value (by using the binary representation)
+ int secondUlong = AsDirectionalInt32(b);
+
+ // Now compare the values.
+ // Note that this comparison can overflow so we'll approach this differently
+ // Do note that we could overflow this way too. We should probably check that we don't.
+ return (a > b) ? (secondUlong + maxNumbersBetween >= firstUlong) : (firstUlong + maxNumbersBetween >= secondUlong);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqual(this IList a, IList b, double maximumAbsoluteError)
+ {
+ return ListForAll(a, b, AlmostEqual, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqual(this IList a, IList b, double maximumAbsoluteError)
+ {
+ return ListForAll(a, b, AlmostEqual, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqual(this IList a, IList b, double maximumAbsoluteError)
+ {
+ return ListForAll(a, b, AlmostEqual, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqual(this IList a, IList b, double maximumAbsoluteError)
+ {
+ return ListForAll(a, b, AlmostEqual, maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, double maximumError)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, maximumError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, double maximumError)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, maximumError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, double maximumError)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, maximumError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, double maximumError)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, maximumError);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqual(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqual, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqual(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqual, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqual(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqual, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqual(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqual, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ public static bool ListAlmostEqualRelative(this IList a, IList b, int decimalPlaces)
+ {
+ return ListForAll(a, b, AlmostEqualRelative, decimalPlaces);
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualNorm(this IList a, IList b, double maximumAbsoluteError)
+ where T : IPrecisionSupport
+ {
+ if (a == null && b == null)
+ {
+ return true;
+ }
+
+ if (a == null || b == null || a.Count != b.Count)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < a.Count; i++)
+ {
+ if (!AlmostEqualNorm(a[i], b[i], maximumAbsoluteError))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ ///
+ /// Compares two lists of doubles and determines if they are equal within the
+ /// specified maximum error.
+ ///
+ /// The first value list.
+ /// The second value list.
+ /// The accuracy required for being almost equal.
+ public static bool ListAlmostEqualNormRelative(this IList a, IList b, double maximumError)
+ where T : IPrecisionSupport
+ {
+ if (a == null && b == null)
+ {
+ return true;
+ }
+
+ if (a == null || b == null || a.Count != b.Count)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < a.Count; i++)
+ {
+ if (!AlmostEqualNormRelative(a[i], b[i], maximumError))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static bool ListForAll(IList a, IList b, Func predicate, TP parameter)
+ {
+ if (a == null && b == null)
+ {
+ return true;
+ }
+
+ if (a == null || b == null || a.Count != b.Count)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < a.Count; i++)
+ {
+ if (!predicate(a[i], b[i], parameter))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ ///
+ /// Compares two complex and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqual(this Vector a, Vector b, double maximumAbsoluteError)
+ where T : struct, IEquatable, IFormattable
+ {
+ return AlmostEqualNorm(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), maximumAbsoluteError);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal within
+ /// the specified maximum error.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The accuracy required for being almost equal.
+ public static bool AlmostEqualRelative(this Vector a, Vector b, double maximumError)
+ where T : struct, IEquatable, IFormattable
+ {
+ return AlmostEqualNormRelative(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), maximumError);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ /// number of decimal places as an absolute measure.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqual(this Vector a, Vector b, int decimalPlaces)
+ where T : struct, IEquatable, IFormattable
+ {
+ return AlmostEqualNorm(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), decimalPlaces);
+ }
+
+ ///
+ /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ ///
+ /// The first value.
+ /// The second value.
+ /// The number of decimal places.
+ public static bool AlmostEqualRelative(this Vector a, Vector b, int decimalPlaces)
+ where T : struct, IEquatable, IFormattable
+ {
+ return AlmostEqualNormRelative(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), decimalPlaces);
+ }
+
+ /////
+ ///// Compares two complex and determines if they are equal within
+ ///// the specified maximum error.
+ /////
+ ///// The first value.
+ ///// The second value.
+ ///// The accuracy required for being almost equal.
+ //public static bool AlmostEqual(this Matrix a, Matrix b, double maximumAbsoluteError)
+ // where T : struct, IEquatable, IFormattable
+ //{
+ // return AlmostEqualNorm(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), maximumAbsoluteError);
+ //}
+
+ /////
+ ///// Compares two doubles and determines if they are equal within
+ ///// the specified maximum error.
+ /////
+ ///// The first value.
+ ///// The second value.
+ ///// The accuracy required for being almost equal.
+ //public static bool AlmostEqualRelative(this Matrix a, Matrix b, double maximumError)
+ // where T : struct, IEquatable, IFormattable
+ //{
+ // return AlmostEqualNormRelative(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), maximumError);
+ //}
+
+ /////
+ ///// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
+ ///// number of decimal places as an absolute measure.
+ /////
+ ///// The first value.
+ ///// The second value.
+ ///// The number of decimal places.
+ //public static bool AlmostEqual(this Matrix a, Matrix b, int decimalPlaces)
+ // where T : struct, IEquatable, IFormattable
+ //{
+ // return AlmostEqualNorm(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), decimalPlaces);
+ //}
+
+ /////
+ ///// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
+ ///// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
+ /////
+ ///// The first value.
+ ///// The second value.
+ ///// The number of decimal places.
+ //public static bool AlmostEqualRelative(this Matrix a, Matrix b, int decimalPlaces)
+ // where T : struct, IEquatable, IFormattable
+ //{
+ // return AlmostEqualNormRelative(a.L2Norm(), b.L2Norm(), (a - b).L2Norm(), decimalPlaces);
+ //}
+ }
+}
diff --git a/src/Numerics/Precision.cs b/src/Numerics/Precision.cs
index 3beafb3a..5e06f718 100644
--- a/src/Numerics/Precision.cs
+++ b/src/Numerics/Precision.cs
@@ -28,15 +28,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-namespace MathNet.Numerics
-{
- using System;
- using System.Collections.Generic;
+using System;
#if PORTABLE
- using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
#endif
+namespace MathNet.Numerics
+{
+
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
@@ -79,21 +79,21 @@ namespace MathNet.Numerics
///
///
///
- public static class Precision
+ public static partial class Precision
{
///
/// The number of binary digits used to represent the binary number for a double precision floating
/// point value. i.e. there are this many digits used to represent the
/// actual number, where in a number as: 0.134556 * 10^5 the digits are 0.134556 and the exponent is 5.
///
- private const int DoubleWidth = 53;
+ const int DoubleWidth = 53;
///
/// The number of binary digits used to represent the binary number for a single precision floating
/// point value. i.e. there are this many digits used to represent the
/// actual number, where in a number as: 0.134556 * 10^5 the digits are 0.134556 and the exponent is 5.
///
- private const int SingleWidth = 24;
+ const int SingleWidth = 24;
///
/// The maximum relative precision of of double-precision floating numbers (64 bit)
@@ -116,14 +116,14 @@ namespace MathNet.Numerics
public static readonly int SingleDecimalPlaces = (int) Math.Floor(Math.Abs(Math.Log10(SinglePrecision)));
///
- /// Value representing 10 * 2^(-52)
+ /// Value representing 10 * 2^(-53) = 1.11022302462516E-15
///
- private static readonly double DefaultDoubleRelativeAccuracy = DoublePrecision * 10;
+ static readonly double DefaultDoubleAccuracy = DoublePrecision*10;
///
- /// Value representing 10 * 2^(-24)
+ /// Value representing 10 * 2^(-24) = 5.96046447753906E-07
///
- private static readonly float DefaultSingleRelativeAccuracy = (float)(SinglePrecision * 10);
+ static readonly float DefaultSingleAccuracy = (float) (SinglePrecision*10);
///
/// Returns the magnitude of the number.
@@ -145,7 +145,7 @@ namespace MathNet.Numerics
#if PORTABLE
var truncated = (int)Truncate(magnitude);
#else
- var truncated = (int)Math.Truncate(magnitude);
+ var truncated = (int) Math.Truncate(magnitude);
#endif
// To get the right number we need to know if the value is negative or positive
@@ -177,7 +177,7 @@ namespace MathNet.Numerics
#if PORTABLE
var truncated = (int)Truncate(magnitude);
#else
- var truncated = (int)Math.Truncate(magnitude);
+ var truncated = (int) Math.Truncate(magnitude);
#endif
// To get the right number we need to know if the value is negative or positive
@@ -201,7 +201,7 @@ namespace MathNet.Numerics
}
int magnitude = Magnitude(value);
- return value * Math.Pow(10, -magnitude);
+ return value*Math.Pow(10, -magnitude);
}
///
@@ -211,7 +211,7 @@ namespace MathNet.Numerics
///
/// The resulting long value.
///
- private static long AsInt64(double value)
+ static long AsInt64(double value)
{
#if PORTABLE
return DoubleToInt64Bits(value);
@@ -227,11 +227,11 @@ namespace MathNet.Numerics
///
/// The input double value.
/// A long value which is roughly the equivalent of the double value.
- private static long AsDirectionalInt64(double value)
+ static long AsDirectionalInt64(double value)
{
// Convert in the normal way.
long result = AsInt64(value);
-
+
// Now find out where we're at in the range
// If the value is larger/equal to zero then we can just return the value
// if the value is negative we subtract long.MinValue from it.
@@ -245,7 +245,7 @@ namespace MathNet.Numerics
///
/// The input float value.
/// An int value which is roughly the equivalent of the double value.
- private static int AsDirectionalInt32(float value)
+ static int AsDirectionalInt32(float value)
{
// Convert in the normal way.
int result = FloatToInt32Bits(value);
@@ -306,7 +306,7 @@ namespace MathNet.Numerics
return Int64BitsToDouble(intValue);
#else
return BitConverter.Int64BitsToDouble(intValue);
-#endif
+#endif
}
///
@@ -362,7 +362,7 @@ namespace MathNet.Numerics
return Int64BitsToDouble(intValue);
#else
return BitConverter.Int64BitsToDouble(intValue);
-#endif
+#endif
}
///
@@ -375,7 +375,7 @@ namespace MathNet.Numerics
///
public static double CoerceZero(this double a, int maxNumbersBetween)
{
- return CoerceZero(a, (long)maxNumbersBetween);
+ return CoerceZero(a, (long) maxNumbersBetween);
}
///
@@ -403,7 +403,7 @@ namespace MathNet.Numerics
// We allow maxNumbersBetween between 0 and the number so
// we need to check if there a
- if (NumbersBetween(0.0, a) <= (ulong)maxNumbersBetween)
+ if (NumbersBetween(0.0, a) <= (ulong) maxNumbersBetween)
{
return 0.0;
}
@@ -426,7 +426,7 @@ namespace MathNet.Numerics
{
throw new ArgumentOutOfRangeException("maximumAbsoluteError");
}
-
+
if (double.IsInfinity(a) || double.IsNaN(a))
{
return a;
@@ -455,12 +455,11 @@ namespace MathNet.Numerics
///
/// The value.
/// The ulps difference.
- /// The bottom range end.
- /// The top range end.
///
/// Thrown if is smaller than zero.
///
- public static void RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween, out double bottomRangeEnd, out double topRangeEnd)
+ /// Tuple of the bottom and top range ends.
+ public static Tuple RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween)
{
// Make sure ulpDifference is non-negative
if (maxNumbersBetween < 1)
@@ -472,17 +471,13 @@ namespace MathNet.Numerics
// return the same infinity for the range.
if (double.IsInfinity(value))
{
- topRangeEnd = value;
- bottomRangeEnd = value;
- return;
+ return new Tuple(value, value);
}
// If the value is a NaN then the range is a NaN too.
if (double.IsNaN(value))
{
- topRangeEnd = double.NaN;
- bottomRangeEnd = double.NaN;
- return;
+ return new Tuple(double.NaN, double.NaN);
}
// Translate the bit pattern of the double to an integer.
@@ -494,14 +489,14 @@ namespace MathNet.Numerics
long intValue = AsInt64(value);
#if PORTABLE
- // We need to protect against over- and under-flow of the intValue when
- // we start to add the ulpsDifference.
+ // We need to protect against over- and under-flow of the intValue when
+ // we start to add the ulpsDifference.
if (intValue < 0)
{
// Note that long.MinValue has the same bit pattern as
// -0.0. Therefore we're working in opposite direction (i.e. add if we want to
// go more negative and subtract if we want to go less negative)
- topRangeEnd = Math.Abs(long.MinValue - intValue) < maxNumbersBetween
+ var topRangeEnd = Math.Abs(long.MinValue - intValue) < maxNumbersBetween
// Got underflow, which can be fixed by splitting the calculation into two bits
// first get the remainder of the intValue after subtracting it from the long.MinValue
// and add that to the ulpsDifference. That way we'll turn positive without underflow
@@ -509,18 +504,20 @@ namespace MathNet.Numerics
// No problems here, move along.
: Int64BitsToDouble(intValue - maxNumbersBetween);
- bottomRangeEnd = Math.Abs(intValue) < maxNumbersBetween
+ var bottomRangeEnd = Math.Abs(intValue) < maxNumbersBetween
// Underflow, which means we'd have to go further than a long would allow us.
// Also we couldn't translate it back to a double, so we'll return -Double.MaxValue
? -double.MaxValue
// intValue is negative. Adding the positive ulpsDifference means that it gets less negative.
// However due to the conversion way this means that the actual double value gets more negative :-S
: Int64BitsToDouble(intValue + maxNumbersBetween);
+
+ return new Tuple(bottomRangeEnd, topRangeEnd);
}
else
{
// IntValue is positive
- topRangeEnd = long.MaxValue - intValue < maxNumbersBetween
+ var topRangeEnd = long.MaxValue - intValue < maxNumbersBetween
// Overflow, which means we'd have to go further than a long would allow us.
// Also we couldn't translate it back to a double, so we'll return Double.MaxValue
? double.MaxValue
@@ -528,13 +525,15 @@ namespace MathNet.Numerics
: Int64BitsToDouble(intValue + maxNumbersBetween);
// Check the bottom range end for underflows
- bottomRangeEnd = intValue > maxNumbersBetween
+ var bottomRangeEnd = intValue > maxNumbersBetween
// No problems here. IntValue is larger than ulpsDifference so we'll end up with a
// positive number.
? Int64BitsToDouble(intValue - maxNumbersBetween)
// Int value is bigger than zero but smaller than the ulpsDifference. So we'll need to deal with
// the reversal at the negative end
: Int64BitsToDouble(long.MinValue + (maxNumbersBetween - intValue));
+
+ return new Tuple(bottomRangeEnd, topRangeEnd);
}
#else
// We need to protect against over- and under-flow of the intValue when
@@ -544,7 +543,7 @@ namespace MathNet.Numerics
// Note that long.MinValue has the same bit pattern as
// -0.0. Therefore we're working in opposite direction (i.e. add if we want to
// go more negative and subtract if we want to go less negative)
- topRangeEnd = Math.Abs(long.MinValue - intValue) < maxNumbersBetween
+ var topRangeEnd = Math.Abs(long.MinValue - intValue) < maxNumbersBetween
// Got underflow, which can be fixed by splitting the calculation into two bits
// first get the remainder of the intValue after subtracting it from the long.MinValue
// and add that to the ulpsDifference. That way we'll turn positive without underflow
@@ -552,18 +551,20 @@ namespace MathNet.Numerics
// No problems here, move along.
: BitConverter.Int64BitsToDouble(intValue - maxNumbersBetween);
- bottomRangeEnd = Math.Abs(intValue) < maxNumbersBetween
+ var bottomRangeEnd = Math.Abs(intValue) < maxNumbersBetween
// Underflow, which means we'd have to go further than a long would allow us.
// Also we couldn't translate it back to a double, so we'll return -Double.MaxValue
? -double.MaxValue
// intValue is negative. Adding the positive ulpsDifference means that it gets less negative.
// However due to the conversion way this means that the actual double value gets more negative :-S
: BitConverter.Int64BitsToDouble(intValue + maxNumbersBetween);
+
+ return new Tuple(bottomRangeEnd, topRangeEnd);
}
else
{
// IntValue is positive
- topRangeEnd = long.MaxValue - intValue < maxNumbersBetween
+ var topRangeEnd = long.MaxValue - intValue < maxNumbersBetween
// Overflow, which means we'd have to go further than a long would allow us.
// Also we couldn't translate it back to a double, so we'll return Double.MaxValue
? double.MaxValue
@@ -571,13 +572,15 @@ namespace MathNet.Numerics
: BitConverter.Int64BitsToDouble(intValue + maxNumbersBetween);
// Check the bottom range end for underflows
- bottomRangeEnd = intValue > maxNumbersBetween
+ var bottomRangeEnd = intValue > maxNumbersBetween
// No problems here. IntValue is larger than ulpsDifference so we'll end up with a
// positive number.
? BitConverter.Int64BitsToDouble(intValue - maxNumbersBetween)
// Int value is bigger than zero but smaller than the ulpsDifference. So we'll need to deal with
// the reversal at the negative end
: BitConverter.Int64BitsToDouble(long.MinValue + (maxNumbersBetween - intValue));
+
+ return new Tuple(bottomRangeEnd, topRangeEnd);
}
#endif
}
@@ -591,9 +594,7 @@ namespace MathNet.Numerics
/// The maximum floating point number which is larger than the given .
public static double MaximumMatchingFloatingPointNumber(this double value, long maxNumbersBetween)
{
- double topRangeEnd, bottomRangeEnd;
- RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween, out bottomRangeEnd, out topRangeEnd);
- return topRangeEnd;
+ return RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween).Item2;
}
///
@@ -605,9 +606,7 @@ namespace MathNet.Numerics
/// The minimum floating point number which is smaller than the given .
public static double MinimumMatchingFloatingPointNumber(this double value, long maxNumbersBetween)
{
- double topRangeEnd, bottomRangeEnd;
- RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween, out bottomRangeEnd, out topRangeEnd);
- return bottomRangeEnd;
+ return RangeOfMatchingFloatingPointNumbers(value, maxNumbersBetween).Item1;
}
///
@@ -615,8 +614,6 @@ namespace MathNet.Numerics
///
/// The value.
/// The relative difference.
- /// The number of ULPS between the value and the value - relativeDifference.
- /// The number of ULPS between the value and the value + relativeDifference.
///
/// Thrown if is smaller than zero.
///
@@ -626,7 +623,11 @@ namespace MathNet.Numerics
///
/// Thrown if is double.NaN.
///
- public static void RangeOfMatchingNumbers(this double value, double relativeDifference, out long bottomRangeEnd, out long topRangeEnd)
+ ///
+ /// Tuple with the number of ULPS between the value and the value - relativeDifference as first,
+ /// and the number of ULPS between the value and the value + relativeDifference as second value.
+ ///
+ public static Tuple RangeOfMatchingNumbers(this double value, double relativeDifference)
{
// Make sure the relative is non-negative
if (relativeDifference < 0)
@@ -651,22 +652,20 @@ namespace MathNet.Numerics
// so return the ulps counts for the difference.
if (value.Equals(0))
{
- topRangeEnd = AsInt64(relativeDifference);
- bottomRangeEnd = topRangeEnd;
- return;
+ var v = AsInt64(relativeDifference);
+ return new Tuple(v, v);
}
// Calculate the ulps for the maximum and minimum values
// Note that these can overflow
- long max = AsDirectionalInt64(value + (relativeDifference * Math.Abs(value)));
- long min = AsDirectionalInt64(value - (relativeDifference * Math.Abs(value)));
+ long max = AsDirectionalInt64(value + (relativeDifference*Math.Abs(value)));
+ long min = AsDirectionalInt64(value - (relativeDifference*Math.Abs(value)));
// Calculate the ulps from the value
long intValue = AsDirectionalInt64(value);
// Determine the ranges
- topRangeEnd = Math.Abs(max - intValue);
- bottomRangeEnd = Math.Abs(intValue - min);
+ return new Tuple(Math.Abs(intValue - min), Math.Abs(max - intValue));
}
///
@@ -708,633 +707,54 @@ namespace MathNet.Numerics
// Now find the number of values between the two doubles. This should not overflow
// given that there are more long values than there are double values
- return (a >= b) ? (ulong)(intA - intB) : (ulong)(intB - intA);
- }
-
- ///
- /// Checks whether two real numbers are almost equal.
- ///
- /// The first number
- /// The second number
- /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
- public static bool AlmostEqual(this double a, double b)
- {
- double diff = a - b;
- return AlmostEqualWithError(a, b, diff, DefaultDoubleRelativeAccuracy);
- }
-
- ///
- /// Checks whether two real numbers are almost equal.
- ///
- /// The first number
- /// The second number
- /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
- public static bool AlmostEqual(this float a, float b)
- {
- double diff = a - b;
- return AlmostEqualWithError(a, b, diff, DefaultSingleRelativeAccuracy);
- }
-
- ///
- /// Checks whether two Compex numbers are almost equal.
- ///
- /// The first number
- /// The second number
- /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
- public static bool AlmostEqual(this Complex a, Complex b)
- {
- double diff = a.NormOfDifference(b);
- return AlmostEqualWithError(a.Norm(), b.Norm(), diff, DefaultDoubleRelativeAccuracy);
- }
-
- ///
- /// Checks whether two Compex numbers are almost equal.
- ///
- /// The first number
- /// The second number
- /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
- public static bool AlmostEqual(this Complex32 a, Complex32 b)
- {
- double diff = ((IPrecisionSupport)a).NormOfDifference(b);
- return AlmostEqualWithError(((IPrecisionSupport)a).Norm(), ((IPrecisionSupport)b).Norm(), diff, DefaultSingleRelativeAccuracy);
- }
- ///
- /// Checks whether two structures with precision support are almost equal.
- ///
- /// The type of the structures. Must implement .
- /// The first structure
- /// The second structure
- /// true if the two values differ by no more than 10 * 2^(-52); false otherwise.
- public static bool AlmostEqual(this T a, T b)
- where T : IPrecisionSupport
- {
- double diff = a.NormOfDifference(b);
- return AlmostEqualWithError(a.Norm(), b.Norm(), diff, DefaultDoubleRelativeAccuracy);
- }
-
- ///
- /// Compares two complex and determines if they are equal within
- /// the specified maximum error.
- ///
- /// The first value.
- /// The second value.
- /// The accuracy required for being almost equal.
- ///
- /// if both complex are almost equal up to the
- /// specified maximum error, otherwise.
- ///
- public static bool AlmostEqualWithError(this Complex a, Complex b, double maximumError)
- {
- double diff = a.NormOfDifference(b);
- return AlmostEqualWithError(a.Norm(), b.Norm(), diff, maximumError);
- }
-
- ///
- /// Compares two complex and determines if they are equal within
- /// the specified maximum error.
- ///
- /// The first value.
- /// The second value.
- /// The accuracy required for being almost equal.
- ///
- /// if both complex are almost equal up to the
- /// specified maximum error, otherwise.
- ///
- public static bool AlmostEqualWithError(this float a, float b, double maximumError)
- {
- return AlmostEqualWithError(a, b, a - b, maximumError);
- }
-
- ///
- /// Compares two doubles and determines if they are equal within
- /// the specified maximum error.
- ///
- /// The first value.
- /// The second value.
- /// The accuracy required for being almost equal.
- ///
- /// if both doubles are almost equal up to the
- /// specified maximum error, otherwise.
- ///
- public static bool AlmostEqualWithError(this double a, double b, double maximumError)
- {
- return AlmostEqualWithError(a, b, a - b, maximumError);
- }
-
- ///
- /// Compares two lists of doubles and determines if they are equal within the
- /// specified maximum error.
- ///
- /// The first value list.
- /// The second value list.
- ///
- /// The accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum error, otherwise.
- ///
- public static bool AlmostEqualListWithError(this IList a, IList b, double maximumError)
- {
- if (a == null && b == null)
- {
- return true;
- }
-
- if (a == null || b == null || a.Count != b.Count)
- {
- return false;
- }
-
- for (int i = 0; i < a.Count; i++)
- {
- if (!AlmostEqualWithError(a[i], b[i], a[i] - b[i], maximumError))
- {
- return false;
- }
- }
-
- return true;
- }
-
- ///
- /// Compares two lists of doubles and determines if they are equal within the
- /// specified maximum error.
- ///
- /// The first value list.
- /// The second value list.
- ///
- /// The accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum error, otherwise.
- ///
- public static bool AlmostEqualListWithError(this IList a, IList b, double maximumError)
- {
- if (a == null && b == null)
- {
- return true;
- }
-
- if (a == null || b == null || a.Count != b.Count)
- {
- return false;
- }
-
- for (int i = 0; i < a.Count; i++)
- {
- if (!AlmostEqualWithError(a[i].Norm(), b[i].Norm(), a[i].NormOfDifference(b[i]), maximumError))
- {
- return false;
- }
- }
-
- return true;
- }
-
- ///
- /// Compares two structure with precision support and determines if they are equal
- /// within the specified maximum relative error.
- ///
- ///
- /// The type of the structures. Must implement .
- ///
- /// The first structure.
- /// The second structure.
- ///
- /// The accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum relative error, otherwise.
- ///
- public static bool AlmostEqualWithError(this T a, T b, double maximumError)
- where T : IPrecisionSupport
- {
- return AlmostEqualWithError(a.Norm(), b.Norm(), a.NormOfDifference(b), maximumError);
- }
-
- ///
- /// Compares two lists of structures with precision support and determines if they
- /// are equal within the specified maximum error.
- ///
- ///
- /// The type of the structures. Must implement .
- ///
- /// The first structure list.
- /// The second structure list.
- ///
- /// The accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum error, otherwise.
- ///
- public static bool AlmostEqualListWithError(this IList a, IList b, double maximumError)
- where T : IPrecisionSupport
- {
- if (a == null && b == null)
- {
- return true;
- }
-
- if (a == null || b == null || a.Count != b.Count)
- {
- return false;
- }
-
- for (int i = 0; i < a.Count; i++)
- {
- if (!AlmostEqualWithError(a[i].Norm(), b[i].Norm(), a[i].NormOfDifference(b[i]), maximumError))
- {
- return false;
- }
- }
-
- return true;
- }
-
- ///
- /// Compares two doubles and determines if they are equal within the specified
- /// maximum error.
- ///
- /// The first value.
- /// The second value.
- ///
- /// The difference of the two values (according to some norm).
- ///
- ///
- /// The accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum error, otherwise.
- ///
- public static bool AlmostEqualWithError(this double a, double b, double diff, double maximumError)
- {
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- if (Math.Abs(a) < DoublePrecision || Math.Abs(b) < DoublePrecision)
- {
- return AlmostEqualWithAbsoluteError(a, b, diff, maximumError);
- }
-
- return AlmostEqualWithRelativeError(a, b, diff, maximumError);
- }
-
- ///
- /// Compares two doubles and determines if they are equal within the specified
- /// maximum absolute error.
- ///
- /// The first value.
- /// The second value.
- ///
- /// The difference of the two values (according to some norm).
- ///
- ///
- /// The absolute accuracy required for being almost equal.
- ///
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum absolute error, otherwise.
- ///
- public static bool AlmostEqualWithAbsoluteError(this double a, double b, double diff, double maximumAbsoluteError)
- {
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- return Math.Abs(diff) < maximumAbsoluteError;
- }
-
- ///
- /// Compares two doubles and determines if they are equal within the specified
- /// maximum relative error.
- ///
- /// The first value.
- /// The second value.
- /// The difference of the two values (according to some norm).
- ///
- /// The relative accuracy required for being
- /// almost equal.
- ///
- /// if both doubles are almost equal up to the specified
- /// maximum relative error, otherwise.
- ///
- public static bool AlmostEqualWithRelativeError(this double a, double b, double diff, double maximumRelativeError)
- {
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- if ((a == 0 && Math.Abs(b) < maximumRelativeError)
- || (b == 0 && Math.Abs(a) < maximumRelativeError))
- {
- return true;
- }
-
- return Math.Abs(diff) < maximumRelativeError * Math.Max(Math.Abs(a), Math.Abs(b));
- }
-
- ///
- /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not. If the numbers
- /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
- ///
- ///
- ///
- /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
- /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
- /// 0.005 and 0.015, but not 0.02 and not 0.00
- ///
- ///
- /// The first value.
- /// The second value.
- /// The number of decimal places.
- /// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- ///
- /// Thrown if is smaller than zero.
- ///
- public static bool AlmostEqualInDecimalPlaces(this double a, double b, int decimalPlaces)
- {
- if (decimalPlaces < 0)
- {
- // Can't have a negative number of decimal places
- throw new ArgumentOutOfRangeException("decimalPlaces");
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- if (Math.Abs(a) < DoublePrecision || Math.Abs(b) < DoublePrecision)
- {
- return AlmostEqualInAbsoluteDecimalPlaces(a, b, decimalPlaces);
- }
-
- // If both numbers are equal, get out now. This should remove the possibility of both numbers being zero
- // and any problems associated with that.
- if (a.Equals(b))
- {
- return true;
- }
-
- return AlmostEqualInRelativeDecimalPlaces(a, b, decimalPlaces);
- }
-
- ///
- /// Compares two floats and determines if they are equal to within the specified number of decimal places or not. If the numbers
- /// are very close to zero an absolute difference is compared, otherwise the relative difference is compared.
- ///
- ///
- ///
- /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
- /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
- /// 0.005 and 0.015, but not 0.02 and not 0.00
- ///
- ///
- /// The first value.
- /// The second value.
- /// The number of decimal places.
- /// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- ///
- /// Thrown if is smaller than zero.
- ///
- public static bool AlmostEqualInDecimalPlaces(this float a, float b, int decimalPlaces)
- {
- if (decimalPlaces < 0)
- {
- // Can't have a negative number of decimal places
- throw new ArgumentOutOfRangeException("decimalPlaces");
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (float.IsNaN(a) || float.IsNaN(b))
- {
- return false;
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (float.IsInfinity(a) || float.IsInfinity(b))
- {
- return a == b;
- }
-
- if (Math.Abs(a) < SinglePrecision || Math.Abs(b) < SinglePrecision)
- {
- return AlmostEqualInAbsoluteDecimalPlaces(a, b, decimalPlaces);
- }
-
- // If both numbers are equal, get out now. This should remove the possibility of both numbers being zero
- // and any problems associated with that.
- if (a.Equals(b))
- {
- return true;
- }
-
- return AlmostEqualInRelativeDecimalPlaces(a, b, decimalPlaces);
+ return (a >= b) ? (ulong) (intA - intB) : (ulong) (intB - intA);
}
///
- /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not.
+ /// Compares two doubles and determines if the first value is larger than the second
+ /// value to within the tolerance or not. Equality comparison is based on the binary representation.
///
- ///
- ///
- /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
- /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
- /// 0.005 and 0.015, but not 0.02 and not 0.00
- ///
- ///
/// The first value.
/// The second value.
- /// The number of decimal places.
- /// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- public static bool AlmostEqualInRelativeDecimalPlaces(this double a, double b, int decimalPlaces)
+ /// The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.
+ /// true if the first value is larger than the second value; otherwise false.
+ public static bool IsLarger(this double a, double b, long maxNumbersBetween)
{
- if (decimalPlaces < 0)
- {
- // Can't have a negative number of decimal places
- throw new ArgumentOutOfRangeException("decimalPlaces");
- }
-
// If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
+ // not even themselves, and thus they're not bigger or
+ // smaller than anything either
if (double.IsNaN(a) || double.IsNaN(b))
{
return false;
}
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal
- int magnitudeOfFirst = Magnitude(a);
- int magnitudeOfSecond = Magnitude(b);
- int magnitudeOfMax = Math.Max(magnitudeOfFirst, magnitudeOfSecond);
- if (magnitudeOfMax > (Math.Min(magnitudeOfFirst, magnitudeOfSecond) + 1))
- {
- return false;
- }
-
- // The values are equal if the difference between the two numbers is smaller than
- // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
- // on each side of the numbers, e.g. if decimalPlaces == 2,
- // then 0.01 will equal between 0.00995 and 0.01005, but not 0.0015 and not 0.0095
- double decimalPlaceMagnitude = Math.Pow(10, magnitudeOfMax - decimalPlaces)/2d;
- return Math.Abs((a - b)) < decimalPlaceMagnitude;
+ return CompareTo(a, b, maxNumbersBetween) > 0;
}
///
- /// Compares two floats and determines if they are equal to within the specified number of decimal places or not.
+ /// Compares two doubles and determines if the first value is larger than the second
+ /// value to within the tolerance or not. Equality comparison is based on the binary representation.
///
- ///
- ///
- /// The values are equal if the difference between the two numbers is smaller than 10^(-numberOfDecimalPlaces). We divide by
- /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
- /// 0.005 and 0.015, but not 0.02 and not 0.00
- ///
- ///
/// The first value.
/// The second value.
- /// The number of decimal places.
- /// if both floats are equal to each other within the specified number of decimal places; otherwise .
- public static bool AlmostEqualInRelativeDecimalPlaces(this float a, float b, int decimalPlaces)
+ /// The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.
+ /// true if the first value is larger than the second value; otherwise false.
+ public static bool IsLarger(this float a, float b, long maxNumbersBetween)
{
- if (decimalPlaces < 0)
- {
- // Can't have a negative number of decimal places
- throw new ArgumentOutOfRangeException("decimalPlaces");
- }
-
// If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
+ // not even themselves, and thus they're not bigger or
+ // smaller than anything either
if (float.IsNaN(a) || float.IsNaN(b))
{
return false;
}
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (float.IsInfinity(a) || float.IsInfinity(b))
- {
- return a == b;
- }
-
- // If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal
- int magnitudeOfFirst = Magnitude(a);
- int magnitudeOfSecond = Magnitude(b);
- int magnitudeOfMax = Math.Max(magnitudeOfFirst, magnitudeOfSecond);
- if (magnitudeOfMax > (Math.Min(magnitudeOfFirst, magnitudeOfSecond) + 1))
- {
- return false;
- }
-
- // The values are equal if the difference between the two numbers is smaller than
- // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
- // on each side of the numbers, e.g. if decimalPlaces == 2,
- // then 0.01 will equal between 0.00995 and 0.01005, but not 0.0015 and not 0.0095
- var decimalPlaceMagnitude = (float) Math.Pow(10, magnitudeOfMax - decimalPlaces)/2d;
- return Math.Abs((a - b)) < decimalPlaceMagnitude;
- }
-
- ///
- /// Compares two doubles and determines if they are equal to within the specified number of decimal places or not, using the
- /// number of decimal places as an absolute measure.
- ///
- ///
- ///
- /// The values are equal if the difference between the two numbers is smaller than 0.5e-decimalPlaces. We divide by
- /// two so that we have half the range on each side of the numbers, e.g. if == 2, then 0.01 will equal between
- /// 0.005 and 0.015, but not 0.02 and not 0.00
- ///
- ///
- /// The first value.
- /// The second value.
- /// The number of decimal places.
- /// if both doubles are equal to each other within the specified number of decimal places; otherwise .
- public static bool AlmostEqualInAbsoluteDecimalPlaces(this double a, double b, int decimalPlaces)
- {
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // The values are equal if the difference between the two numbers is smaller than
- // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
- // on each side of the numbers, e.g. if decimalPlaces == 2,
- // then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
- double decimalPlaceMagnitude = Math.Pow(10, -decimalPlaces)/2d;
- return Math.Abs((a - b)) < decimalPlaceMagnitude;
+ return CompareTo(a, b, maxNumbersBetween) > 0;
}
///
- /// Compares two floats and determines if they are equal to within the specified number of decimal places or not, using the
- /// number of decimal places as an absolute measure.
+ /// Compares two doubles and determines if the first value is larger than the second
+ /// value to within the specified number of decimal places or not.
///
///
///
@@ -1346,146 +766,8 @@ namespace MathNet.Numerics
/// The first value.
/// The second value.
/// The number of decimal places.
- /// if both floats are equal to each other within the specified number of decimal places; otherwise .
- public static bool AlmostEqualInAbsoluteDecimalPlaces(this float a, float b, int decimalPlaces)
- {
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (float.IsNaN(a) || float.IsNaN(b))
- {
- return false;
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (float.IsInfinity(a) || float.IsInfinity(b))
- {
- return a == b;
- }
-
- // The values are equal if the difference between the two numbers is smaller than
- // 10^(-numberOfDecimalPlaces). We divide by two so that we have half the range
- // on each side of the numbers, e.g. if decimalPlaces == 2,
- // then 0.01 will equal between 0.005 and 0.015, but not 0.02 and not 0.00
- var decimalPlaceMagnitude = (float) Math.Pow(10, -decimalPlaces)/2f;
- return Math.Abs((a - b)) < decimalPlaceMagnitude;
- }
-
- ///
- /// Compares two doubles and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
- ///
- ///
- ///
- /// Determines the 'number' of floating point numbers between two values (i.e. the number of discrete steps
- /// between the two numbers) and then checks if that is within the specified tolerance. So if a tolerance
- /// of 1 is passed then the result will be true only if the two numbers have the same binary representation
- /// OR if they are two adjacent numbers that only differ by one step.
- ///
- ///
- /// The comparison method used is explained in http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm . The article
- /// at http://www.extremeoptimization.com/resources/Articles/FPDotNetConceptsAndFormats.aspx explains how to transform the C code to
- /// .NET enabled code without using pointers and unsafe code.
- ///
- ///
- /// The first value.
- /// The second value.
- /// The maximum number of floating point values between the two values. Must be 1 or larger.
- /// if both doubles are equal to each other within the specified tolerance; otherwise .
- ///
- /// Thrown if is smaller than one.
- ///
- public static bool AlmostEqual(this double a, double b, long maxNumbersBetween)
- {
- // Make sure maxNumbersBetween is non-negative and small enough that the
- // default NAN won't compare as equal to anything.
- if (maxNumbersBetween < 1)
- {
- throw new ArgumentOutOfRangeException("maxNumbersBetween");
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (double.IsInfinity(a) || double.IsInfinity(b))
- {
- return a == b;
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (double.IsNaN(a) || double.IsNaN(b))
- {
- return false;
- }
-
- // Get the first double and convert it to an integer value (by using the binary representation)
- long firstUlong = AsDirectionalInt64(a);
-
- // Get the second double and convert it to an integer value (by using the binary representation)
- long secondUlong = AsDirectionalInt64(b);
-
- // Now compare the values.
- // Note that this comparison can overflow so we'll approach this differently
- // Do note that we could overflow this way too. We should probably check that we don't.
- return (a > b) ? (secondUlong + maxNumbersBetween >= firstUlong) : (firstUlong + maxNumbersBetween >= secondUlong);
- }
-
- ///
- /// Compares two floats and determines if they are equal to within the tolerance or not. Equality comparison is based on the binary representation.
- ///
- /// The first value.
- /// The second value.
- /// The maximum number of floating point values between the two values. Must be 1 or larger.
- /// if both floats are equal to each other within the specified tolerance; otherwise .
- ///
- /// Thrown if is smaller than one.
- ///
- public static bool AlmostEqual(this float a, float b, int maxNumbersBetween)
- {
- // Make sure maxNumbersBetween is non-negative and small enough that the
- // default NAN won't compare as equal to anything.
- if (maxNumbersBetween < 1)
- {
- throw new ArgumentOutOfRangeException("maxNumbersBetween");
- }
-
- // If A or B are infinity (positive or negative) then
- // only return true if they are exactly equal to each other -
- // that is, if they are both infinities of the same sign.
- if (float.IsInfinity(a) || float.IsInfinity(b))
- {
- return a == b;
- }
-
- // If A or B are a NAN, return false. NANs are equal to nothing,
- // not even themselves.
- if (float.IsNaN(a) || float.IsNaN(b))
- {
- return false;
- }
-
- // Get the first float and convert it to an integer value (by using the binary representation)
- int firstUlong = AsDirectionalInt32(a);
-
- // Get the second float and convert it to an integer value (by using the binary representation)
- int secondUlong = AsDirectionalInt32(b);
-
- // Now compare the values.
- // Note that this comparison can overflow so we'll approach this differently
- // Do note that we could overflow this way too. We should probably check that we don't.
- return (a > b) ? (secondUlong + maxNumbersBetween >= firstUlong) : (firstUlong + maxNumbersBetween >= secondUlong);
- }
-
- ///
- /// Compares two doubles and determines if the first value is larger than the second
- /// value to within the tolerance or not. Equality comparison is based on the binary representation.
- ///
- /// The first value.
- /// The second value.
- /// The maximum number of floating point values for which the two values are considered equal. Must be 1 or larger.
/// true if the first value is larger than the second value; otherwise false.
- public static bool IsLarger(this double a, double b, long maxNumbersBetween)
+ public static bool IsLargerDecimal(this double a, double b, int decimalPlaces)
{
// If A or B are a NAN, return false. NANs are equal to nothing,
// not even themselves, and thus they're not bigger or
@@ -1495,7 +777,7 @@ namespace MathNet.Numerics
return false;
}
- return CompareTo(a, b, maxNumbersBetween) > 0;
+ return CompareToDecimal(a, b, decimalPlaces) > 0;
}
///
@@ -1513,17 +795,17 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// true if the first value is larger than the second value; otherwise false.
- public static bool IsLargerWithDecimalPlaces(this double a, double b, int decimalPlaces)
+ public static bool IsLargerDecimal(this float a, float b, int decimalPlaces)
{
// If A or B are a NAN, return false. NANs are equal to nothing,
// not even themselves, and thus they're not bigger or
// smaller than anything either
- if (double.IsNaN(a) || double.IsNaN(b))
+ if (float.IsNaN(a) || float.IsNaN(b))
{
return false;
}
- return CompareToInDecimalPlaces(a, b, decimalPlaces) > 0;
+ return CompareToDecimal(a, b, decimalPlaces) > 0;
}
///
@@ -1583,7 +865,7 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// true if the first value is smaller than the second value; otherwise false.
- public static bool IsSmallerWithDecimalPlaces(this double a, double b, int decimalPlaces)
+ public static bool IsSmallerDecimal(this double a, double b, int decimalPlaces)
{
// If A or B are a NAN, return false. NANs are equal to nothing,
// not even themselves, and thus they're not bigger or
@@ -1593,9 +875,9 @@ namespace MathNet.Numerics
return false;
}
- return CompareToInDecimalPlaces(a, b, decimalPlaces) < 0;
+ return CompareToDecimal(a, b, decimalPlaces) < 0;
}
-
+
///
/// Compares two floats and determines if the first value is smaller than the second
/// value to within the specified number of decimal places or not.
@@ -1611,17 +893,17 @@ namespace MathNet.Numerics
/// The second value.
/// The number of decimal places.
/// true if the first value is smaller than the second value; otherwise false.
- public static bool IsSmallerWithDecimalPlaces(this float a, float b, int decimalPlaces)
+ public static bool IsSmallerDecimal(this float a, float b, int decimalPlaces)
{
// If A or B are a NAN, return false. NANs are equal to nothing,
// not even themselves, and thus they're not bigger or
// smaller than anything either
- if (double.IsNaN(a) || double.IsNaN(b))
+ if (float.IsNaN(a) || float.IsNaN(b))
{
return false;
}
- return CompareToInDecimalPlaces(a, b, decimalPlaces) < 0;
+ return CompareToDecimal(a, b, decimalPlaces) < 0;
}
///
@@ -1669,7 +951,7 @@ namespace MathNet.Numerics
// If the numbers are equal to within the tolerance then
// there's technically no difference
- if (AlmostEqual(a, b, maxNumbersBetween))
+ if (AlmostEqualNumbersBetween(a, b, maxNumbersBetween))
{
return 0;
}
@@ -1703,7 +985,7 @@ namespace MathNet.Numerics
///
///
///
- public static int CompareToInDecimalPlaces(this double a, double b, int decimalPlaces)
+ public static int CompareToDecimal(this double a, double b, int decimalPlaces)
{
// If A or B are a NAN, return false. NANs are equal to nothing,
// not even themselves, and thus they're not bigger or
@@ -1722,7 +1004,7 @@ namespace MathNet.Numerics
// If the numbers are equal to within the number of decimal places
// then there's technically no difference
- if (AlmostEqualInDecimalPlaces(a, b, decimalPlaces))
+ if (AlmostEqualRelative(a, b, decimalPlaces))
{
return 0;
}
@@ -1785,7 +1067,7 @@ namespace MathNet.Numerics
///
public static double PositiveEpsilonOf(this double value)
{
- return 2 * EpsilonOf(value);
+ return 2*EpsilonOf(value);
}
///
diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
index db67e7eb..770ffc4b 100644
--- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
+++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
@@ -2581,7 +2581,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
test = stemp[l].Magnitude + stemp[l + 1].Magnitude;
ztest = test + e[l].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
e[l] = 0.0;
break;
@@ -2610,7 +2610,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
ztest = test + stemp[ls].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
stemp[ls] = 0.0;
break;
diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
index 757bb555..d986454f 100644
--- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
+++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
@@ -2579,7 +2579,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
test = stemp[l].Magnitude + stemp[l + 1].Magnitude;
ztest = test + e[l].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
e[l] = 0.0f;
break;
@@ -2608,7 +2608,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
ztest = test + stemp[ls].Magnitude;
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
stemp[ls] = 0.0f;
break;
diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
index d22dc12e..10a0dfbc 100644
--- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
+++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
@@ -2469,7 +2469,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
test = Math.Abs(stemp[l]) + Math.Abs(stemp[l + 1]);
ztest = test + Math.Abs(e[l]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
e[l] = 0.0;
break;
@@ -2498,7 +2498,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
ztest = test + Math.Abs(stemp[ls]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 15))
+ if (ztest.AlmostEqualRelative(test, 15))
{
stemp[ls] = 0.0;
break;
diff --git a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs
index 0db34a31..87e7860b 100644
--- a/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs
+++ b/src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs
@@ -2471,7 +2471,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
{
test = Math.Abs(stemp[l]) + Math.Abs(stemp[l + 1]);
ztest = test + Math.Abs(e[l]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
e[l] = 0.0f;
break;
@@ -2500,7 +2500,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
ztest = test + Math.Abs(stemp[ls]);
- if (ztest.AlmostEqualInDecimalPlaces(test, 7))
+ if (ztest.AlmostEqualRelative(test, 7))
{
stemp[ls] = 0.0f;
break;
diff --git a/src/Numerics/RootFinding/Bisection.cs b/src/Numerics/RootFinding/Bisection.cs
index a2b8cac8..d9701ad2 100644
--- a/src/Numerics/RootFinding/Bisection.cs
+++ b/src/Numerics/RootFinding/Bisection.cs
@@ -107,7 +107,7 @@ namespace MathNet.Numerics.RootFinding
for (int i = 0; i <= maxIterations; i++)
{
- if (Math.Abs(fmax - fmin) < 0.5*accuracy && upperBound.AlmostEqual(lowerBound))
+ if (Math.Abs(fmax - fmin) < 0.5*accuracy && upperBound.AlmostEqualRelative(lowerBound))
{
return true;
}
diff --git a/src/Numerics/RootFinding/Brent.cs b/src/Numerics/RootFinding/Brent.cs
index 41c103b6..ac1c6b13 100644
--- a/src/Numerics/RootFinding/Brent.cs
+++ b/src/Numerics/RootFinding/Brent.cs
@@ -100,7 +100,7 @@ namespace MathNet.Numerics.RootFinding
double xMidOld = xMid;
xMid = (upperBound - root)/2.0;
- if (Math.Abs(xMid) <= xAcc1 && froot.AlmostEqualWithAbsoluteError(0, froot, accuracy))
+ if (Math.Abs(xMid) <= xAcc1 && froot.AlmostEqualNormRelative(0, froot, accuracy))
{
return true;
}
@@ -117,7 +117,7 @@ namespace MathNet.Numerics.RootFinding
double s = froot/fmin;
double p;
double q;
- if (lowerBound.AlmostEqual(upperBound))
+ if (lowerBound.AlmostEqualRelative(upperBound))
{
p = 2.0*xMid*s;
q = 1.0 - s;
diff --git a/src/UnitTests/AssertHelpers.cs b/src/UnitTests/AssertHelpers.cs
index 49d5ed34..5a0c2f7f 100644
--- a/src/UnitTests/AssertHelpers.cs
+++ b/src/UnitTests/AssertHelpers.cs
@@ -40,10 +40,7 @@ namespace MathNet.Numerics.UnitTests
///
internal class AssertHelpers
{
- ///
- /// Asserts that the expected value and the actual value are equal.
- ///
- public static void AreEqual(Complex expected, Complex actual)
+ public static void AlmostEqual(Complex expected, Complex actual)
{
if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity())
{
@@ -61,10 +58,7 @@ namespace MathNet.Numerics.UnitTests
}
}
- ///
- /// Asserts that the expected value and the actual value are equal.
- ///
- public static void AreEqual(Complex32 expected, Complex32 actual)
+ public static void AlmostEqual(Complex32 expected, Complex32 actual)
{
if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity())
{
@@ -82,10 +76,7 @@ namespace MathNet.Numerics.UnitTests
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
- /// and are NaN then no assert is thrown.
- ///
+
public static void AlmostEqual(double expected, double actual, int decimalPlaces)
{
if (double.IsNaN(expected) && double.IsNaN(actual))
@@ -93,16 +84,12 @@ namespace MathNet.Numerics.UnitTests
return;
}
- if (!expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces))
+ if (!expected.AlmostEqual(actual, decimalPlaces))
{
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
- /// and are NaN then no assert is thrown.
- ///
public static void AlmostEqual(float expected, float actual, int decimalPlaces)
{
if (float.IsNaN(expected) && float.IsNaN(actual))
@@ -110,187 +97,175 @@ namespace MathNet.Numerics.UnitTests
return;
}
- if (!expected.AlmostEqualInDecimalPlaces(actual, decimalPlaces))
+ if (!expected.AlmostEqual(actual, decimalPlaces))
{
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
- ///
public static void AlmostEqual(Complex expected, Complex actual, int decimalPlaces)
{
- if (!expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces))
+ if (!expected.Real.AlmostEqual(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- if (!expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces))
+ if (!expected.Imaginary.AlmostEqual(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
- ///
public static void AlmostEqual(Complex32 expected, Complex32 actual, int decimalPlaces)
{
- if (!expected.Real.AlmostEqualInDecimalPlaces(actual.Real, decimalPlaces))
+ if (!expected.Real.AlmostEqual(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- if (!expected.Imaginary.AlmostEqualInDecimalPlaces(actual.Imaginary, decimalPlaces))
+ if (!expected.Imaginary.AlmostEqual(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
- /// and are NaN then no assert is thrown.
- ///
- public static void AlmostEqualAbsolute(double expected, double actual, int decimalPlaces)
+ public static void AlmostEqualRelative(double expected, double actual, int decimalPlaces)
{
if (double.IsNaN(expected) && double.IsNaN(actual))
{
return;
}
- if (!expected.AlmostEqualInAbsoluteDecimalPlaces(actual, decimalPlaces))
+ if (!expected.AlmostEqualRelative(actual, decimalPlaces))
{
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places. If both
- /// and are NaN then no assert is thrown.
- ///
- public static void AlmostEqualAbsolute(float expected, float actual, int decimalPlaces)
+ public static void AlmostEqualRelative(float expected, float actual, int decimalPlaces)
{
if (float.IsNaN(expected) && float.IsNaN(actual))
{
return;
}
- if (!expected.AlmostEqualInAbsoluteDecimalPlaces(actual, decimalPlaces))
+ if (!expected.AlmostEqualRelative(actual, decimalPlaces))
{
Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected, actual);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
- ///
- public static void AlmostEqualAbsolute(Complex expected, Complex actual, int decimalPlaces)
+ public static void AlmostEqualRelative(Complex expected, Complex actual, int decimalPlaces)
{
- if (!expected.Real.AlmostEqualInAbsoluteDecimalPlaces(actual.Real, decimalPlaces))
+ if (!expected.Real.AlmostEqualRelative(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- if (!expected.Imaginary.AlmostEqualInAbsoluteDecimalPlaces(actual.Imaginary, decimalPlaces))
+ if (!expected.Imaginary.AlmostEqualRelative(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain number of decimal places.
- ///
- public static void AlmostEqualAbsolute(Complex32 expected, Complex32 actual, int decimalPlaces)
+ public static void AlmostEqualRelative(Complex32 expected, Complex32 actual, int decimalPlaces)
{
- if (!expected.Real.AlmostEqualInAbsoluteDecimalPlaces(actual.Real, decimalPlaces))
+ if (!expected.Real.AlmostEqualRelative(actual.Real, decimalPlaces))
{
Assert.Fail("Real components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Real, actual.Real);
}
- if (!expected.Imaginary.AlmostEqualInAbsoluteDecimalPlaces(actual.Imaginary, decimalPlaces))
+ if (!expected.Imaginary.AlmostEqualRelative(actual.Imaginary, decimalPlaces))
{
Assert.Fail("Imaginary components are not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected.Imaginary, actual.Imaginary);
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain
- /// maximum error.
- ///
- /// The type of the structures. Must implement
- /// .
- /// The expected value.
- /// The actual value.
- /// The accuracy required for being almost equal.
- public static void AlmostEqual(T expected, T actual, double maximumError)
- where T : IPrecisionSupport
+
+ public static void ListAlmostEqual(IList expected, IList actual, int decimalPlaces)
{
- if (!actual.AlmostEqualWithError(expected, maximumError))
+ for (var i = 0; i < expected.Count; i++)
{
- Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected, actual);
+ if (!actual[i].AlmostEqual(expected[i], decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
+ }
+ }
+ }
+
+ public static void ListAlmostEqual(IList expected, IList actual, int decimalPlaces)
+ {
+ for (var i = 0; i < expected.Count; i++)
+ {
+ if (!actual[i].AlmostEqual(expected[i], decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
+ }
+ }
+ }
+
+ public static void ListAlmostEqual(IList expected, IList actual, int decimalPlaces)
+ {
+ for (var i = 0; i < expected.Count; i++)
+ {
+ if (!actual[i].AlmostEqual(expected[i], decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
+ }
+ }
+ }
+
+ public static void ListAlmostEqual(IList expected, IList actual, int decimalPlaces)
+ {
+ for (var i = 0; i < expected.Count; i++)
+ {
+ if (!actual[i].AlmostEqual(expected[i], decimalPlaces))
+ {
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
+ }
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain
- /// maximum error.
- ///
- public static void AlmostEqualList(IList expected, IList actual, double maximumError)
+ public static void ListAlmostEqualRelative(IList expected, IList actual, int decimalPlaces)
{
for (var i = 0; i < expected.Count; i++)
{
- if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
+ if (!actual[i].AlmostEqualRelative(expected[i], decimalPlaces))
{
- Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
}
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain
- /// maximum error.
- ///
- public static void AlmostEqualList(IList expected, IList actual, double maximumError)
+ public static void ListAlmostEqualRelative(IList expected, IList actual, int decimalPlaces)
{
for (var i = 0; i < expected.Count; i++)
{
- if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
+ if (!actual[i].AlmostEqualRelative(expected[i], decimalPlaces))
{
- Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
}
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain
- /// maximum error.
- ///
- /// The type of the structures. Must implement
- /// .
- public static void AlmostEqualList(IList expected, IList actual, double maximumError)
- where T : IPrecisionSupport
+ public static void ListAlmostEqualRelative(IList expected, IList actual, int decimalPlaces)
{
for (var i = 0; i < expected.Count; i++)
{
- if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
+ if (!actual[i].AlmostEqualRelative(expected[i], decimalPlaces))
{
- Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
}
}
}
- ///
- /// Asserts that the expected value and the actual value are equal up to a certain
- /// maximum error.
- ///
- public static void AlmostEqualList(IList expected, IList actual, double maximumError)
+ public static void ListAlmostEqualRelative(IList expected, IList actual, int decimalPlaces)
{
for (var i = 0; i < expected.Count; i++)
{
- if (!actual[i].AlmostEqualWithError(expected[i], maximumError))
+ if (!actual[i].AlmostEqualRelative(expected[i], decimalPlaces))
{
- Assert.Fail("Not equal within a maximum error {0}. Expected:{1}; Actual:{2}", maximumError, expected[i], actual[i]);
+ Assert.Fail("Not equal within {0} places. Expected:{1}; Actual:{2}", decimalPlaces, expected[i], actual[i]);
}
}
}
diff --git a/src/UnitTests/ComplexTests/Complex32Test.cs b/src/UnitTests/ComplexTests/Complex32Test.cs
index 64bf0154..0acccf26 100644
--- a/src/UnitTests/ComplexTests/Complex32Test.cs
+++ b/src/UnitTests/ComplexTests/Complex32Test.cs
@@ -121,7 +121,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var value = new Complex32(real, imag);
var expected = new Complex32(expectedReal, expectedImag);
- AssertHelpers.AlmostEqual(expected, value.Exponential(), 7);
+ AssertHelpers.AlmostEqualRelative(expected, value.Exponential(), 6);
}
///
@@ -140,7 +140,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var value = new Complex32(real, imag);
var expected = new Complex32(expectedReal, expectedImag);
- AssertHelpers.AlmostEqual(expected, value.NaturalLogarithm(), 7);
+ AssertHelpers.AlmostEqualRelative(expected, value.NaturalLogarithm(), 7);
}
///
@@ -151,38 +151,38 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var a = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
var b = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(
- new Complex32(9.99998047207974718744e-1f, -1.76553541154378695012e-6f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(
+ new Complex32(9.99998047207974718744e-1f, -1.76553541154378695012e-6f), a.Power(b), 6);
a = new Complex32(0.0f, 1.19209289550780998537e-7f);
b = new Complex32(0.0f, -1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(1.00000018725172576491f, 1.90048076369011843105e-6f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(1.00000018725172576491f, 1.90048076369011843105e-6f), a.Power(b), 6);
a = new Complex32(0.0f, -1.19209289550780998537e-7f);
b = new Complex32(0.0f, 0.5f);
- AssertHelpers.AlmostEqual(new Complex32(-2.56488189382693049636e-1f, -2.17823120666116144959f), a.Power(b), 5);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-2.56488189382693049636e-1f, -2.17823120666116144959f), a.Power(b), 4);
a = new Complex32(0.0f, 0.5f);
b = new Complex32(0.0f, -0.5f);
- AssertHelpers.AlmostEqual(new Complex32(2.06287223508090495171f, 7.45007062179724087859e-1f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(2.06287223508090495171f, 7.45007062179724087859e-1f), a.Power(b), 6);
a = new Complex32(0.0f, -0.5f);
b = new Complex32(0.0f, 1.0f);
- AssertHelpers.AlmostEqual(new Complex32(3.70040633557002510874f, -3.07370876701949232239f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(3.70040633557002510874f, -3.07370876701949232239f), a.Power(b), 6);
a = new Complex32(0.0f, 2.0f);
b = new Complex32(0.0f, -2.0f);
- AssertHelpers.AlmostEqual(new Complex32(4.24532146387429353891f, -2.27479427903521192648e1f), a.Power(b), 6);
+ AssertHelpers.AlmostEqualRelative(new Complex32(4.24532146387429353891f, -2.27479427903521192648e1f), a.Power(b), 5);
a = new Complex32(0.0f, -8.388608e6f);
b = new Complex32(1.19209289550780998537e-7f, 0.0f);
- AssertHelpers.AlmostEqual(new Complex32(1.00000190048219620166f, -1.87253870018168043834e-7f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(1.00000190048219620166f, -1.87253870018168043834e-7f), a.Power(b), 6);
a = new Complex32(0.0f, 0.0f);
b = new Complex32(0.0f, 0.0f);
- AssertHelpers.AlmostEqual(new Complex32(1.0f, 0.0f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(1.0f, 0.0f), a.Power(b), 6);
a = new Complex32(0.0f, 0.0f);
b = new Complex32(1.0f, 0.0f);
- AssertHelpers.AlmostEqual(new Complex32(0.0f, 0.0f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.0f, 0.0f), a.Power(b), 6);
a = new Complex32(0.0f, 0.0f);
b = new Complex32(-1.0f, 0.0f);
- AssertHelpers.AlmostEqual(new Complex32(float.PositiveInfinity, 0.0f), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(float.PositiveInfinity, 0.0f), a.Power(b), 6);
a = new Complex32(0.0f, 0.0f);
b = new Complex32(-1.0f, 1.0f);
- AssertHelpers.AlmostEqual(new Complex32(float.PositiveInfinity, float.PositiveInfinity), a.Power(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(float.PositiveInfinity, float.PositiveInfinity), a.Power(b), 6);
a = new Complex32(0.0f, 0.0f);
b = new Complex32(0.0f, 1.0f);
Assert.That(a.Power(b).IsNaN());
@@ -196,22 +196,22 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var a = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
var b = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(0.0f, 0.0f), a.Root(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.0f, 0.0f), a.Root(b), 6);
a = new Complex32(0.0f, -1.19209289550780998537e-7f);
b = new Complex32(0.0f, 0.5f);
- AssertHelpers.AlmostEqual(new Complex32(0.038550761943650161f, 0.019526430428319544f), a.Root(b), 6);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.038550761943650161f, 0.019526430428319544f), a.Root(b), 5);
a = new Complex32(0.0f, 0.5f);
b = new Complex32(0.0f, -0.5f);
- AssertHelpers.AlmostEqual(new Complex32(0.007927894711475968f, -0.042480480425152213f), a.Root(b), 6);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.007927894711475968f, -0.042480480425152213f), a.Root(b), 5);
a = new Complex32(0.0f, -0.5f);
b = new Complex32(0.0f, 1.0f);
- AssertHelpers.AlmostEqual(new Complex32(0.15990905692806806f, 0.13282699942462053f), a.Root(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.15990905692806806f, 0.13282699942462053f), a.Root(b), 6);
a = new Complex32(0.0f, 2.0f);
b = new Complex32(0.0f, -2.0f);
- AssertHelpers.AlmostEqual(new Complex32(0.42882900629436788f, 0.15487175246424678f), a.Root(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.42882900629436788f, 0.15487175246424678f), a.Root(b), 6);
a = new Complex32(0.0f, -8.388608e6f);
b = new Complex32(1.19209289550780998537e-7f, 0.0f);
- AssertHelpers.AlmostEqual(new Complex32(float.PositiveInfinity, float.NegativeInfinity), a.Root(b), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(float.PositiveInfinity, float.NegativeInfinity), a.Root(b), 6);
}
///
@@ -221,17 +221,17 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
public void CanComputeSquare()
{
var complex = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(0, 2.8421709430403888e-14f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0, 2.8421709430403888e-14f), complex.Square(), 7);
complex = new Complex32(0.0f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(-1.4210854715201944e-14f, 0.0f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-1.4210854715201944e-14f, 0.0f), complex.Square(), 7);
complex = new Complex32(0.0f, -1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(-1.4210854715201944e-14f, 0.0f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-1.4210854715201944e-14f, 0.0f), complex.Square(), 7);
complex = new Complex32(0.0f, 0.5f);
- AssertHelpers.AlmostEqual(new Complex32(-0.25f, 0.0f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-0.25f, 0.0f), complex.Square(), 7);
complex = new Complex32(0.0f, -0.5f);
- AssertHelpers.AlmostEqual(new Complex32(-0.25f, 0.0f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-0.25f, 0.0f), complex.Square(), 7);
complex = new Complex32(0.0f, -8.388608e6f);
- AssertHelpers.AlmostEqual(new Complex32(-70368744177664.0f, 0.0f), complex.Square(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(-70368744177664.0f, 0.0f), complex.Square(), 7);
}
///
@@ -241,24 +241,24 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
public void CanComputeSquareRoot()
{
var complex = new Complex32(1.19209289550780998537e-7f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(
+ AssertHelpers.AlmostEqualRelative(
new Complex32(0.00037933934912842666f, 0.00015712750315077684f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(
+ AssertHelpers.AlmostEqualRelative(
new Complex32(0.00024414062499999973f, 0.00024414062499999976f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, -1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(
+ AssertHelpers.AlmostEqualRelative(
new Complex32(0.00024414062499999973f, -0.00024414062499999976f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, 0.5f);
- AssertHelpers.AlmostEqual(new Complex32(0.5f, 0.5f), complex.SquareRoot(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.5f, 0.5f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, -0.5f);
- AssertHelpers.AlmostEqual(new Complex32(0.5f, -0.5f), complex.SquareRoot(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(0.5f, -0.5f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, -8.388608e6f);
- AssertHelpers.AlmostEqual(new Complex32(2048.0f, -2048.0f), complex.SquareRoot(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(2048.0f, -2048.0f), complex.SquareRoot(), 7);
complex = new Complex32(8.388608e6f, 1.19209289550780998537e-7f);
- AssertHelpers.AlmostEqual(new Complex32(2896.3093757400989f, 2.0579515874459933e-11f), complex.SquareRoot(), 7);
+ AssertHelpers.AlmostEqualRelative(new Complex32(2896.3093757400989f, 2.0579515874459933e-11f), complex.SquareRoot(), 7);
complex = new Complex32(0.0f, 0.0f);
- AssertHelpers.AlmostEqual(Complex32.Zero, complex.SquareRoot(), 7);
+ AssertHelpers.AlmostEqualRelative(Complex32.Zero, complex.SquareRoot(), 7);
}
///
diff --git a/src/UnitTests/ComplexTests/ComplexTest.cs b/src/UnitTests/ComplexTests/ComplexTest.cs
index dc10b314..9e4f7701 100644
--- a/src/UnitTests/ComplexTests/ComplexTest.cs
+++ b/src/UnitTests/ComplexTests/ComplexTest.cs
@@ -55,7 +55,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag);
- AssertHelpers.AlmostEqual(expected, value.Exp(), 15);
+ AssertHelpers.AlmostEqualRelative(expected, value.Exp(), 15);
}
///
@@ -74,7 +74,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag);
- AssertHelpers.AlmostEqual(expected, value.Ln(), 15);
+ AssertHelpers.AlmostEqualRelative(expected, value.Ln(), 14);
}
///
@@ -85,39 +85,39 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var a = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
var b = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(
- new Complex(9.99998047207974718744e-1, -1.76553541154378695012e-6), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(
+ new Complex(9.99998047207974718744e-1, -1.76553541154378695012e-6), a.Power(b), 14);
a = new Complex(0.0, 1.19209289550780998537e-7);
b = new Complex(0.0, -1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(new Complex(1.00000018725172576491, 1.90048076369011843105e-6), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(1.00000018725172576491, 1.90048076369011843105e-6), a.Power(b), 14);
a = new Complex(0.0, -1.19209289550780998537e-7);
b = new Complex(0.0, 0.5);
- AssertHelpers.AlmostEqual(new Complex(-2.56488189382693049636e-1, -2.17823120666116144959), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-2.56488189382693049636e-1, -2.17823120666116144959), a.Power(b), 14);
a = new Complex(0.0, 0.5);
b = new Complex(0.0, -0.5);
- AssertHelpers.AlmostEqual(new Complex(2.06287223508090495171, 7.45007062179724087859e-1), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(2.06287223508090495171, 7.45007062179724087859e-1), a.Power(b), 14);
a = new Complex(0.0, -0.5);
b = new Complex(0.0, 1.0);
- AssertHelpers.AlmostEqual(new Complex(3.70040633557002510874, -3.07370876701949232239), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(3.70040633557002510874, -3.07370876701949232239), a.Power(b), 14);
a = new Complex(0.0, 2.0);
b = new Complex(0.0, -2.0);
- AssertHelpers.AlmostEqual(new Complex(4.24532146387429353891, -2.27479427903521192648e1), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(4.24532146387429353891, -2.27479427903521192648e1), a.Power(b), 14);
a = new Complex(0.0, -8.388608e6);
b = new Complex(1.19209289550780998537e-7, 0.0);
- AssertHelpers.AlmostEqual(new Complex(1.00000190048219620166, -1.87253870018168043834e-7), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(1.00000190048219620166, -1.87253870018168043834e-7), a.Power(b), 14);
a = new Complex(0.0, 0.0);
b = new Complex(0.0, 0.0);
- AssertHelpers.AlmostEqual(new Complex(1.0, 0.0), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(1.0, 0.0), a.Power(b), 14);
a = new Complex(0.0, 0.0);
b = new Complex(1.0, 0.0);
- AssertHelpers.AlmostEqual(new Complex(0.0, 0.0), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.0, 0.0), a.Power(b), 14);
a = new Complex(0.0, 0.0);
b = new Complex(-1.0, 0.0);
- AssertHelpers.AlmostEqual(new Complex(double.PositiveInfinity, 0.0), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(double.PositiveInfinity, 0.0), a.Power(b), 14);
a = new Complex(0.0, 0.0);
b = new Complex(-1.0, 1.0);
- AssertHelpers.AlmostEqual(new Complex(double.PositiveInfinity, double.PositiveInfinity), a.Power(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(double.PositiveInfinity, double.PositiveInfinity), a.Power(b), 14);
a = new Complex(0.0, 0.0);
b = new Complex(0.0, 1.0);
Assert.That(a.Power(b).IsNaN());
@@ -131,23 +131,23 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
{
var a = new Complex(0.0, -1.19209289550780998537e-7);
var b = new Complex(0.0, 0.5);
- AssertHelpers.AlmostEqual(new Complex(0.038550761943650161, 0.019526430428319544), a.Root(b), 14);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.038550761943650161, 0.019526430428319544), a.Root(b), 13);
a = new Complex(0.0, 0.5);
b = new Complex(0.0, -0.5);
- AssertHelpers.AlmostEqual(new Complex(0.007927894711475968, -0.042480480425152213), a.Root(b), 14);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.007927894711475968, -0.042480480425152213), a.Root(b), 13);
a = new Complex(0.0, -0.5);
b = new Complex(0.0, 1.0);
- AssertHelpers.AlmostEqual(new Complex(0.15990905692806806, 0.13282699942462053), a.Root(b), 14);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.15990905692806806, 0.13282699942462053), a.Root(b), 13);
a = new Complex(0.0, 2.0);
b = new Complex(0.0, -2.0);
- AssertHelpers.AlmostEqual(new Complex(0.42882900629436788, 0.15487175246424678), a.Root(b), 14);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.42882900629436788, 0.15487175246424678), a.Root(b), 13);
//a = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
//b = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
//AssertHelpers.AlmostEqual(new Complex(0.0, 0.0), a.Root(b), 15);
a = new Complex(0.0, -8.388608e6);
b = new Complex(1.19209289550780998537e-7, 0.0);
- AssertHelpers.AlmostEqual(new Complex(double.PositiveInfinity, double.NegativeInfinity), a.Root(b), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(double.PositiveInfinity, double.NegativeInfinity), a.Root(b), 14);
}
///
@@ -157,17 +157,17 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
public void CanComputeSquare()
{
var complex = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(new Complex(0, 2.8421709430403888e-14), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(0, 2.8421709430403888e-14), complex.Square(), 15);
complex = new Complex(0.0, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15);
complex = new Complex(0.0, -1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15);
complex = new Complex(0.0, 0.5);
- AssertHelpers.AlmostEqual(new Complex(-0.25, 0.0), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-0.25, 0.0), complex.Square(), 15);
complex = new Complex(0.0, -0.5);
- AssertHelpers.AlmostEqual(new Complex(-0.25, 0.0), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-0.25, 0.0), complex.Square(), 15);
complex = new Complex(0.0, -8.388608e6);
- AssertHelpers.AlmostEqual(new Complex(-70368744177664.0, 0.0), complex.Square(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(-70368744177664.0, 0.0), complex.Square(), 15);
}
///
@@ -177,24 +177,24 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
public void CanComputeSquareRoot()
{
var complex = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(
- new Complex(0.00037933934912842666, 0.00015712750315077684), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(
+ new Complex(0.00037933934912842666, 0.00015712750315077684), complex.SquareRoot(), 14);
complex = new Complex(0.0, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(
- new Complex(0.00024414062499999973, 0.00024414062499999976), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(
+ new Complex(0.00024414062499999973, 0.00024414062499999976), complex.SquareRoot(), 14);
complex = new Complex(0.0, -1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(
- new Complex(0.00024414062499999973, -0.00024414062499999976), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(
+ new Complex(0.00024414062499999973, -0.00024414062499999976), complex.SquareRoot(), 14);
complex = new Complex(0.0, 0.5);
- AssertHelpers.AlmostEqual(new Complex(0.5, 0.5), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.5, 0.5), complex.SquareRoot(), 14);
complex = new Complex(0.0, -0.5);
- AssertHelpers.AlmostEqual(new Complex(0.5, -0.5), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(0.5, -0.5), complex.SquareRoot(), 14);
complex = new Complex(0.0, -8.388608e6);
- AssertHelpers.AlmostEqual(new Complex(2048.0, -2048.0), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(2048.0, -2048.0), complex.SquareRoot(), 14);
complex = new Complex(8.388608e6, 1.19209289550780998537e-7);
- AssertHelpers.AlmostEqual(new Complex(2896.3093757400989, 2.0579515874459933e-11), complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(new Complex(2896.3093757400989, 2.0579515874459933e-11), complex.SquareRoot(), 14);
complex = new Complex(0.0, 0.0);
- AssertHelpers.AlmostEqual(Complex.Zero, complex.SquareRoot(), 15);
+ AssertHelpers.AlmostEqualRelative(Complex.Zero, complex.SquareRoot(), 14);
}
///
diff --git a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs
index 7694e583..c245d636 100644
--- a/src/UnitTests/DistributionTests/Continuous/BetaTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/BetaTests.cs
@@ -191,7 +191,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateEntropy(double a, double b, double entropy)
{
var n = new Beta(a, b);
- AssertHelpers.AlmostEqual(entropy, n.Entropy, 14);
+ AssertHelpers.AlmostEqualRelative(entropy, n.Entropy, 13);
}
///
@@ -213,7 +213,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(double a, double b, double skewness)
{
var n = new Beta(a, b);
- AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
+ AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 14);
}
///
@@ -368,8 +368,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(double a, double b, double x, double pdf)
{
var n = new Beta(a, b);
- AssertHelpers.AlmostEqual(pdf, n.Density(x), 13);
- AssertHelpers.AlmostEqual(pdf, Beta.PDF(a, b, x), 13);
+ AssertHelpers.AlmostEqualRelative(pdf, n.Density(x), 12);
+ AssertHelpers.AlmostEqualRelative(pdf, Beta.PDF(a, b, x), 12);
}
///
@@ -414,8 +414,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(double a, double b, double x, double pdfln)
{
var n = new Beta(a, b);
- AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
- AssertHelpers.AlmostEqual(pdfln, Beta.PDFLn(a, b, x), 14);
+ AssertHelpers.AlmostEqualRelative(pdfln, n.DensityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(pdfln, Beta.PDFLn(a, b, x), 13);
}
///
@@ -458,8 +458,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double a, double b, double x, double cdf)
{
var n = new Beta(a, b);
- AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 13);
- AssertHelpers.AlmostEqual(cdf, Beta.CDF(a, b, x), 13);
+ AssertHelpers.AlmostEqualRelative(cdf, n.CumulativeDistribution(x), 13);
+ AssertHelpers.AlmostEqualRelative(cdf, Beta.CDF(a, b, x), 13);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
index 60b52b21..dba3872b 100644
--- a/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
@@ -240,7 +240,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateVariance(int shape, double invScale, double var)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(var, n.Variance, 15);
+ AssertHelpers.AlmostEqualRelative(var, n.Variance, 15);
}
///
@@ -258,7 +258,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateStdDev(int shape, double invScale, double sdev)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(sdev, n.StdDev, 15);
+ AssertHelpers.AlmostEqualRelative(sdev, n.StdDev, 15);
}
///
@@ -276,7 +276,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateEntropy(int shape, double invScale, double entropy)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(entropy, n.Entropy, 13);
+ AssertHelpers.AlmostEqualRelative(entropy, n.Entropy, 12);
}
///
@@ -294,7 +294,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(int shape, double invScale, double skewness)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
+ AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 15);
}
///
@@ -372,8 +372,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(int shape, double invScale, double x, double pdf)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
- AssertHelpers.AlmostEqual(pdf, Erlang.PDF(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(pdf, n.Density(x), 13);
+ AssertHelpers.AlmostEqualRelative(pdf, Erlang.PDF(shape, invScale, x), 13);
}
///
@@ -404,8 +404,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
- AssertHelpers.AlmostEqual(pdfln, Erlang.PDFLn(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(pdfln, n.DensityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(pdfln, Erlang.PDFLn(shape, invScale, x), 13);
}
///
@@ -457,8 +457,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(int shape, double invScale, double x, double cdf)
{
var n = new Erlang(shape, invScale);
- AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 14);
- AssertHelpers.AlmostEqual(cdf, Erlang.CDF(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(cdf, n.CumulativeDistribution(x), 13);
+ AssertHelpers.AlmostEqualRelative(cdf, Erlang.CDF(shape, invScale, x), 13);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs
index 6442a3d1..98e2e07f 100644
--- a/src/UnitTests/DistributionTests/Continuous/GammaTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/GammaTests.cs
@@ -244,7 +244,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateVariance(double shape, double invScale, double var)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(var, n.Variance, 15);
+ AssertHelpers.AlmostEqualRelative(var, n.Variance, 15);
}
///
@@ -262,7 +262,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateStdDev(double shape, double invScale, double sdev)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(sdev, n.StdDev, 15);
+ AssertHelpers.AlmostEqualRelative(sdev, n.StdDev, 15);
}
///
@@ -280,7 +280,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateEntropy(double shape, double invScale, double entropy)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(entropy, n.Entropy, 13);
+ AssertHelpers.AlmostEqualRelative(entropy, n.Entropy, 12);
}
///
@@ -298,7 +298,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(double shape, double invScale, double skewness)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
+ AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 15);
}
///
@@ -377,8 +377,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(int shape, double invScale, double x, double pdf)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
- AssertHelpers.AlmostEqual(pdf, Gamma.PDF(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(pdf, n.Density(x), 13);
+ AssertHelpers.AlmostEqualRelative(pdf, Gamma.PDF(shape, invScale, x), 13);
}
///
@@ -409,8 +409,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
- AssertHelpers.AlmostEqual(pdfln, Gamma.PDFLn(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(pdfln, n.DensityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(pdfln, Gamma.PDFLn(shape, invScale, x), 13);
}
///
@@ -499,8 +499,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(int shape, double invScale, double x, double cdf)
{
var n = new Gamma(shape, invScale);
- AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 14);
- AssertHelpers.AlmostEqual(cdf, Gamma.CDF(shape, invScale, x), 14);
+ AssertHelpers.AlmostEqualRelative(cdf, n.CumulativeDistribution(x), 13);
+ AssertHelpers.AlmostEqualRelative(cdf, Gamma.CDF(shape, invScale, x), 13);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
index eee3f768..d348eee3 100644
--- a/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
@@ -172,7 +172,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateEntropy(double mu, double sigma, double entropy)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(entropy, n.Entropy, 14);
+ AssertHelpers.AlmostEqualRelative(entropy, n.Entropy, 14);
}
///
@@ -208,7 +208,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(double mu, double sigma, double skewness)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(skewness, n.Skewness, 14);
+ AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 13);
}
///
@@ -316,7 +316,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateMean(double mu, double sigma, double mean)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(mean, n.Mean, 14);
+ AssertHelpers.AlmostEqualRelative(mean, n.Mean, 14);
}
///
@@ -377,8 +377,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(double mu, double sigma, double x, double p)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(p, n.Density(x), 14);
- AssertHelpers.AlmostEqual(p, LogNormal.PDF(mu, sigma, x), 14);
+ AssertHelpers.AlmostEqualRelative(p, n.Density(x), 13);
+ AssertHelpers.AlmostEqualRelative(p, LogNormal.PDF(mu, sigma, x), 13);
}
///
@@ -419,8 +419,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(double mu, double sigma, double x, double p)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
- AssertHelpers.AlmostEqual(p, LogNormal.PDFLn(mu, sigma, x), 14);
+ AssertHelpers.AlmostEqualRelative(p, n.DensityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(p, LogNormal.PDFLn(mu, sigma, x), 13);
}
///
@@ -519,8 +519,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double mu, double sigma, double x, double f)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);
- AssertHelpers.AlmostEqual(f, LogNormal.CDF(mu, sigma, x), 8);
+ AssertHelpers.AlmostEqualRelative(f, n.CumulativeDistribution(x), 7);
+ AssertHelpers.AlmostEqualRelative(f, LogNormal.CDF(mu, sigma, x), 7);
}
///
@@ -553,8 +553,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateInverseCumulativeDistribution(double mu, double sigma, double x, double f)
{
var n = new LogNormal(mu, sigma);
- AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 8);
- AssertHelpers.AlmostEqual(x, LogNormal.InvCDF(mu, sigma, f), 8);
+ AssertHelpers.AlmostEqualRelative(x, n.InverseCumulativeDistribution(f), 8);
+ AssertHelpers.AlmostEqualRelative(x, LogNormal.InvCDF(mu, sigma, f), 8);
}
///
@@ -570,8 +570,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
var original = new LogNormal(mu, sigma, new Random(100));
var estimated = LogNormal.Estimate(original.Samples().Take(10000));
- AssertHelpers.AlmostEqual(mu, estimated.Mu, 2);
- AssertHelpers.AlmostEqual(sigma, estimated.Sigma, 2);
+ AssertHelpers.AlmostEqualRelative(mu, estimated.Mu, 1);
+ AssertHelpers.AlmostEqualRelative(sigma, estimated.Sigma, 1);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs
index 55e19e18..c44cef16 100644
--- a/src/UnitTests/DistributionTests/Continuous/NormalTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/NormalTests.cs
@@ -123,8 +123,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void CanCreateNormalFromMeanAndVariance(double mean, double var)
{
var n = Normal.WithMeanVariance(mean, var);
- AssertHelpers.AlmostEqual(mean, n.Mean, 16);
- AssertHelpers.AlmostEqual(var, n.Variance, 16);
+ AssertHelpers.AlmostEqualRelative(mean, n.Mean, 15);
+ AssertHelpers.AlmostEqualRelative(var, n.Variance, 15);
}
///
@@ -141,8 +141,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void CanCreateNormalFromMeanAndPrecision(double mean, double prec)
{
var n = Normal.WithMeanPrecision(mean, prec);
- AssertHelpers.AlmostEqual(mean, n.Mean, 15);
- AssertHelpers.AlmostEqual(prec, n.Precision, 15);
+ AssertHelpers.AlmostEqualRelative(mean, n.Mean, 15);
+ AssertHelpers.AlmostEqualRelative(prec, n.Precision, 15);
}
///
@@ -472,8 +472,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double x, double f)
{
var n = Normal.WithMeanStdDev(5.0, 2.0);
- AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 10);
- AssertHelpers.AlmostEqual(f, Normal.CDF(5.0, 2.0, x), 10);
+ AssertHelpers.AlmostEqualRelative(f, n.CumulativeDistribution(x), 9);
+ AssertHelpers.AlmostEqualRelative(f, Normal.CDF(5.0, 2.0, x), 9);
}
///
@@ -494,8 +494,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateInverseCumulativeDistribution(double x, double f)
{
var n = Normal.WithMeanStdDev(5.0, 2.0);
- AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 15);
- AssertHelpers.AlmostEqual(x, Normal.InvCDF(5.0, 2.0, f), 15);
+ AssertHelpers.AlmostEqualRelative(x, n.InverseCumulativeDistribution(f), 14);
+ AssertHelpers.AlmostEqualRelative(x, Normal.InvCDF(5.0, 2.0, f), 14);
}
///
@@ -511,8 +511,8 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
var original = new Normal(mean, stddev, new Random(100));
var estimated = Normal.Estimate(original.Samples().Take(10000));
- AssertHelpers.AlmostEqual(mean, estimated.Mean, 2);
- AssertHelpers.AlmostEqual(stddev, estimated.StdDev, 2);
+ AssertHelpers.AlmostEqualRelative(mean, estimated.Mean, 1);
+ AssertHelpers.AlmostEqualRelative(stddev, estimated.StdDev, 1);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
index 6a87b93c..9c18612b 100644
--- a/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
@@ -182,7 +182,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(double scale, double skn)
{
var n = new Rayleigh(scale);
- AssertHelpers.AlmostEqual(skn, n.Skewness, 17);
+ AssertHelpers.AlmostEqualRelative(skn, n.Skewness, 17);
}
///
diff --git a/src/UnitTests/DistributionTests/Continuous/StableTests.cs b/src/UnitTests/DistributionTests/Continuous/StableTests.cs
index dfb0dcdb..0eeba6b9 100644
--- a/src/UnitTests/DistributionTests/Continuous/StableTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/StableTests.cs
@@ -341,7 +341,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(double alpha, double beta, double scale, double location, double x, double d)
{
var n = new Stable(alpha, beta, scale, location);
- AssertHelpers.AlmostEqual(d, n.Density(x), 15);
+ AssertHelpers.AlmostEqualRelative(d, n.Density(x), 15);
}
///
@@ -365,7 +365,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(double alpha, double beta, double scale, double location, double x, double dln)
{
var n = new Stable(alpha, beta, scale, location);
- AssertHelpers.AlmostEqual(dln, n.DensityLn(x), 15);
+ AssertHelpers.AlmostEqualRelative(dln, n.DensityLn(x), 15);
}
///
@@ -410,7 +410,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double alpha, double beta, double scale, double location, double x, double cdf)
{
var n = new Stable(alpha, beta, scale, location);
- AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 15);
+ AssertHelpers.AlmostEqualRelative(cdf, n.CumulativeDistribution(x), 15);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
index 22d19b02..c75ddcf4 100644
--- a/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
@@ -341,7 +341,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(double location, double scale, double dof, double x, double p)
{
var n = new StudentT(location, scale, dof);
- AssertHelpers.AlmostEqual(p, n.Density(x), 13);
+ AssertHelpers.AlmostEqualRelative(p, n.Density(x), 13);
}
///
@@ -368,7 +368,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(double location, double scale, double dof, double x, double p)
{
var n = new StudentT(location, scale, dof);
- AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(p, n.DensityLn(x), 13);
}
///
@@ -454,7 +454,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double location, double scale, double dof, double x, double c)
{
var n = new StudentT(location, scale, dof);
- AssertHelpers.AlmostEqual(c, n.CumulativeDistribution(x), 13);
+ AssertHelpers.AlmostEqualRelative(c, n.CumulativeDistribution(x), 13);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
index c67426fb..bb76f330 100644
--- a/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
+++ b/src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
@@ -164,7 +164,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateMean(double shape, double scale, double mean)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(mean, n.Mean, 13);
+ AssertHelpers.AlmostEqualRelative(mean, n.Mean, 13);
}
///
@@ -180,7 +180,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateVariance(double shape, double scale, double var)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(var, n.Variance, 13);
+ AssertHelpers.AlmostEqualRelative(var, n.Variance, 12);
}
///
@@ -196,7 +196,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateStdDev(double shape, double scale, double sdev)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(sdev, n.StdDev, 13);
+ AssertHelpers.AlmostEqualRelative(sdev, n.StdDev, 12);
}
///
@@ -212,7 +212,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateSkewness(double shape, double scale, double skewness)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(skewness, n.Skewness, 11);
+ AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 10);
}
///
@@ -244,7 +244,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateMedian(double shape, double scale, double median)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(median, n.Median, 13);
+ AssertHelpers.AlmostEqualRelative(median, n.Median, 13);
}
///
@@ -289,7 +289,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensity(double shape, double scale, double x, double pdf)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
+ AssertHelpers.AlmostEqualRelative(pdf, n.Density(x), 13);
}
///
@@ -314,7 +314,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateDensityLn(double shape, double scale, double x, double pdfln)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
+ AssertHelpers.AlmostEqualRelative(pdfln, n.DensityLn(x), 14);
}
///
@@ -397,7 +397,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
public void ValidateCumulativeDistribution(double shape, double scale, double x, double cdf)
{
var n = new Weibull(shape, scale);
- AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 15);
+ AssertHelpers.AlmostEqualRelative(cdf, n.CumulativeDistribution(x), 14);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs b/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
index 293ee42d..2c2b260b 100644
--- a/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
@@ -119,7 +119,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateEntropy(double p)
{
var b = new Bernoulli(p);
- AssertHelpers.AlmostEqual(-((1.0 - p) * Math.Log(1.0 - p)) - (p * Math.Log(p)), b.Entropy, 14);
+ AssertHelpers.AlmostEqualRelative(-((1.0 - p) * Math.Log(1.0 - p)) - (p * Math.Log(p)), b.Entropy, 14);
}
///
diff --git a/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs b/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
index 12b5f49e..98cc03b1 100644
--- a/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
@@ -125,7 +125,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateEntropy(double p, int n, double e)
{
var b = new Binomial(p, n);
- AssertHelpers.AlmostEqual(e, b.Entropy, 14);
+ AssertHelpers.AlmostEqualRelative(e, b.Entropy, 14);
}
///
@@ -211,7 +211,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateProbability(double p, int n, int x, double d)
{
var b = new Binomial(p, n);
- AssertHelpers.AlmostEqual(d, b.Probability(x), 14);
+ AssertHelpers.AlmostEqualRelative(d, b.Probability(x), 14);
}
///
@@ -248,7 +248,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateProbabilityLn(double p, int n, int x, double dln)
{
var b = new Binomial(p, n);
- AssertHelpers.AlmostEqual(dln, b.ProbabilityLn(x), 14);
+ AssertHelpers.AlmostEqualRelative(dln, b.ProbabilityLn(x), 14);
}
///
diff --git a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
index 43b5c113..9c2d7c53 100644
--- a/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
@@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateMean(int lambda, int nu, double mean)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
- AssertHelpers.AlmostEqual(mean, d.Mean, 10);
+ AssertHelpers.AlmostEqualRelative(mean, d.Mean, 10);
}
///
@@ -236,7 +236,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateProbability(double lambda, double nu, int x, double p)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
- AssertHelpers.AlmostEqual(p, d.Probability(x), 13);
+ AssertHelpers.AlmostEqualRelative(p, d.Probability(x), 12);
}
///
@@ -255,7 +255,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateProbabilityLn(double lambda, double nu, int x, double pln)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
- AssertHelpers.AlmostEqual(pln, d.ProbabilityLn(x), 13);
+ AssertHelpers.AlmostEqualRelative(pln, d.ProbabilityLn(x), 12);
}
///
@@ -295,7 +295,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateCumulativeDistribution(double lambda, double nu, int x, double cdf)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
- AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 13);
+ AssertHelpers.AlmostEqualRelative(cdf, d.CumulativeDistribution(x), 12);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs b/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
index cf740cb4..16f2ef56 100644
--- a/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
@@ -151,7 +151,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateEntropy(int l, int u, double e)
{
var du = new DiscreteUniform(l, u);
- AssertHelpers.AlmostEqual(e, du.Entropy, 14);
+ AssertHelpers.AlmostEqualRelative(e, du.Entropy, 14);
}
///
diff --git a/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs b/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
index 28a4dbcf..b3c6c366 100644
--- a/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
@@ -355,7 +355,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateCumulativeDistribution(int population, int success, int draws, double x, double cdf)
{
var d = new Hypergeometric(population, success, draws);
- AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 10);
+ AssertHelpers.AlmostEqualRelative(cdf, d.CumulativeDistribution(x), 9);
}
[Test]
diff --git a/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs b/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs
index de92ba6a..39ba4470 100644
--- a/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs
+++ b/src/UnitTests/DistributionTests/Discrete/ZipfTests.cs
@@ -153,7 +153,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
public void ValidateEntropy(double s, int n, double e)
{
var d = new Zipf(s, n);
- AssertHelpers.AlmostEqual(e, d.Entropy, 15);
+ AssertHelpers.AlmostEqualRelative(e, d.Entropy, 15);
}
///
@@ -292,7 +292,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
{
var d = new Zipf(s, n);
var cdf = SpecialFunctions.GeneralHarmonic(x, s) / SpecialFunctions.GeneralHarmonic(n, s);
- AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 14);
+ AssertHelpers.AlmostEqualRelative(cdf, d.CumulativeDistribution(x), 14);
}
}
}
diff --git a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs
index a03f1622..d8b08bbc 100644
--- a/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs
+++ b/src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs
@@ -172,7 +172,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
for (var i = 0; i < 5; i++)
{
- AssertHelpers.AlmostEqual(0.3 / 1.5, d.Mean[i], 15);
+ AssertHelpers.AlmostEqualRelative(0.3 / 1.5, d.Mean[i], 15);
}
}
@@ -193,7 +193,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
var d = new Dirichlet(alpha);
for (var i = 0; i < 10; i++)
{
- AssertHelpers.AlmostEqual(i * (sum - i) / (sum * sum * (sum + 1.0)), d.Variance[i], 15);
+ AssertHelpers.AlmostEqualRelative(i * (sum - i) / (sum * sum * (sum + 1.0)), d.Variance[i], 15);
}
}
@@ -210,7 +210,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
public void ValidateDensity(double[] x, double res)
{
var d = new Dirichlet(new[] { 0.1, 0.3, 0.5, 0.8 });
- AssertHelpers.AlmostEqual(res, d.Density(x), 12);
+ AssertHelpers.AlmostEqualRelative(res, d.Density(x), 12);
}
///
@@ -222,7 +222,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
public void ValidateDensityLn(double[] x)
{
var d = new Dirichlet(new[] { 0.1, 0.3, 0.5, 0.8 });
- AssertHelpers.AlmostEqual(d.DensityLn(x), Math.Log(d.Density(x)), 12);
+ AssertHelpers.AlmostEqualRelative(d.DensityLn(x), Math.Log(d.Density(x)), 12);
}
///
@@ -237,7 +237,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
{
var d = new Dirichlet(new[] { 0.1, 0.3 });
var beta = new Beta(0.1, 0.3);
- AssertHelpers.AlmostEqual(d.DensityLn(new[] { x }), beta.DensityLn(x), 10);
+ AssertHelpers.AlmostEqualRelative(d.DensityLn(new[] { x }), beta.DensityLn(x), 10);
}
///
@@ -252,7 +252,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
var sum = x.Sum(t => (t - 1) * SpecialFunctions.DiGamma(t));
var res = SpecialFunctions.GammaLn(x.Sum()) + ((x.Sum() - x.Length) * SpecialFunctions.DiGamma(x.Sum())) - sum;
- AssertHelpers.AlmostEqual(res, d.Entropy, 12);
+ AssertHelpers.AlmostEqualRelative(res, d.Entropy, 12);
}
///
diff --git a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs
index 96447ab0..4d50814f 100644
--- a/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs
+++ b/src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs
@@ -284,7 +284,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
x[0, 0] = 5;
var d = new InverseWishart(nu, matrix);
- AssertHelpers.AlmostEqual(density, d.Density(x), 16);
+ AssertHelpers.AlmostEqualRelative(density, d.Density(x), 16);
}
///
diff --git a/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs b/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs
index 8353faa1..8275162b 100644
--- a/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs
+++ b/src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs
@@ -294,7 +294,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
x[0, 0] = 2;
x[0, 1] = 2;
- AssertHelpers.AlmostEqual(0.00015682927366491211, d.Density(x), 16);
+ AssertHelpers.AlmostEqualRelative(0.00015682927366491211, d.Density(x), 16);
}
///
diff --git a/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs b/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs
index 8c3b27a1..26df25d9 100644
--- a/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs
+++ b/src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs
@@ -149,7 +149,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
{
- AssertHelpers.AlmostEqual(res[i], b.Skewness[i], 12);
+ AssertHelpers.AlmostEqualRelative(res[i], b.Skewness[i], 12);
}
}
@@ -167,7 +167,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
{
- AssertHelpers.AlmostEqual(res[i], b.Variance[i], 12);
+ AssertHelpers.AlmostEqualRelative(res[i], b.Variance[i], 12);
}
}
@@ -185,7 +185,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
{
- AssertHelpers.AlmostEqual(res[i], b.Mean[i], 12);
+ AssertHelpers.AlmostEqualRelative(res[i], b.Mean[i], 12);
}
}
@@ -201,7 +201,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
public void ValidateProbability(double[] p, int[] x, double res)
{
var b = new Multinomial(p, x.Sum());
- AssertHelpers.AlmostEqual(b.Probability(x), res, 12);
+ AssertHelpers.AlmostEqualRelative(b.Probability(x), res, 12);
}
///
@@ -214,7 +214,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
public void ValidateProbabilityLn(int[] x)
{
var b = new Multinomial(_largeP, x.Sum());
- AssertHelpers.AlmostEqual(b.ProbabilityLn(x), Math.Log(b.Probability(x)), 12);
+ AssertHelpers.AlmostEqualRelative(b.ProbabilityLn(x), Math.Log(b.Probability(x)), 12);
}
///
diff --git a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs
index b7387841..4c6dd717 100644
--- a/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs
+++ b/src/UnitTests/DistributionTests/Multivariate/WishartTests.cs
@@ -286,7 +286,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
x[0, 0] = 5;
var d = new Wishart(nu, matrix);
- AssertHelpers.AlmostEqual(density, d.Density(x), 16);
+ AssertHelpers.AlmostEqualRelative(density, d.Density(x), 16);
}
///
diff --git a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs b/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs
index 5343c525..40386709 100644
--- a/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs
+++ b/src/UnitTests/FinancialTests/CompoundMonthlyReturnTests.cs
@@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.FinancialTests
//act
var cmpdReturn = inputData.CompoundMonthlyReturn();
//assert
- AssertHelpers.AlmostEqual(0.0870999982199265, cmpdReturn, 15);
+ AssertHelpers.AlmostEqualRelative(0.0870999982199265, cmpdReturn, 14);
}
//Definitly need more tests here. Would love to find test data for these stats similar to the .dat files used for other tests.
diff --git a/src/UnitTests/IntegralTransformsTests/FourierTest.cs b/src/UnitTests/IntegralTransformsTests/FourierTest.cs
index 61ca37c4..0ac02a4c 100644
--- a/src/UnitTests/IntegralTransformsTests/FourierTest.cs
+++ b/src/UnitTests/IntegralTransformsTests/FourierTest.cs
@@ -101,20 +101,10 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
var dft = new DiscreteFourierTransform();
- Assert.Throws(
- typeof (ArgumentException),
- () => dft.Radix2Forward(samples, FourierOptions.Default));
-
- Assert.Throws(
- typeof (ArgumentException),
- () => dft.Radix2Inverse(samples, FourierOptions.Default));
-
- Assert.Throws(
- typeof (ArgumentException),
- () => DiscreteFourierTransform.Radix2(samples, -1));
- Assert.Throws(
- typeof (ArgumentException),
- () => DiscreteFourierTransform.Radix2Parallel(samples, -1));
+ Assert.Throws(typeof (ArgumentException), () => dft.Radix2Forward(samples, FourierOptions.Default));
+ Assert.Throws(typeof (ArgumentException), () => dft.Radix2Inverse(samples, FourierOptions.Default));
+ Assert.Throws(typeof (ArgumentException), () => DiscreteFourierTransform.Radix2(samples, -1));
+ Assert.Throws(typeof (ArgumentException), () => DiscreteFourierTransform.Radix2Parallel(samples, -1));
}
}
}
diff --git a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs
index e364e1a0..cf1a86f4 100644
--- a/src/UnitTests/IntegralTransformsTests/HartleyTest.cs
+++ b/src/UnitTests/IntegralTransformsTests/HartleyTest.cs
@@ -58,14 +58,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
///
/// Verify if matches DFT.
///
- /// Samples array.
- /// Maximum error value.
- /// Is inverse.
- /// DFT function delegate.
- /// Hartley transform delegate.
static void VerifyMatchesDft(
double[] samples,
- double maximumError,
+ int maximumErrorDecimalPlaces,
bool inverse,
Action dft,
Func hartley)
@@ -76,7 +71,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
dft(fourierComplex);
var fourierReal = ArrayHelpers.ConvertAll(fourierComplex, s => s.Real);
- AssertHelpers.AlmostEqualList(fourierReal, hartleyReal, maximumError);
+ AssertHelpers.ListAlmostEqual(fourierReal, hartleyReal, maximumErrorDecimalPlaces);
}
///
@@ -94,13 +89,13 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesDft(
samples,
- 1e-5,
+ 5,
false,
s => Transform.FourierForward(s, fourierOptions),
s => dht.NaiveForward(s, hartleyOptions));
VerifyMatchesDft(
samples,
- 1e-5,
+ 5,
true,
s => Transform.FourierInverse(s, fourierOptions),
s => dht.NaiveInverse(s, hartleyOptions));
diff --git a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs
index 9fef9cdf..d6be87dc 100644
--- a/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs
+++ b/src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs
@@ -24,7 +24,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using MathNet.Numerics.Distributions;
using MathNet.Numerics.IntegralTransforms;
using MathNet.Numerics.IntegralTransforms.Algorithms;
@@ -55,58 +54,6 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
return new ContinuousUniform(-1, 1, new Random(seed));
}
- ///
- /// Verify if is reversible complex.
- ///
- /// Samples count.
- /// Maximum error value.
- /// Forward delegate.
- /// Inverse delegate.
- void VerifyIsReversibleComplex(
- int count,
- double maximumError,
- Func forward,
- Func inverse)
- {
- var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), count);
- var work = new Complex[samples.Length];
- samples.CopyTo(work, 0);
-
- work = forward(work);
-
- Assert.IsFalse(work.AlmostEqualListWithError(samples, maximumError));
-
- work = inverse(work);
-
- AssertHelpers.AlmostEqualList(samples, work, maximumError);
- }
-
- ///
- /// Verify if is reversible real.
- ///
- /// Samples count.
- /// Maximum error value.
- /// Forward delegate.
- /// Inverse delegate.
- void VerifyIsReversibleReal(
- int count,
- double maximumError,
- Func forward,
- Func inverse)
- {
- var samples = SignalGenerator.Random(x => x, GetUniform(1), count);
- var work = new double[samples.Length];
- samples.CopyTo(work, 0);
-
- work = forward(work);
-
- Assert.IsFalse(work.AlmostEqualListWithError(samples, maximumError));
-
- work = inverse(work);
-
- AssertHelpers.AlmostEqualList(samples, work, maximumError);
- }
-
///
/// Fourier naive is reversible.
///
@@ -117,11 +64,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
{
var dft = new DiscreteFourierTransform();
- VerifyIsReversibleComplex(
- 0x80,
- 1e-12,
- s => dft.NaiveForward(s, options),
- s => dft.NaiveInverse(s, options));
+ var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x80);
+ var work = new Complex[samples.Length];
+ samples.CopyTo(work, 0);
+
+ work = dft.NaiveForward(work, options);
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
+
+ work = dft.NaiveInverse(work, options);
+ AssertHelpers.ListAlmostEqual(samples, work, 12);
}
///
@@ -134,19 +85,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
{
var dft = new DiscreteFourierTransform();
- VerifyIsReversibleComplex(
- 0x8000,
- 1e-12,
- s =>
- {
- dft.Radix2Forward(s, options);
- return s;
- },
- s =>
- {
- dft.Radix2Inverse(s, options);
- return s;
- });
+ var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x8000);
+ var work = new Complex[samples.Length];
+ samples.CopyTo(work, 0);
+
+ dft.Radix2Forward(work, options);
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
+
+ dft.Radix2Inverse(work, options);
+ AssertHelpers.ListAlmostEqual(samples, work, 12);
}
///
@@ -159,19 +106,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
{
var dft = new DiscreteFourierTransform();
- VerifyIsReversibleComplex(
- 0x7FFF,
- 1e-12,
- s =>
- {
- dft.BluesteinForward(s, options);
- return s;
- },
- s =>
- {
- dft.BluesteinInverse(s, options);
- return s;
- });
+ var samples = SignalGenerator.Random((u, v) => new Complex(u, v), GetUniform(1), 0x7FFF);
+ var work = new Complex[samples.Length];
+ samples.CopyTo(work, 0);
+
+ dft.BluesteinForward(work, options);
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
+
+ dft.BluesteinInverse(work, options);
+ AssertHelpers.ListAlmostEqual(samples, work, 10);
}
///
@@ -184,11 +127,15 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
{
var dht = new DiscreteHartleyTransform();
- VerifyIsReversibleReal(
- 0x80,
- 1e-9,
- s => dht.NaiveForward(s, options),
- s => dht.NaiveInverse(s, options));
+ var samples = SignalGenerator.Random(x => x, GetUniform(1), 0x80);
+ var work = new double[samples.Length];
+ samples.CopyTo(work, 0);
+
+ work = dht.NaiveForward(work, options);
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
+
+ work = dht.NaiveInverse(work, options);
+ AssertHelpers.ListAlmostEqual(samples, work, 12);
}
///
@@ -202,19 +149,16 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
samples.CopyTo(work, 0);
Transform.FourierForward(work);
-
- Assert.IsFalse(work.AlmostEqualListWithError(samples, 1e-12));
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
Transform.FourierInverse(work);
-
- AssertHelpers.AlmostEqualList(samples, work, 1e-12);
+ AssertHelpers.ListAlmostEqual(samples, work, 10);
Transform.FourierInverse(work, FourierOptions.Default);
-
- Assert.IsFalse(work.AlmostEqualListWithError(samples, 1e-12));
+ Assert.IsFalse(work.ListAlmostEqual(samples, 6));
Transform.FourierForward(work, FourierOptions.Default);
- AssertHelpers.AlmostEqualList(samples, work, 1e-12);
+ AssertHelpers.ListAlmostEqual(samples, work, 10);
}
}
}
diff --git a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs
index c9164f6a..ff0f1bf8 100644
--- a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs
+++ b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs
@@ -58,13 +58,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
///
/// Verify matches naive complex.
///
- /// Samples count.
- /// Maximum error.
- /// Naive transform.
- /// Fast delegate.
static void VerifyMatchesNaiveComplex(
Complex[] samples,
- double maximumError,
+ int maximumErrorDecimalPlaces,
Func naive,
Action fast)
{
@@ -74,7 +70,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
samples.CopyTo(spectrumFast, 0);
fast(spectrumFast);
- AssertHelpers.AlmostEqualList(spectrumNaive, spectrumFast, maximumError);
+ AssertHelpers.ListAlmostEqual(spectrumNaive, spectrumFast, maximumErrorDecimalPlaces);
}
///
@@ -91,13 +87,13 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 12,
s => dft.NaiveForward(s, options),
s => dft.Radix2Forward(s, options));
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 12,
s => dft.NaiveInverse(s, options),
s => dft.Radix2Inverse(s, options));
}
@@ -116,13 +112,13 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveForward(s, options),
s => dft.Radix2Forward(s, options));
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveInverse(s, options),
s => dft.Radix2Inverse(s, options));
}
@@ -141,13 +137,13 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 12,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 12,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
@@ -166,13 +162,13 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
@@ -191,12 +187,12 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
- 1e-12,
+ 10,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
diff --git a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs
index 41f2ae7d..02c5545c 100644
--- a/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs
+++ b/src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs
@@ -137,7 +137,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
public void CanComputeDotProduct()
{
var result = Control.LinearAlgebraProvider.DotProduct(_x, _y);
- AssertHelpers.AlmostEqual(152.35, result, 15);
+ AssertHelpers.AlmostEqualRelative(152.35, result, 15);
}
///
@@ -205,7 +205,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
- AssertHelpers.AlmostEqual(12.1, norm, 6);
+ AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
///
@@ -217,7 +217,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
- AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
+ AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
///
@@ -241,7 +241,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
- AssertHelpers.AlmostEqual(12.1, norm, 6);
+ AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
///
@@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
- AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
+ AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
///
@@ -284,7 +284,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -305,7 +305,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -326,7 +326,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -347,7 +347,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -368,7 +368,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -389,7 +389,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var j = 0; j < c.ColumnCount; j++)
{
- AssertHelpers.AlmostEqual(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
+ AssertHelpers.AlmostEqualRelative(2.2*x.Row(i)*y.Column(j), c[i, j], 15);
}
}
}
@@ -408,15 +408,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
Control.LinearAlgebraProvider.LUFactor(a, matrix.RowCount, ipiv);
- AssertHelpers.AlmostEqual(a[0], -4.4, 15);
- AssertHelpers.AlmostEqual(a[1], 0.25, 15);
- AssertHelpers.AlmostEqual(a[2], 0, 15);
- AssertHelpers.AlmostEqual(a[3], 5.5, 15);
- AssertHelpers.AlmostEqual(a[4], -3.575, 15);
- AssertHelpers.AlmostEqual(a[5], -0.307692307692308, 15);
- AssertHelpers.AlmostEqual(a[6], 6.6, 15);
- AssertHelpers.AlmostEqual(a[7], -4.95, 15);
- AssertHelpers.AlmostEqual(a[8], 0.676923076923077, 15);
+ AssertHelpers.AlmostEqualRelative(a[0], -4.4, 15);
+ AssertHelpers.AlmostEqualRelative(a[1], 0.25, 15);
+ AssertHelpers.AlmostEqualRelative(a[2], 0, 15);
+ AssertHelpers.AlmostEqualRelative(a[3], 5.5, 15);
+ AssertHelpers.AlmostEqualRelative(a[4], -3.575, 15);
+ AssertHelpers.AlmostEqualRelative(a[5], -0.307692307692308, 14);
+ AssertHelpers.AlmostEqualRelative(a[6], 6.6, 15);
+ AssertHelpers.AlmostEqualRelative(a[7], -4.95, 14);
+ AssertHelpers.AlmostEqualRelative(a[8], 0.676923076923077, 14);
Assert.AreEqual(ipiv[0], 2);
Assert.AreEqual(ipiv[1], 2);
Assert.AreEqual(ipiv[2], 2);
@@ -434,15 +434,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount);
- AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
- AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
- AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
- AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
- AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
- AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
- AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
+ AssertHelpers.AlmostEqualRelative(a[0], -0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[1], -0.909090909090908, 13);
+ AssertHelpers.AlmostEqualRelative(a[2], 0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[3], -0.340909090909090, 13);
+ AssertHelpers.AlmostEqualRelative(a[4], -2.045454545454543, 13);
+ AssertHelpers.AlmostEqualRelative(a[5], 1.477272727272726, 13);
+ AssertHelpers.AlmostEqualRelative(a[6], -0.113636363636364, 13);
+ AssertHelpers.AlmostEqualRelative(a[7], 0.227272727272727, 13);
+ AssertHelpers.AlmostEqualRelative(a[8], -0.113636363636364, 13);
}
///
@@ -461,15 +461,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
Control.LinearAlgebraProvider.LUFactor(a, matrix.RowCount, ipiv);
Control.LinearAlgebraProvider.LUInverseFactored(a, matrix.RowCount, ipiv);
- AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
- AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
- AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
- AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
- AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
- AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
- AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
+ AssertHelpers.AlmostEqualRelative(a[0], -0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[1], -0.909090909090908, 13);
+ AssertHelpers.AlmostEqualRelative(a[2], 0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[3], -0.340909090909090, 13);
+ AssertHelpers.AlmostEqualRelative(a[4], -2.045454545454543, 13);
+ AssertHelpers.AlmostEqualRelative(a[5], 1.477272727272726, 13);
+ AssertHelpers.AlmostEqualRelative(a[6], -0.113636363636364, 13);
+ AssertHelpers.AlmostEqualRelative(a[7], 0.227272727272727, 13);
+ AssertHelpers.AlmostEqualRelative(a[8], -0.113636363636364, 13);
}
///
@@ -486,15 +486,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var work = new Complex[matrix.RowCount];
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount, work);
- AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
- AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
- AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
- AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
- AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
- AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
- AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
+ AssertHelpers.AlmostEqualRelative(a[0], -0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[1], -0.909090909090908, 13);
+ AssertHelpers.AlmostEqualRelative(a[2], 0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[3], -0.340909090909090, 13);
+ AssertHelpers.AlmostEqualRelative(a[4], -2.045454545454543, 13);
+ AssertHelpers.AlmostEqualRelative(a[5], 1.477272727272726, 13);
+ AssertHelpers.AlmostEqualRelative(a[6], -0.113636363636364, 13);
+ AssertHelpers.AlmostEqualRelative(a[7], 0.227272727272727, 13);
+ AssertHelpers.AlmostEqualRelative(a[8], -0.113636363636364, 13);
}
///
@@ -515,15 +515,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var work = new Complex[matrix.RowCount];
Control.LinearAlgebraProvider.LUInverseFactored(a, matrix.RowCount, ipiv, work);
- AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
- AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
- AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
- AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
- AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
- AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
- AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
- AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
+ AssertHelpers.AlmostEqualRelative(a[0], -0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[1], -0.909090909090908, 13);
+ AssertHelpers.AlmostEqualRelative(a[2], 0.454545454545454, 13);
+ AssertHelpers.AlmostEqualRelative(a[3], -0.340909090909090, 13);
+ AssertHelpers.AlmostEqualRelative(a[4], -2.045454545454543, 13);
+ AssertHelpers.AlmostEqualRelative(a[5], 1.477272727272726, 13);
+ AssertHelpers.AlmostEqualRelative(a[6], -0.113636363636364, 13);
+ AssertHelpers.AlmostEqualRelative(a[7], 0.227272727272727, 13);
+ AssertHelpers.AlmostEqualRelative(a[8], -0.113636363636364, 13);
}
///
@@ -539,12 +539,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var b = new[] {new Complex(1.0, 0), 2.0, 3.0, 4.0, 5.0, 6.0};
Control.LinearAlgebraProvider.LUSolve(2, a, matrix.RowCount, b);
- AssertHelpers.AlmostEqual(b[0], -1.477272727272726, 14);
- AssertHelpers.AlmostEqual(b[1], -4.318181818181815, 14);
- AssertHelpers.AlmostEqual(b[2], 3.068181818181816, 14);
- AssertHelpers.AlmostEqual(b[3], -4.204545454545451, 14);
- AssertHelpers.AlmostEqual(b[4], -12.499999999999989, 14);
- AssertHelpers.AlmostEqual(b[5], 8.522727272727266, 14);
+ AssertHelpers.AlmostEqualRelative(b[0], -1.477272727272726, 14);
+ AssertHelpers.AlmostEqualRelative(b[1], -4.318181818181815, 14);
+ AssertHelpers.AlmostEqualRelative(b[2], 3.068181818181816, 14);
+ AssertHelpers.AlmostEqualRelative(b[3], -4.204545454545451, 14);
+ AssertHelpers.AlmostEqualRelative(b[4], -12.499999999999989, 14);
+ AssertHelpers.AlmostEqualRelative(b[5], 8.522727272727266, 14);
NotModified(matrix.RowCount, matrix.ColumnCount, a, matrix);
}
@@ -565,12 +565,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var b = new[] {new Complex(1.0, 0), 2.0, 3.0, 4.0, 5.0, 6.0};
Control.LinearAlgebraProvider.LUSolveFactored(2, a, matrix.RowCount, ipiv, b);
- AssertHelpers.AlmostEqual(b[0], -1.477272727272726, 14);
- AssertHelpers.AlmostEqual(b[1], -4.318181818181815, 14);
- AssertHelpers.AlmostEqual(b[2], 3.068181818181816, 14);
- AssertHelpers.AlmostEqual(b[3], -4.204545454545451, 14);
- AssertHelpers.AlmostEqual(b[4], -12.499999999999989, 14);
- AssertHelpers.AlmostEqual(b[5], 8.522727272727266, 14);
+ AssertHelpers.AlmostEqualRelative(b[0], -1.477272727272726, 14);
+ AssertHelpers.AlmostEqualRelative(b[1], -4.318181818181815, 14);
+ AssertHelpers.AlmostEqualRelative(b[2], 3.068181818181816, 14);
+ AssertHelpers.AlmostEqualRelative(b[3], -4.204545454545451, 14);
+ AssertHelpers.AlmostEqualRelative(b[4], -12.499999999999989, 14);
+ AssertHelpers.AlmostEqualRelative(b[5], 8.522727272727266, 14);
}
///
@@ -611,12 +611,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var b = new[] {new Complex(1.0, 0), 2.0, 3.0, 4.0, 5.0, 6.0};
Control.LinearAlgebraProvider.CholeskySolve(a, 3, b, 2);
- AssertHelpers.AlmostEqual(b[0], 0, 14);
- AssertHelpers.AlmostEqual(b[1], 1, 14);
- AssertHelpers.AlmostEqual(b[2], 0, 14);
- AssertHelpers.AlmostEqual(b[3], 3, 14);
- AssertHelpers.AlmostEqual(b[4], 1, 14);
- AssertHelpers.AlmostEqual(b[5], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[0], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[1], 1, 14);
+ AssertHelpers.AlmostEqualRelative(b[2], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[3], 3, 14);
+ AssertHelpers.AlmostEqualRelative(b[4], 1, 14);
+ AssertHelpers.AlmostEqualRelative(b[5], 0, 14);
NotModified(3, 3, a, matrix);
}
@@ -634,12 +634,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var b = new[] {new Complex(1.0, 0), 2.0, 3.0, 4.0, 5.0, 6.0};
Control.LinearAlgebraProvider.CholeskySolveFactored(a, 3, b, 2);
- AssertHelpers.AlmostEqual(b[0], 0, 14);
- AssertHelpers.AlmostEqual(b[1], 1, 14);
- AssertHelpers.AlmostEqual(b[2], 0, 14);
- AssertHelpers.AlmostEqual(b[3], 3, 14);
- AssertHelpers.AlmostEqual(b[4], 1, 14);
- AssertHelpers.AlmostEqual(b[5], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[0], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[1], 1, 14);
+ AssertHelpers.AlmostEqualRelative(b[2], 0, 14);
+ AssertHelpers.AlmostEqualRelative(b[3], 3, 14);
+ AssertHelpers.AlmostEqualRelative(b[4], 1, 14);
+ AssertHelpers.AlmostEqualRelative(b[5], 0, 14);
}
///
@@ -664,7 +664,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -691,7 +691,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -718,7 +718,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -746,7 +746,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -774,7 +774,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -802,7 +802,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -829,7 +829,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -856,7 +856,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -884,7 +884,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -911,7 +911,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
- AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
+ AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 14);
}
}
}
@@ -934,12 +934,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mx = new DenseMatrix(matrix.ColumnCount, 2, x);
var mb = matrix*mx;
- AssertHelpers.AlmostEqual(mb[0, 0], b[0], 14);
- AssertHelpers.AlmostEqual(mb[1, 0], b[1], 14);
- AssertHelpers.AlmostEqual(mb[2, 0], b[2], 14);
- AssertHelpers.AlmostEqual(mb[0, 1], b[3], 14);
- AssertHelpers.AlmostEqual(mb[1, 1], b[4], 14);
- AssertHelpers.AlmostEqual(mb[2, 1], b[5], 14);
+ AssertHelpers.AlmostEqualRelative(mb[0, 0], b[0], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 0], b[1], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 0], b[2], 13);
+ AssertHelpers.AlmostEqualRelative(mb[0, 1], b[3], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 1], b[4], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 1], b[5], 13);
}
///
@@ -961,10 +961,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mb = new DenseMatrix(matrix.RowCount, 2, b);
var test = (matrix.Transpose()*matrix).Inverse()*matrix.Transpose()*mb;
- AssertHelpers.AlmostEqual(test[0, 0], x[0], 14);
- AssertHelpers.AlmostEqual(test[1, 0], x[1], 14);
- AssertHelpers.AlmostEqual(test[0, 1], x[2], 14);
- AssertHelpers.AlmostEqual(test[1, 1], x[3], 14);
+ AssertHelpers.AlmostEqualRelative(test[0, 0], x[0], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 0], x[1], 13);
+ AssertHelpers.AlmostEqualRelative(test[0, 1], x[2], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 1], x[3], 13);
}
///
@@ -988,12 +988,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mx = new DenseMatrix(matrix.ColumnCount, 2, x);
var mb = matrix*mx;
- AssertHelpers.AlmostEqual(mb[0, 0], b[0], 14);
- AssertHelpers.AlmostEqual(mb[1, 0], b[1], 14);
- AssertHelpers.AlmostEqual(mb[2, 0], b[2], 14);
- AssertHelpers.AlmostEqual(mb[0, 1], b[3], 14);
- AssertHelpers.AlmostEqual(mb[1, 1], b[4], 14);
- AssertHelpers.AlmostEqual(mb[2, 1], b[5], 14);
+ AssertHelpers.AlmostEqualRelative(mb[0, 0], b[0], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 0], b[1], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 0], b[2], 13);
+ AssertHelpers.AlmostEqualRelative(mb[0, 1], b[3], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 1], b[4], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 1], b[5], 13);
}
///
@@ -1017,10 +1017,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mb = new DenseMatrix(matrix.RowCount, 2, b);
var test = (matrix.Transpose()*matrix).Inverse()*matrix.Transpose()*mb;
- AssertHelpers.AlmostEqual(test[0, 0], x[0], 14);
- AssertHelpers.AlmostEqual(test[1, 0], x[1], 14);
- AssertHelpers.AlmostEqual(test[0, 1], x[2], 14);
- AssertHelpers.AlmostEqual(test[1, 1], x[3], 14);
+ AssertHelpers.AlmostEqualRelative(test[0, 0], x[0], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 0], x[1], 13);
+ AssertHelpers.AlmostEqualRelative(test[0, 1], x[2], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 1], x[3], 13);
}
///
@@ -1045,12 +1045,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mx = new DenseMatrix(matrix.ColumnCount, 2, x);
var mb = matrix*mx;
- AssertHelpers.AlmostEqual(mb[0, 0], b[0], 14);
- AssertHelpers.AlmostEqual(mb[1, 0], b[1], 14);
- AssertHelpers.AlmostEqual(mb[2, 0], b[2], 14);
- AssertHelpers.AlmostEqual(mb[0, 1], b[3], 14);
- AssertHelpers.AlmostEqual(mb[1, 1], b[4], 14);
- AssertHelpers.AlmostEqual(mb[2, 1], b[5], 14);
+ AssertHelpers.AlmostEqualRelative(mb[0, 0], b[0], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 0], b[1], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 0], b[2], 13);
+ AssertHelpers.AlmostEqualRelative(mb[0, 1], b[3], 13);
+ AssertHelpers.AlmostEqualRelative(mb[1, 1], b[4], 13);
+ AssertHelpers.AlmostEqualRelative(mb[2, 1], b[5], 13);
}
///
@@ -1075,10 +1075,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var mb = new DenseMatrix(matrix.RowCount, 2, b);
var test = (matrix.Transpose()*matrix).Inverse()*matrix.Transpose()*mb;
- AssertHelpers.AlmostEqual(test[0, 0], x[0], 14);
- AssertHelpers.AlmostEqual(test[1, 0], x[1], 14);
- AssertHelpers.AlmostEqual(test[0, 1], x[2], 14);
- AssertHelpers.AlmostEqual(test[1, 1], x[3], 14);
+ AssertHelpers.AlmostEqualRelative(test[0, 0], x[0], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 0], x[1], 13);
+ AssertHelpers.AlmostEqualRelative(test[0, 1], x[2], 13);
+ AssertHelpers.AlmostEqualRelative(test[1, 1], x[3], 13);
}
///