diff --git a/src/Managed.UnitTests/PrecisionTest.cs b/src/Managed.UnitTests/PrecisionTest.cs index c9569cda..3a37c0f9 100644 --- a/src/Managed.UnitTests/PrecisionTest.cs +++ b/src/Managed.UnitTests/PrecisionTest.cs @@ -34,8 +34,8 @@ namespace MathNet.Numerics.UnitTests [TestFixture] public sealed class PrecisionTest { - private const double mAcceptableError = 1e-12; - private readonly double mDoublePrecision = System.Math.Pow(2, -53); + private const double _acceptableError = 1e-12; + private readonly double _doublePrecision = System.Math.Pow(2, -53); [Test] public void Magnitude() @@ -91,40 +91,40 @@ namespace MathNet.Numerics.UnitTests [Test] public void Value() { - Assert.AreApproximatelyEqual(0, Precision.Value(0), mAcceptableError); + Assert.AreApproximatelyEqual(0, Precision.Value(0), _acceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(1), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(10), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(100), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(1000), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(10000), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(100000), mAcceptableError); - Assert.AreApproximatelyEqual(1, Precision.Value(1000000), mAcceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(1), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(10), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(100), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(1000), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(10000), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(100000), _acceptableError); + Assert.AreApproximatelyEqual(1, Precision.Value(1000000), _acceptableError); - Assert.AreApproximatelyEqual(1.1, Precision.Value(1.1e5), mAcceptableError); - Assert.AreApproximatelyEqual(2.2, Precision.Value(2.2e-5), mAcceptableError); - Assert.AreApproximatelyEqual(3.3, Precision.Value(3.3e9), mAcceptableError); - Assert.AreApproximatelyEqual(4.4, Precision.Value(4.4e-11), mAcceptableError); + Assert.AreApproximatelyEqual(1.1, Precision.Value(1.1e5), _acceptableError); + Assert.AreApproximatelyEqual(2.2, Precision.Value(2.2e-5), _acceptableError); + Assert.AreApproximatelyEqual(3.3, Precision.Value(3.3e9), _acceptableError); + Assert.AreApproximatelyEqual(4.4, Precision.Value(4.4e-11), _acceptableError); } // Bug fix test: Magnitude of negative numbers returns zero [Test] public void ValueWithNegativeValues() { - Assert.AreApproximatelyEqual(0, Precision.Value(0), mAcceptableError); + Assert.AreApproximatelyEqual(0, Precision.Value(0), _acceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-1), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-10), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-100), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-1000), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-10000), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-100000), mAcceptableError); - Assert.AreApproximatelyEqual(-1, Precision.Value(-1000000), mAcceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-1), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-10), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-100), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-1000), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-10000), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-100000), _acceptableError); + Assert.AreApproximatelyEqual(-1, Precision.Value(-1000000), _acceptableError); - Assert.AreApproximatelyEqual(-1.1, Precision.Value(-1.1e5), mAcceptableError); - Assert.AreApproximatelyEqual(-2.2, Precision.Value(-2.2e-5), mAcceptableError); - Assert.AreApproximatelyEqual(-3.3, Precision.Value(-3.3e9), mAcceptableError); - Assert.AreApproximatelyEqual(-4.4, Precision.Value(-4.4e-11), mAcceptableError); + Assert.AreApproximatelyEqual(-1.1, Precision.Value(-1.1e5), _acceptableError); + Assert.AreApproximatelyEqual(-2.2, Precision.Value(-2.2e-5), _acceptableError); + Assert.AreApproximatelyEqual(-3.3, Precision.Value(-3.3e9), _acceptableError); + Assert.AreApproximatelyEqual(-4.4, Precision.Value(-4.4e-11), _acceptableError); } [Test] @@ -481,31 +481,31 @@ namespace MathNet.Numerics.UnitTests Assert.IsTrue(Precision.AlmostEqual(0, -0, 1)); // compare two nearby numbers - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 3 * mDoublePrecision, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 + mDoublePrecision, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - mDoublePrecision, 1)); - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 3 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 3 * _doublePrecision, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 + _doublePrecision, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - _doublePrecision, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 3 * _doublePrecision, 1)); // compare with the two numbers reversed in compare order - Assert.IsFalse(Precision.AlmostEqual(1.0 + 3 * mDoublePrecision, 1.0, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0 + mDoublePrecision, 1.0, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0 - mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.AlmostEqual(1.0 - 3 * mDoublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0 + 3 * _doublePrecision, 1.0, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0 + _doublePrecision, 1.0, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0 - _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0 - 3 * _doublePrecision, 1.0, 1)); // compare two slightly more different numbers - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 10 * mDoublePrecision, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 + 10 * mDoublePrecision, 10)); - Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - 10 * mDoublePrecision, 10)); - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 10 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 10 * _doublePrecision, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 + 10 * _doublePrecision, 10)); + Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - 10 * _doublePrecision, 10)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 10 * _doublePrecision, 1)); // compare different numbers Assert.IsFalse(Precision.AlmostEqual(2.0, 1.0, 1)); Assert.IsFalse(Precision.AlmostEqual(1.0, 2.0, 1)); // compare different numbers with large tolerance - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 1e5 * mDoublePrecision, 1)); - Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - 1e5 * mDoublePrecision, 200000)); - Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 1e5 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 + 1e5 * _doublePrecision, 1)); + Assert.IsTrue(Precision.AlmostEqual(1.0, 1.0 - 1e5 * _doublePrecision, 200000)); + Assert.IsFalse(Precision.AlmostEqual(1.0, 1.0 - 1e5 * _doublePrecision, 1)); // compare inf & inf Assert.IsTrue(Precision.AlmostEqual(double.PositiveInfinity, double.PositiveInfinity, 1)); @@ -568,8 +568,8 @@ namespace MathNet.Numerics.UnitTests Assert.IsFalse(Precision.AlmostEqualInDecimalPlaces(100.0, 106.00, 2)); Assert.IsFalse(Precision.AlmostEqualInDecimalPlaces(100.0, 94.000, 2)); - Assert.IsTrue(Precision.AlmostEqualInDecimalPlaces(0.0, 4 * mDoublePrecision, 12)); - Assert.IsTrue(Precision.AlmostEqualInDecimalPlaces(0.0, -4 * mDoublePrecision, 12)); + Assert.IsTrue(Precision.AlmostEqualInDecimalPlaces(0.0, 4 * _doublePrecision, 12)); + Assert.IsTrue(Precision.AlmostEqualInDecimalPlaces(0.0, -4 * _doublePrecision, 12)); } [Test] @@ -598,31 +598,31 @@ namespace MathNet.Numerics.UnitTests Assert.IsFalse(Precision.IsLarger(0, -0, 1)); // compare two nearby numbers - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 3 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - mDoublePrecision, 1)); - Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 3 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 3 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + _doublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - _doublePrecision, 1)); + Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 3 * _doublePrecision, 1)); // compare with the two numbers reversed in compare order - Assert.IsTrue(Precision.IsLarger(1.0 + 3 * mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.IsLarger(1.0 + mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.IsLarger(1.0 - mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.IsLarger(1.0 - 3 * mDoublePrecision, 1.0, 1)); + Assert.IsTrue(Precision.IsLarger(1.0 + 3 * _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsLarger(1.0 + _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsLarger(1.0 - _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsLarger(1.0 - 3 * _doublePrecision, 1.0, 1)); // compare two slightly more different numbers - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 10 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 10 * mDoublePrecision, 10)); - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - 10 * mDoublePrecision, 10)); - Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 10 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 10 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 10 * _doublePrecision, 10)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - 10 * _doublePrecision, 10)); + Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 10 * _doublePrecision, 1)); // compare different numbers Assert.IsTrue(Precision.IsLarger(2.0, 1.0, 1)); Assert.IsFalse(Precision.IsLarger(1.0, 2.0, 1)); // compare different numbers with large tolerance - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 1e5 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - 1e5 * mDoublePrecision, 200000)); - Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 1e5 * mDoublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 + 1e5 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsLarger(1.0, 1.0 - 1e5 * _doublePrecision, 200000)); + Assert.IsTrue(Precision.IsLarger(1.0, 1.0 - 1e5 * _doublePrecision, 1)); // compare inf & inf Assert.IsFalse(Precision.IsLarger(double.PositiveInfinity, double.PositiveInfinity, 1)); @@ -675,13 +675,13 @@ namespace MathNet.Numerics.UnitTests Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(100.0, 106.00, 2)); Assert.IsTrue(Precision.IsLargerWithDecimalPlaces(100.0, 94.000, 2)); - double max = 4 * System.Math.Pow(10, Precision.Magnitude(mDoublePrecision)); - Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, max, -Precision.Magnitude(mDoublePrecision))); - Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(mDoublePrecision))); + double max = 4 * System.Math.Pow(10, Precision.Magnitude(_doublePrecision)); + Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, max, -Precision.Magnitude(_doublePrecision))); + Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(_doublePrecision))); - max = 6 * System.Math.Pow(10, Precision.Magnitude(mDoublePrecision)); - Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, max, -Precision.Magnitude(mDoublePrecision))); - Assert.IsTrue(Precision.IsLargerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(mDoublePrecision))); + max = 6 * System.Math.Pow(10, Precision.Magnitude(_doublePrecision)); + Assert.IsFalse(Precision.IsLargerWithDecimalPlaces(0.0, max, -Precision.Magnitude(_doublePrecision))); + Assert.IsTrue(Precision.IsLargerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(_doublePrecision))); } [Test] @@ -691,31 +691,31 @@ namespace MathNet.Numerics.UnitTests Assert.IsFalse(Precision.IsSmaller(0, -0, 1)); // compare two nearby numbers - Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 3 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 + mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 3 * mDoublePrecision, 1)); + Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 3 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 + _doublePrecision, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - _doublePrecision, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 3 * _doublePrecision, 1)); // compare with the two numbers reversed in compare order - Assert.IsFalse(Precision.IsSmaller(1.0 + 3 * mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0 + mDoublePrecision, 1.0, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0 - mDoublePrecision, 1.0, 1)); - Assert.IsTrue(Precision.IsSmaller(1.0 - 3 * mDoublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0 + 3 * _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0 + _doublePrecision, 1.0, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0 - _doublePrecision, 1.0, 1)); + Assert.IsTrue(Precision.IsSmaller(1.0 - 3 * _doublePrecision, 1.0, 1)); // compare two slightly more different numbers - Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 10 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 + 10 * mDoublePrecision, 10)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 10 * mDoublePrecision, 10)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 10 * mDoublePrecision, 1)); + Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 10 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 + 10 * _doublePrecision, 10)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 10 * _doublePrecision, 10)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 10 * _doublePrecision, 1)); // compare different numbers Assert.IsFalse(Precision.IsSmaller(2.0, 1.0, 1)); Assert.IsTrue(Precision.IsSmaller(1.0, 2.0, 1)); // compare different numbers with large tolerance - Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 1e5 * mDoublePrecision, 1)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 1e5 * mDoublePrecision, 200000)); - Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 1e5 * mDoublePrecision, 1)); + Assert.IsTrue(Precision.IsSmaller(1.0, 1.0 + 1e5 * _doublePrecision, 1)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 1e5 * _doublePrecision, 200000)); + Assert.IsFalse(Precision.IsSmaller(1.0, 1.0 - 1e5 * _doublePrecision, 1)); // compare inf & inf Assert.IsFalse(Precision.IsSmaller(double.PositiveInfinity, double.PositiveInfinity, 1)); @@ -768,13 +768,13 @@ namespace MathNet.Numerics.UnitTests Assert.IsTrue(Precision.IsSmallerWithDecimalPlaces(100.0, 106.00, 2)); Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(100.0, 94.000, 2)); - double max = 4 * System.Math.Pow(10, Precision.Magnitude(mDoublePrecision)); - Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, max, -Precision.Magnitude(mDoublePrecision))); - Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(mDoublePrecision))); + double max = 4 * System.Math.Pow(10, Precision.Magnitude(_doublePrecision)); + Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, max, -Precision.Magnitude(_doublePrecision))); + Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(_doublePrecision))); - max = 6 * System.Math.Pow(10, Precision.Magnitude(mDoublePrecision)); - Assert.IsTrue(Precision.IsSmallerWithDecimalPlaces(0.0, max, -Precision.Magnitude(mDoublePrecision))); - Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(mDoublePrecision))); + max = 6 * System.Math.Pow(10, Precision.Magnitude(_doublePrecision)); + Assert.IsTrue(Precision.IsSmallerWithDecimalPlaces(0.0, max, -Precision.Magnitude(_doublePrecision))); + Assert.IsFalse(Precision.IsSmallerWithDecimalPlaces(0.0, -max, -Precision.Magnitude(_doublePrecision))); } [Test] @@ -836,31 +836,31 @@ namespace MathNet.Numerics.UnitTests Assert.AreEqual(0, Precision.CompareTo(0, -0, 1)); // compare two nearby numbers - Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 3 * mDoublePrecision, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 + mDoublePrecision, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - mDoublePrecision, 1)); - Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 3 * mDoublePrecision, 1)); + Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 3 * _doublePrecision, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 + _doublePrecision, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - _doublePrecision, 1)); + Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 3 * _doublePrecision, 1)); // compare with the two numbers reversed in compare order - Assert.AreEqual(1, Precision.CompareTo(1.0 + 3 * mDoublePrecision, 1.0, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0 + mDoublePrecision, 1.0, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0 - mDoublePrecision, 1.0, 1)); - Assert.AreEqual(-1, Precision.CompareTo(1.0 - 3 * mDoublePrecision, 1.0, 1)); + Assert.AreEqual(1, Precision.CompareTo(1.0 + 3 * _doublePrecision, 1.0, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0 + _doublePrecision, 1.0, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0 - _doublePrecision, 1.0, 1)); + Assert.AreEqual(-1, Precision.CompareTo(1.0 - 3 * _doublePrecision, 1.0, 1)); // compare two slightly more different numbers - Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 10 * mDoublePrecision, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 + 10 * mDoublePrecision, 10)); - Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - 10 * mDoublePrecision, 10)); - Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 10 * mDoublePrecision, 1)); + Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 10 * _doublePrecision, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 + 10 * _doublePrecision, 10)); + Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - 10 * _doublePrecision, 10)); + Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 10 * _doublePrecision, 1)); // compare different numbers Assert.AreEqual(1, Precision.CompareTo(2.0, 1.0, 1)); Assert.AreEqual(-1, Precision.CompareTo(1.0, 2.0, 1)); // compare different numbers with large tolerance - Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 1e5 * mDoublePrecision, 1)); - Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - 1e5 * mDoublePrecision, 200000)); - Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 1e5 * mDoublePrecision, 1)); + Assert.AreEqual(-1, Precision.CompareTo(1.0, 1.0 + 1e5 * _doublePrecision, 1)); + Assert.AreEqual(0, Precision.CompareTo(1.0, 1.0 - 1e5 * _doublePrecision, 200000)); + Assert.AreEqual(1, Precision.CompareTo(1.0, 1.0 - 1e5 * _doublePrecision, 1)); // compare inf & inf Assert.AreEqual(0, Precision.CompareTo(double.PositiveInfinity, double.PositiveInfinity, 1)); @@ -891,31 +891,31 @@ namespace MathNet.Numerics.UnitTests Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(0, -0, Precision.NumberOfDecimalPlacesForFloats)); // compare two nearby numbers - Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 10 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 + mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 10 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 10 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 + _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 10 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); // compare with the two numbers reversed in compare order - Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0 + 10 * mDoublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0 + mDoublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0 - mDoublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0 - 10 * mDoublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0 + 10 * _doublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0 + _doublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0 - _doublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0 - 10 * _doublePrecision, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); // compare two slightly more different numbers - Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 50 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 50 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles - 2)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 50 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles - 2)); - Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 50 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 50 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 50 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles - 2)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 50 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles - 2)); + Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 50 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); // compare different numbers Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(2.0, 1.0, Precision.NumberOfDecimalPlacesForDoubles)); Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 2.0, Precision.NumberOfDecimalPlacesForDoubles)); // compare different numbers with large tolerance - Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 1e5 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); - Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 1e5 * mDoublePrecision, 10)); - Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 1e5 * mDoublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(-1, Precision.CompareToInDecimalPlaces(1.0, 1.0 + 1e5 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); + Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 1e5 * _doublePrecision, 10)); + Assert.AreEqual(1, Precision.CompareToInDecimalPlaces(1.0, 1.0 - 1e5 * _doublePrecision, Precision.NumberOfDecimalPlacesForDoubles)); // compare inf & inf Assert.AreEqual(0, Precision.CompareToInDecimalPlaces(double.PositiveInfinity, double.PositiveInfinity, Precision.NumberOfDecimalPlacesForDoubles)); diff --git a/src/Managed/Managed.csproj b/src/Managed/Managed.csproj index cc1613c0..68fdb34f 100644 --- a/src/Managed/Managed.csproj +++ b/src/Managed/Managed.csproj @@ -10,7 +10,7 @@ Properties MathNet.Numerics MathNet.Numerics - v2.0 + v3.5 512 true ..\MathNet.Numerics.snk @@ -37,6 +37,9 @@ + + 3.5 + diff --git a/src/Managed/Precision.cs b/src/Managed/Precision.cs index 7139b15b..f5bf016b 100644 --- a/src/Managed/Precision.cs +++ b/src/Managed/Precision.cs @@ -96,7 +96,7 @@ namespace MathNet.Numerics #endregion /// - /// Initializes the class. + /// Initializes static members of the Precision class. /// static Precision() { @@ -133,7 +133,7 @@ namespace MathNet.Numerics /// /// The value. /// The magnitute of the number. - public static int Magnitude(double value) + public static int Magnitude(this double value) { // Can't do this with zero because the 10-log of zero doesn't exist. if (value.Equals(0.0)) @@ -150,9 +150,10 @@ namespace MathNet.Numerics // truncating a negative number will give us a magnitude that is off by 1 if (magnitude < 0) { - return ((int)(System.Math.Truncate(magnitude - 1))); + return (int)System.Math.Truncate(magnitude - 1); } - return ((int)(System.Math.Truncate(magnitude))); + + return (int)System.Math.Truncate(magnitude); } /// @@ -160,7 +161,7 @@ namespace MathNet.Numerics /// /// The value. /// The value of the number. - public static double Value(double value) + public static double Value(this double value) { if (value.Equals(0.0)) { @@ -168,9 +169,16 @@ namespace MathNet.Numerics } int magnitude = Magnitude(value); - return value * (System.Math.Pow(10, -magnitude)); + return value * System.Math.Pow(10, -magnitude); } + /// + /// Gets the equivalent long value for the given double value. + /// + /// The double value which should be turned into a long value. + /// + /// The resulting long value. + /// private static long GetLongFromDouble(double value) { return BitConverter.DoubleToInt64Bits(value); @@ -187,6 +195,7 @@ namespace MathNet.Numerics { // Convert in the normal way. long result = GetLongFromDouble(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. @@ -196,11 +205,13 @@ namespace MathNet.Numerics /// /// Increments a floating point number to the next bigger number representable by the data type. /// + /// The value which needs to be incremented. /// /// The incrementation step length depends on the provided value. /// Increment(double.MaxValue) will return positive infinity. /// - public static double Increment(double value) + /// The next larger floating point value. + public static double Increment(this double value) { if (double.IsInfinity(value) || double.IsNaN(value)) { @@ -237,11 +248,13 @@ namespace MathNet.Numerics /// /// Decrements a floating point number to the next smaller number representable by the data type. /// + /// The value which should be decremented. /// /// The decrementation step length depends on the provided value. /// Decrement(double.MinValue) will return negative infinity. /// - public static double Decrement(double value) + /// The next smaller floating point value. + public static double Decrement(this double value) { if (double.IsInfinity(value) || double.IsNaN(value)) { @@ -255,6 +268,7 @@ namespace MathNet.Numerics // gets closer to zero! // i.e. 0 - double.epsilon will give the largest long value! long intValue = GetLongFromDouble(value); + // If the value is zero then we'd really like the value to be -0. So we'll make it -0 // and then everything else should work out. if (intValue == 0) @@ -285,7 +299,7 @@ namespace MathNet.Numerics /// /// Zero if || is fewer than numbers from zero, otherwise. /// - public static double CoerceZero(double a, int maxNumbersBetween) + public static double CoerceZero(this double a, int maxNumbersBetween) { return CoerceZero(a, (long)maxNumbersBetween); } @@ -301,7 +315,7 @@ namespace MathNet.Numerics /// /// Thrown if is smaller than zero. /// - public static double CoerceZero(double a, long maxNumbersBetween) + public static double CoerceZero(this double a, long maxNumbersBetween) { if (maxNumbersBetween < 0) { @@ -332,7 +346,7 @@ namespace MathNet.Numerics /// /// Thrown if is smaller than zero. /// - public static double CoerceZero(double a, double maximumAbsoluteError) + public static double CoerceZero(this double a, double maximumAbsoluteError) { if (maximumAbsoluteError < 0) { @@ -357,7 +371,7 @@ namespace MathNet.Numerics /// /// The real number to coerce to zero, if it is almost zero. /// Zero if || is smaller than 10*2^(-52) = 0.22e-14, otherwise. - public static double CoerceZero(double a) + public static double CoerceZero(this double a) { return CoerceZero(a, _doubleMachinePrecision); } @@ -367,22 +381,22 @@ namespace MathNet.Numerics /// /// The value. /// The ulps difference. - /// The top range end. /// The bottom range end. + /// The top range end. /// /// Thrown if is smaller than zero. /// - public static void RangeOfMatchingFloatingPointNumbers(double value, long maxNumbersBetween, out double bottomRangeEnd, out double topRangeEnd) + public static void RangeOfMatchingFloatingPointNumbers(this double value, long maxNumbersBetween, out double bottomRangeEnd, out double topRangeEnd) { // Make sure ulpDifference is non-negative if (maxNumbersBetween < 1) { - throw new ArgumentOutOfRangeException("ulpsDifference"); + throw new ArgumentOutOfRangeException("maxNumbersBetween"); } // If the value is infinity (positive or negative) just // return the same infinity for the range. - if ((double.IsInfinity(value))) + if (double.IsInfinity(value)) { topRangeEnd = value; bottomRangeEnd = value; @@ -475,8 +489,8 @@ namespace MathNet.Numerics /// /// The value. /// The ulps difference. - /// - public static double MaximumMatchingFloatingPointNumber(double value, long maxNumbersBetween) + /// 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); @@ -489,8 +503,8 @@ namespace MathNet.Numerics /// /// The value. /// The ulps difference. - /// - public static double MinimumMatchingFloatingPointNumber(double value, long maxNumbersBetween) + /// 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); @@ -502,8 +516,8 @@ 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. + /// The number of ULPS between the value and the value + relativeDifference. /// /// Thrown if is smaller than zero. /// @@ -513,7 +527,7 @@ namespace MathNet.Numerics /// /// Thrown if is double.NaN. /// - public static void RangeOfMatchingNumbers(double value, double relativeDifference, out long bottomRangeEnd, out long topRangeEnd) + public static void RangeOfMatchingNumbers(this double value, double relativeDifference, out long bottomRangeEnd, out long topRangeEnd) { // Make sure the relative is non-negative if (relativeDifference < 0) @@ -523,7 +537,7 @@ namespace MathNet.Numerics // If the value is infinity (positive or negative) then // we can't determine the range. - if ((double.IsInfinity(value))) + if (double.IsInfinity(value)) { throw new ArgumentOutOfRangeException("value"); } @@ -545,8 +559,8 @@ namespace MathNet.Numerics // Calculate the ulps for the maximum and minimum values // Note that these can overflow - long max = GetDirectionalLongFromDouble(value + relativeDifference * System.Math.Abs(value)); - long min = GetDirectionalLongFromDouble(value - relativeDifference * System.Math.Abs(value)); + long max = GetDirectionalLongFromDouble(value + (relativeDifference * System.Math.Abs(value))); + long min = GetDirectionalLongFromDouble(value - (relativeDifference * System.Math.Abs(value))); // Calculate the ulps from the value long intValue = GetDirectionalLongFromDouble(value); @@ -556,13 +570,13 @@ namespace MathNet.Numerics bottomRangeEnd = System.Math.Abs(intValue - min); } - /// /// Evaluates the count of numbers between two double numbers /// - /// - /// + /// The first parameter. + /// The second parameter. /// The second number is included in the number, thus two equal numbers evaluate to zero and two neighbor numbers evaluate to one. Therefore, what is returned is actually the count of numbers between plus 1. + /// The number of floating point values between and . /// /// Thrown if is double.PositiveInfinity or double.NegativeInfinity. /// @@ -575,7 +589,7 @@ namespace MathNet.Numerics /// /// Thrown if is double.NaN. /// - public static ulong NumbersBetween(double a, double b) + public static ulong NumbersBetween(this double a, double b) { if (double.IsNaN(a) || double.IsInfinity(a)) { @@ -605,7 +619,7 @@ namespace MathNet.Numerics /// /// True if || is less than steps from zero, False otherwise. /// - public static bool AlmostZero(double a, long maxNumbersBetween) + public static bool AlmostZero(this double a, long maxNumbersBetween) { if (maxNumbersBetween < 0) { @@ -629,7 +643,7 @@ namespace MathNet.Numerics /// /// True if || is smaller than , False otherwise. /// - public static bool AlmostZero(double a, double maximumAbsoluteError) + public static bool AlmostZero(this double a, double maximumAbsoluteError) { if (maximumAbsoluteError < 0) { @@ -651,7 +665,7 @@ namespace MathNet.Numerics /// /// True if || is smaller than 10*2^(-52) = 0.22e-14, False otherwise. /// - public static bool AlmostZero(double a) + public static bool AlmostZero(this double a) { return AlmostZero(a, _doubleMachinePrecision); } @@ -679,21 +693,21 @@ namespace MathNet.Numerics /// /// Thrown if is smaller than one. /// - public static bool AlmostEqual(double a, double b, long maxNumbersBetween) + public static bool AlmostEqual(this double a, double b, long maxNumbersBetween) { - // Make sure maxUlps is non-negative and small enough that the + // 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("maxUlps"); + 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))) + if (double.IsInfinity(a) || double.IsInfinity(b)) { - return (a == b); + return a == b; } // If A or B are a NAN, return false. NANs are equal to nothing, @@ -733,17 +747,17 @@ namespace MathNet.Numerics /// /// Thrown if is smaller than zero. /// - public static bool AlmostEqualInDecimalPlaces(double a, double b, int decimalPlaces) + 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("numberOfSignificantFigures"); + 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))) + if (double.IsNaN(a) || double.IsNaN(b)) { return false; } @@ -751,9 +765,9 @@ namespace MathNet.Numerics // 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))) + if (double.IsInfinity(a) || double.IsInfinity(b)) { - return (a == b); + return a == b; } // If both numbers are equal, get out now. This should remove the possibility of both numbers being zero @@ -763,10 +777,11 @@ namespace MathNet.Numerics return true; } - if ((AlmostZero(a)) || (AlmostZero(b))) + if (AlmostZero(a) || AlmostZero(b)) { return AlmostEqualWithAbsoluteDecimalPlaces(a, b, decimalPlaces); } + return AlmostEqualWithRelativeDecimalPlaces(a, b, decimalPlaces); } @@ -784,7 +799,7 @@ namespace MathNet.Numerics /// The second value. /// The number of decimal places. /// if both doubles are equal to each other within the specified number of decimal places; otherwise . - private static bool AlmostEqualWithRelativeDecimalPlaces(double a, double b, int decimalPlaces) + private static bool AlmostEqualWithRelativeDecimalPlaces(this double a, double b, int decimalPlaces) { // If the magnitudes of the two numbers are equal to within one magnitude the numbers could potentially be equal int magnitudeOfFirst = Magnitude(a); @@ -804,11 +819,11 @@ namespace MathNet.Numerics double maxDifference = decimalPlaceMagnitude / 2.0; if (a > b) { - return (a * System.Math.Pow(10, -magnitudeOfFirst) - maxDifference < b * System.Math.Pow(10, -magnitudeOfFirst)); + return (a * System.Math.Pow(10, -magnitudeOfFirst)) - maxDifference < (b * System.Math.Pow(10, -magnitudeOfFirst)); } else { - return (b * System.Math.Pow(10, -magnitudeOfSecond) - maxDifference < a * System.Math.Pow(10, -magnitudeOfSecond)); + return (b * System.Math.Pow(10, -magnitudeOfSecond)) - maxDifference < (a * System.Math.Pow(10, -magnitudeOfSecond)); } } @@ -827,14 +842,15 @@ namespace MathNet.Numerics /// The second value. /// The number of decimal places. /// if both doubles are equal to each other within the specified number of decimal places; otherwise . - private static bool AlmostEqualWithAbsoluteDecimalPlaces(double a, double b, int decimalPlaces) + private static bool AlmostEqualWithAbsoluteDecimalPlaces(this double a, double b, int decimalPlaces) { double decimalPlaceMagnitude = System.Math.Pow(10, -(decimalPlaces - 1)); + // 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 - return (System.Math.Abs((a - b)) < decimalPlaceMagnitude / 2.0); + return System.Math.Abs((a - b)) < decimalPlaceMagnitude / 2.0; } /// @@ -845,17 +861,17 @@ namespace MathNet.Numerics /// 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(double a, double b, long maxNumbersBetween) + public static bool IsLarger(this double a, double b, long maxNumbersBetween) { // 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 (double.IsNaN(a) || double.IsNaN(b)) { return false; } - return (CompareTo(a, b, maxNumbersBetween) > 0); + return CompareTo(a, b, maxNumbersBetween) > 0; } /// @@ -873,17 +889,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(double a, double b, int decimalPlaces) + public static bool IsLargerWithDecimalPlaces(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 // smaller than anything either - if ((double.IsNaN(a)) || (double.IsNaN(b))) + if (double.IsNaN(a) || double.IsNaN(b)) { return false; } - return (CompareToInDecimalPlaces(a, b, decimalPlaces) > 0); + return CompareToInDecimalPlaces(a, b, decimalPlaces) > 0; } /// @@ -894,17 +910,17 @@ namespace MathNet.Numerics /// 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 smaller than the second value; otherwise false. - public static bool IsSmaller(double a, double b, long maxNumbersBetween) + public static bool IsSmaller(this double a, double b, long maxNumbersBetween) { // 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 (double.IsNaN(a) || double.IsNaN(b)) { return false; } - return (CompareTo(a, b, maxNumbersBetween) < 0); + return CompareTo(a, b, maxNumbersBetween) < 0; } /// @@ -922,17 +938,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(double a, double b, int decimalPlaces) + public static bool IsSmallerWithDecimalPlaces(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 // smaller than anything either - if ((double.IsNaN(a)) || (double.IsNaN(b))) + if (double.IsNaN(a) || double.IsNaN(b)) { return false; } - return (CompareToInDecimalPlaces(a, b, decimalPlaces) < 0); + return CompareToInDecimalPlaces(a, b, decimalPlaces) < 0; } /// @@ -949,31 +965,31 @@ namespace MathNet.Numerics /// /// /// -1 - /// is smaller than by more than the tolerance. + /// is smaller than by more than the tolerance. /// /// /// 0 - /// is equal to within the tolerance. + /// is equal to within the tolerance. /// /// /// 1 - /// is bigger than by more than the tolerance. + /// is bigger than by more than the tolerance. /// /// /// - public static int CompareTo(double a, double b, long maxNumbersBetween) + public static int CompareTo(this double a, double b, long maxNumbersBetween) { // 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 (double.IsNaN(a) || double.IsNaN(b)) { return a.CompareTo(b); } // If A or B are infinity (positive or negative) then // only return true if first is smaller - if ((double.IsInfinity(a)) || (double.IsInfinity(b))) + if (double.IsInfinity(a) || double.IsInfinity(b)) { return a.CompareTo(b); } @@ -1002,31 +1018,31 @@ namespace MathNet.Numerics /// /// /// -1 - /// is smaller than by more than a magnitude equal to . + /// is smaller than by more than a magnitude equal to . /// /// /// 0 - /// is equal to within a magnitude equal to . + /// is equal to within a magnitude equal to . /// /// /// 1 - /// is bigger than by more than a magnitude equal to . + /// is bigger than by more than a magnitude equal to . /// /// /// - public static int CompareToInDecimalPlaces(double a, double b, int decimalPlaces) + public static int CompareToInDecimalPlaces(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 // smaller than anything either - if ((double.IsNaN(a)) || (double.IsNaN(b))) + if (double.IsNaN(a) || double.IsNaN(b)) { return a.CompareTo(b); } // If A or B are infinity (positive or negative) then // only return true if first is smaller - if ((double.IsInfinity(a)) || (double.IsInfinity(b))) + if (double.IsInfinity(a) || double.IsInfinity(b)) { return a.CompareTo(b); } diff --git a/src/Native/Native.csproj b/src/Native/Native.csproj index 1a5b3fd3..0f687d89 100644 --- a/src/Native/Native.csproj +++ b/src/Native/Native.csproj @@ -10,7 +10,7 @@ Properties MathNet.Numerics MathNet.Numerics.Native - v2.0 + v3.5 512 true ..\MathNet.Numerics.snk @@ -34,6 +34,9 @@ + + 3.5 +