Skip to content

Instantly share code, notes, and snippets.

@sailro
Created October 27, 2017 21:20
Show Gist options
  • Save sailro/672140effc6604fee6bdb6e2d5500309 to your computer and use it in GitHub Desktop.
Save sailro/672140effc6604fee6bdb6e2d5500309 to your computer and use it in GitHub Desktop.
[Test]
public void FloatingPointEvaluation()
{
/* If you create a custom algorithm that determines whether two floating-point
* numbers can be considered equal, you must use a value that is greater than
* the Epsilon constant to establish the acceptable absolute margin of difference
* for the two values to be considered equal. Typically, that margin of difference
* is many times greater than Epsilon. */
AssertExpressionsAtLine(13, "Fields.cs", new Evaluations
{
{ "1f + float.Epsilon == 1f", "true" },
{ "1d + double.Epsilon == 1d", "true" },
{ "1/6d+1/6d+1/6d+1/6d+1/6d+1/6d == 1d", "false" },
{ "1/6f+1/6f+1/6f+1/6f+1/6f+1/6f == 1f", "true" },
{ "Math.Abs(1.0f - (1/6f+1/6f+1/6f+1/6f+1/6f+1/6f)) < 1E-07", "true" },
{ "Math.Abs(1.0d - (1/6d+1/6d+1/6d+1/6d+1/6d+1/6d)) < 1E-07", "true" },
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment