From e2862a8d7150da6afd13b6af58c79d4d06a024eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 3 May 2019 15:40:21 +0200 Subject: [PATCH] Add documentation for custom precision in float stringification --- docs/tostring.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/tostring.md b/docs/tostring.md index 77322dc6..549f8aed 100644 --- a/docs/tostring.md +++ b/docs/tostring.md @@ -7,6 +7,8 @@ [Catch::is_range specialisation](#catchis_range-specialisation)
[Exceptions](#exceptions)
[Enums](#enums)
+[Floating point precision](#floating-point-precision)
+ Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes). Most built-in or std types are supported out of the box but there are two ways that you can tell Catch how to convert your own types (or other, third-party types) into strings. @@ -104,6 +106,22 @@ TEST_CASE() { } ``` +## Floating point precision + +Catch provides a built-in `StringMaker` specialization for both `float` +`double`. By default, it uses what we think is a reasonable precision, +but you can customize it by modifying the `precision` static variable +inside the `StringMaker` specialization, like so: + +```cpp + Catch::StringMaker::precision = 15; + const float testFloat1 = 1.12345678901234567899f; + const float testFloat2 = 1.12345678991234567899f; + REQUIRE(testFloat1 == testFloat2); +``` + +This assertion will fail and print out the `testFloat1` and `testFloat2` +to 15 decimal places. ---