Mega Code Archive

 
Categories / C# / Data Types
 

Is Nearly Equal

using System; using System.Collections.Generic; namespace Test {     class TestUtilities     {         // allow last three digits to deviate         public static readonly double TargetPrecision = Math.Pow(2.0, -42);         // equality of reals         public static bool IsNearlyEqual(double x, double y)         {             return (IsNearlyEqual(x, y, TargetPrecision));         }         public static bool IsNearlyEqual(double x, double y, double e)         {             if (2.0 * Math.Abs(x - y) <= e * (Math.Abs(x) + Math.Abs(y)))             {                 return (true);             }             else             {                 return (false);             }         }     } }