Skip to content

Commit

Permalink
Update catch_tostring.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
mlimber authored and horenmar committed May 1, 2019
1 parent 9c741fe commit 3794770
Show file tree
Hide file tree
Showing 4 changed files with 1,608 additions and 2 deletions.
25 changes: 23 additions & 2 deletions include/internal/catch_tostring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,32 @@ std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) {
return "nullptr";
}

int StringMaker<float>::m_precision = 5;

std::string StringMaker<float>::convert(float value) {
return fpToString(value, 5) + 'f';
return fpToString(value, m_precision) + 'f';
}

void StringMaker<float>::setPrecision(int precision) {
m_precision = precision;
}

int StringMaker<float>::getPrecision() {
return m_precision;
}

int StringMaker<double>::m_precision = 10;

std::string StringMaker<double>::convert(double value) {
return fpToString(value, 10);
return fpToString(value, m_precision);
}

void StringMaker<double>::setPrecision(int precision) {
m_precision = precision;
}

int StringMaker<double>::getPrecision() {
return m_precision;
}

std::string ratio_string<std::atto>::symbol() { return "a"; }
Expand Down
9 changes: 9 additions & 0 deletions include/internal/catch_tostring.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,19 @@ namespace Catch {
template<>
struct StringMaker<float> {
static std::string convert(float value);
static void setPrecision(int precision);
static int getPrecision();
private:
static int m_precision;
};

template<>
struct StringMaker<double> {
static std::string convert(double value);
static void setPrecision(int precision);
static int getPrecision();
private:
static int m_precision;
};

template <typename T>
Expand Down
Loading

0 comments on commit 3794770

Please sign in to comment.