You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/assertions.md
+22-3Lines changed: 22 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,13 +53,32 @@ Catch provides a way to perform tolerant comparisons of floating point values th
53
53
REQUIRE( performComputation() == Approx( 2.1 ) );
54
54
```
55
55
56
-
By default a small epsilon value is used that covers many simple cases of rounding errors. When this is insufficent the epsilon value (the amount within which a difference either way is ignored) can be specified by calling the ```epsilon()``` method on the ```Approx``` instance. e.g.:
56
+
This way `Approx` is constructed with reasonable defaults, covering most simple cases of rounding errors. If these are insufficient, each `Approx` instance has 3 tuning knobs, that can be used to customize it for your computation.
57
57
58
+
*__epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
59
+
*__margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
60
+
*__scale__ - scale serves to adjust the base for comparison used by epsilon, can be used when By default set to `1.0`.
61
+
62
+
#### epsilon example
63
+
```cpp
64
+
Approx target = Approx(100).epsilon(0.01);
65
+
100.0 == target; // Obviously true
66
+
200.0 == target; // Obviously still false
67
+
100.5 == target; // True, because we set target to allow up to 1% error
_Margin check is used only if the relative (epsilon and scale based) check fails._
72
+
```cpp
73
+
Approx target = Approx(100).margin(5);
74
+
100.0 == target; // Obviously true
75
+
200.0 == target; // Obviously still false
76
+
104.0 == target; // True, because we set target to allow absolute error up to 5
60
77
```
61
78
62
-
When dealing with very large or very small numbers it can be useful to specify a scale, which can be achieved by calling the ```scale()``` method on the ```Approx``` instance.
79
+
#### scale
80
+
Scale can be useful if the computation leading to the result worked on different scale, than is used by the results (and thus expected errors are on a different scale than would be expected based on the results alone).
0 commit comments