diff options
| author | Martin Hořeňovský | 2017-02-27 14:22:17 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-02-27 14:22:17 +0100 |
| commit | e4f4335b07511589f4508527f9deaaa239f3c5ce (patch) | |
| tree | 320bb6c701ef4bd5a88c9673440d49a39c8edd74 /docs | |
| parent | 8c078997155a86b45fc2dcf66c571461ebf51348 (diff) | |
| download | catch3-e4f4335b07511589f4508527f9deaaa239f3c5ce.tar.gz | |
Improved Approx documentation
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/assertions.md | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/docs/assertions.md b/docs/assertions.md index d3a90478..ff79f0ee 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -53,13 +53,32 @@ Catch provides a way to perform tolerant comparisons of floating point values th REQUIRE( performComputation() == Approx( 2.1 ) ); ``` -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.: +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. +* __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`. +* __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`. +* __scale__ - scale serves to adjust the base for comparison used by epsilon, can be used when By default set to `1.0`. + +#### epsilon example +```cpp +Approx target = Approx(100).epsilon(0.01); +100.0 == target; // Obviously true +200.0 == target; // Obviously still false +100.5 == target; // True, because we set target to allow up to 1% error ``` -REQUIRE( 22/7 == Approx( 3.141 ).epsilon( 0.01 ) ); + +#### margin example +_Margin check is used only if the relative (epsilon and scale based) check fails._ +```cpp +Approx target = Approx(100).margin(5); +100.0 == target; // Obviously true +200.0 == target; // Obviously still false +104.0 == target; // True, because we set target to allow absolute error up to 5 ``` -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. +#### scale +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). + ## Exceptions |