The value used during the assertion.
The target value.
An epsilon value to be used as the maximum absolute and relative error in the comparison.
The error message to display.
The file name where the error occurred. The value is added automatically at the call site.
The line where the error occurred. The value is added automatically at the call site.
DUnitAssertError if the assertation fails.
1 float smallestFloatSubnormal = float.min_normal * float.epsilon; 2 smallestFloatSubnormal.assertApprox(-smallestFloatSubnormal, 0.00001); 3 4 double smallestDoubleSubnormal = double.min_normal * double.epsilon; 5 smallestDoubleSubnormal.assertApprox(-smallestDoubleSubnormal, 0.00001); 6 7 0.0f.assertApprox(-0.0f, 0.00001); 8 (-0.0f).assertApprox(0.0f, 0.00001); 9 0.0.assertApprox(-0.0, 0.00001); 10 (-0.0).assertApprox(0.0, 0.00001); 11 2.0f.assertApprox(1.99f, 0.01); 12 1.99f.assertApprox(2.0f, 0.01); 13 2.0.assertApprox(1.99, 0.01); 14 1.99.assertApprox(2.0, 0.01); 15 16 // The following tests pass but are open for debate whether or not they should. 17 float.max.assertApprox(float.infinity, 0.00001); 18 float.infinity.assertApprox(float.max, 0.00001); 19 double.infinity.assertApprox(double.max, 0.00001); 20 double.max.assertApprox(double.infinity, 0.00001); 21 float.nan.assertApprox(float.nan, 0.00001); 22 double.nan.assertApprox(double.nan, 0.00001); 23 24 // Assert a DUnitAssertError is thrown if assertApprox fails. 25 10f.assertApprox(0f, 0.00001).assertThrow!(DUnitAssertError)("Failed asserting approximately equal");
Assert that two floating point values are approximately equal using an epsilon value.