Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-05-03 17:46:03 +0200
committerGitHub2019-05-03 17:46:03 +0200
commit92ad9ee355945a4f2b494d1934faaa4bb412ae40 (patch)
tree0d51a85922fbe7f9abee77d3e3a36a3fc2d13e04 /include
parent9c741fe96073ed620ffc032afbed1f3c789d2b68 (diff)
parente2862a8d7150da6afd13b6af58c79d4d06a024eb (diff)
downloadcatch3-92ad9ee355945a4f2b494d1934faaa4bb412ae40.tar.gz
Merge pull request #1614 from mlimber/master
Allow custom precision in error reports for floating-point numbers
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_tostring.cpp9
-rw-r--r--include/internal/catch_tostring.h3
2 files changed, 10 insertions, 2 deletions
diff --git a/include/internal/catch_tostring.cpp b/include/internal/catch_tostring.cpp
index b857d3fb..f59676e7 100644
--- a/include/internal/catch_tostring.cpp
+++ b/include/internal/catch_tostring.cpp
@@ -234,11 +234,16 @@ std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) {
return "nullptr";
}
+int StringMaker<float>::precision = 5;
+
std::string StringMaker<float>::convert(float value) {
- return fpToString(value, 5) + 'f';
+ return fpToString(value, precision) + 'f';
}
+
+int StringMaker<double>::precision = 10;
+
std::string StringMaker<double>::convert(double value) {
- return fpToString(value, 10);
+ return fpToString(value, precision);
}
std::string ratio_string<std::atto>::symbol() { return "a"; }
diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h
index 52634a8c..cb248ea9 100644
--- a/include/internal/catch_tostring.h
+++ b/include/internal/catch_tostring.h
@@ -261,10 +261,13 @@ namespace Catch {
template<>
struct StringMaker<float> {
static std::string convert(float value);
+ static int precision;
};
+
template<>
struct StringMaker<double> {
static std::string convert(double value);
+ static int precision;
};
template <typename T>