@ -34,8 +34,8 @@ namespace MathNet.Numerics.UnitTests
[TestFixture]
public sealed class PrecisionTest
{
private const double mA cceptableError = 1e-12 ;
private readonly double mD oublePrecision = System . Math . Pow ( 2 , - 5 3 ) ;
private const double _ a cceptableError = 1e-12 ;
private readonly double _d oublePrecision = System . Math . Pow ( 2 , - 5 3 ) ;
[Test]
public void Magnitude ( )
@ -91,40 +91,40 @@ namespace MathNet.Numerics.UnitTests
[Test]
public void Value ( )
{
Assert . AreApproximatelyEqual < double , double > ( 0 , Precision . Value ( 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 0 , Precision . Value ( 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1 , Precision . Value ( 1 0 0 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1.1 , Precision . Value ( 1.1e5 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 2.2 , Precision . Value ( 2.2e-5 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 3.3 , Precision . Value ( 3.3e9 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 4.4 , Precision . Value ( 4.4e-11 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 1.1 , Precision . Value ( 1.1e5 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 2.2 , Precision . Value ( 2.2e-5 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 3.3 , Precision . Value ( 3.3e9 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 4.4 , Precision . Value ( 4.4e-11 ) , _ a cceptableError) ;
}
// Bug fix test: Magnitude of negative numbers returns zero
[Test]
public void ValueWithNegativeValues ( )
{
Assert . AreApproximatelyEqual < double , double > ( 0 , Precision . Value ( 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( 0 , Precision . Value ( 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 0 0 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1 , Precision . Value ( - 1 0 0 0 0 0 0 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1.1 , Precision . Value ( - 1.1e5 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 2.2 , Precision . Value ( - 2.2e-5 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 3.3 , Precision . Value ( - 3.3e9 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 4.4 , Precision . Value ( - 4.4e-11 ) , mA cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 1.1 , Precision . Value ( - 1.1e5 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 2.2 , Precision . Value ( - 2.2e-5 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 3.3 , Precision . Value ( - 3.3e9 ) , _ a cceptableError) ;
Assert . AreApproximatelyEqual < double , double > ( - 4.4 , Precision . Value ( - 4.4e-11 ) , _ a cceptableError) ;
}
[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 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 + mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 3 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 + 3 * _d oublePrecision , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 + _d oublePrecision , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 3 * _d oublePrecision , 1 ) ) ;
// compare with the two numbers reversed in compare order
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 + 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 + mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 - mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 - 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 + 3 * _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 + _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 - _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 - 3 * _d oublePrecision , 1.0 , 1 ) ) ;
// compare two slightly more different numbers
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 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 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 2 0 0 0 0 0 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 + 1e5 * _d oublePrecision , 1 ) ) ;
Assert . IsTrue ( Precision . AlmostEqual ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 2 0 0 0 0 0 ) ) ;
Assert . IsFalse ( Precision . AlmostEqual ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 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 ( 1 0 0.0 , 1 0 6.00 , 2 ) ) ;
Assert . IsFalse ( Precision . AlmostEqualInDecimalPlaces ( 1 0 0.0 , 9 4.000 , 2 ) ) ;
Assert . IsTrue ( Precision . AlmostEqualInDecimalPlaces ( 0.0 , 4 * mD oublePrecision, 1 2 ) ) ;
Assert . IsTrue ( Precision . AlmostEqualInDecimalPlaces ( 0.0 , - 4 * mD oublePrecision, 1 2 ) ) ;
Assert . IsTrue ( Precision . AlmostEqualInDecimalPlaces ( 0.0 , 4 * _d oublePrecision , 1 2 ) ) ;
Assert . IsTrue ( Precision . AlmostEqualInDecimalPlaces ( 0.0 , - 4 * _d oublePrecision , 1 2 ) ) ;
}
[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 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 3 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 3 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - _d oublePrecision , 1 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 3 * _d oublePrecision , 1 ) ) ;
// compare with the two numbers reversed in compare order
Assert . IsTrue ( Precision . IsLarger ( 1.0 + 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 + mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 - mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 - 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 + 3 * _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 + _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 - _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 - 3 * _d oublePrecision , 1.0 , 1 ) ) ;
// compare two slightly more different numbers
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 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 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 2 0 0 0 0 0 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 + 1e5 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsLarger ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 2 0 0 0 0 0 ) ) ;
Assert . IsTrue ( Precision . IsLarger ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 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 ( 1 0 0.0 , 1 0 6.00 , 2 ) ) ;
Assert . IsTrue ( Precision . IsLargerWithDecimalPlaces ( 1 0 0.0 , 9 4.000 , 2 ) ) ;
double max = 4 * System . Math . Pow ( 1 0 , Precision . Magnitude ( mD oublePrecision) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
double max = 4 * System . Math . Pow ( 1 0 , Precision . Magnitude ( _d oublePrecision ) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
max = 6 * System . Math . Pow ( 1 0 , Precision . Magnitude ( mD oublePrecision) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
Assert . IsTrue ( Precision . IsLargerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
max = 6 * System . Math . Pow ( 1 0 , Precision . Magnitude ( _d oublePrecision ) ) ;
Assert . IsFalse ( Precision . IsLargerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
Assert . IsTrue ( Precision . IsLargerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
}
[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 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 + mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 3 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . IsSmaller ( 1.0 , 1.0 + 3 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 + _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 3 * _d oublePrecision , 1 ) ) ;
// compare with the two numbers reversed in compare order
Assert . IsFalse ( Precision . IsSmaller ( 1.0 + 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 + mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 - mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . IsSmaller ( 1.0 - 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 + 3 * _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 + _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 - _d oublePrecision , 1.0 , 1 ) ) ;
Assert . IsTrue ( Precision . IsSmaller ( 1.0 - 3 * _d oublePrecision , 1.0 , 1 ) ) ;
// compare two slightly more different numbers
Assert . IsTrue ( Precision . IsSmaller ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . IsSmaller ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 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 * mD oublePrecision, 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 2 0 0 0 0 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 1 ) ) ;
Assert . IsTrue ( Precision . IsSmaller ( 1.0 , 1.0 + 1e5 * _d oublePrecision , 1 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 2 0 0 0 0 0 ) ) ;
Assert . IsFalse ( Precision . IsSmaller ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 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 ( 1 0 0.0 , 1 0 6.00 , 2 ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 1 0 0.0 , 9 4.000 , 2 ) ) ;
double max = 4 * System . Math . Pow ( 1 0 , Precision . Magnitude ( mD oublePrecision) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
double max = 4 * System . Math . Pow ( 1 0 , Precision . Magnitude ( _d oublePrecision ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
max = 6 * System . Math . Pow ( 1 0 , Precision . Magnitude ( mD oublePrecision) ) ;
Assert . IsTrue ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( mD oublePrecision) ) ) ;
max = 6 * System . Math . Pow ( 1 0 , Precision . Magnitude ( _d oublePrecision ) ) ;
Assert . IsTrue ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
Assert . IsFalse ( Precision . IsSmallerWithDecimalPlaces ( 0.0 , - max , - Precision . Magnitude ( _d oublePrecision ) ) ) ;
}
[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 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 + mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 3 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 , 1.0 + 3 * _d oublePrecision , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 + _d oublePrecision , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - _d oublePrecision , 1 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 3 * _d oublePrecision , 1 ) ) ;
// compare with the two numbers reversed in compare order
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 + 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 + mD oublePrecision, 1.0 , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 - mD oublePrecision, 1.0 , 1 ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 - 3 * mD oublePrecision, 1.0 , 1 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 + 3 * _d oublePrecision , 1.0 , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 + _d oublePrecision , 1.0 , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 - _d oublePrecision , 1.0 , 1 ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 - 3 * _d oublePrecision , 1.0 , 1 ) ) ;
// compare two slightly more different numbers
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 + 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 1 0 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 + 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 1 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 1 0 * _d oublePrecision , 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 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 2 0 0 0 0 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 1 ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareTo ( 1.0 , 1.0 + 1e5 * _d oublePrecision , 1 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareTo ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 2 0 0 0 0 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareTo ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 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 + 1 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 1 0 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1 0 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
// compare with the two numbers reversed in compare order
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 + 1 0 * mD oublePrecision, 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 + mD oublePrecision, 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 - mD oublePrecision, 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 - 1 0 * mD oublePrecision, 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 + 1 0 * _d oublePrecision , 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 + _d oublePrecision , 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 - _d oublePrecision , 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 - 1 0 * _d oublePrecision , 1.0 , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
// compare two slightly more different numbers
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 5 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 5 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles - 2 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 5 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles - 2 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 5 0 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 5 0 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 5 0 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles - 2 ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 5 0 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles - 2 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 5 0 * _d oublePrecision , 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 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1e5 * mD oublePrecision, 1 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1e5 * mD oublePrecision, Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( - 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 + 1e5 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1e5 * _d oublePrecision , 1 0 ) ) ;
Assert . AreEqual ( 1 , Precision . CompareToInDecimalPlaces ( 1.0 , 1.0 - 1e5 * _d oublePrecision , Precision . NumberOfDecimalPlacesForDoubles ) ) ;
// compare inf & inf
Assert . AreEqual ( 0 , Precision . CompareToInDecimalPlaces ( double . PositiveInfinity , double . PositiveInfinity , Precision . NumberOfDecimalPlacesForDoubles ) ) ;