-Fixed DefaultValueHandling.Ignore with decimal properties

-Fixed approximate floating point comparisons
This commit is contained in:
James Newton-King
2012-06-09 13:54:30 +12:00
parent 55854f1682
commit 1b972cd65f
6 changed files with 90 additions and 4 deletions
+9 -2
View File
@@ -83,8 +83,15 @@ namespace Newtonsoft.Json.Utilities
public static bool ApproxEquals(double d1, double d2)
{
// are values equal to within 6 (or so) digits of precision?
return Math.Abs(d1 - d2) < (Math.Abs(d1) * 1e-6);
const double epsilon = 2.2204460492503131E-16;
if (d1 == d2)
return true;
double tolerance = ((Math.Abs(d1) + Math.Abs(d2)) + 10.0) * epsilon;
double difference = d1 - d2;
return (-tolerance < difference && tolerance > difference);
}
}
}