Commit d4e00bd4 by Simon Gene Gottlieb Committed by Jesse Beder

fix: rename fp_to_string to FpToString to match coding style

parent bd070a7b
...@@ -181,7 +181,7 @@ inline Emitter& Emitter::WriteStreamable(T value) { ...@@ -181,7 +181,7 @@ inline Emitter& Emitter::WriteStreamable(T value) {
} }
if (!special) { if (!special) {
stream << fp_to_string(value, stream.precision()); stream << FpToString(value, stream.precision());
} }
m_stream << stream.str(); m_stream << stream.str();
......
...@@ -26,13 +26,13 @@ namespace fp_formatting { ...@@ -26,13 +26,13 @@ namespace fp_formatting {
* *
* Example: * Example:
* std::array<char, 20> buffer; * std::array<char, 20> buffer;
* auto ct = convertToChars(buffer.begin(), buffer.end(), 23, 3); * auto ct = ConvertToChars(buffer.begin(), buffer.end(), 23, 3);
* assert(ct = 3); * assert(ct = 3);
* assert(buffer[0] == '0'); * assert(buffer[0] == '0');
* assert(buffer[1] == '2'); * assert(buffer[1] == '2');
* assert(buffer[2] == '3'); * assert(buffer[2] == '3');
*/ */
inline auto convertToChars(char* begin, char* end, size_t value, int width=1) -> int { inline auto ConvertToChars(char* begin, char* end, size_t value, int width=1) -> int {
assert(width >= 1); assert(width >= 1);
assert(end >= begin); // end must be after begin assert(end >= begin); // end must be after begin
assert(end-begin >= width); // Buffer must be large enough assert(end-begin >= width); // Buffer must be large enough
...@@ -62,7 +62,7 @@ inline auto convertToChars(char* begin, char* end, size_t value, int width=1) -> ...@@ -62,7 +62,7 @@ inline auto convertToChars(char* begin, char* end, size_t value, int width=1) ->
* converts a value 'v' to a string. Uses dragonbox for formatting. * converts a value 'v' to a string. Uses dragonbox for formatting.
*/ */
template <typename T> template <typename T>
auto fp_to_string(T v, int precision = 0) -> std::string { auto FpToString(T v, int precision = 0) -> std::string {
// assert(precision > 0); // assert(precision > 0);
// hardcoded constant, at which exponent should switch to a scientific notation // hardcoded constant, at which exponent should switch to a scientific notation
int const lowerExponentThreshold = -5; int const lowerExponentThreshold = -5;
...@@ -81,7 +81,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string { ...@@ -81,7 +81,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
auto r = jkj::dragonbox::to_decimal(v); auto r = jkj::dragonbox::to_decimal(v);
auto digits = std::array<char, 20>{}; // max digits of size_t is 20. auto digits = std::array<char, 20>{}; // max digits of size_t is 20.
auto digits_ct = convertToChars(digits.data(), digits.data() + digits.size(), r.significand); auto digits_ct = ConvertToChars(digits.data(), digits.data() + digits.size(), r.significand);
// check if requested precision is lower than // check if requested precision is lower than
// required digits for exact representation // required digits for exact representation
...@@ -136,7 +136,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string { ...@@ -136,7 +136,7 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
*(output_ptr++) = 'e'; *(output_ptr++) = 'e';
*(output_ptr++) = (exponent>=0)?'+':'-'; *(output_ptr++) = (exponent>=0)?'+':'-';
auto exp_digits = std::array<char, 20>{}; auto exp_digits = std::array<char, 20>{};
auto exp_digits_ct = convertToChars(exp_digits.data(), exp_digits.data() + exp_digits.size(), std::abs(exponent), /*.precision=*/ 2); auto exp_digits_ct = ConvertToChars(exp_digits.data(), exp_digits.data() + exp_digits.size(), std::abs(exponent), /*.precision=*/ 2);
for (int i{0}; i < exp_digits_ct; ++i) { for (int i{0}; i < exp_digits_ct; ++i) {
*(output_ptr++) = exp_digits[i]; *(output_ptr++) = exp_digits[i];
} }
...@@ -184,18 +184,18 @@ auto fp_to_string(T v, int precision = 0) -> std::string { ...@@ -184,18 +184,18 @@ auto fp_to_string(T v, int precision = 0) -> std::string {
} }
} }
inline auto fp_to_string(float v, size_t precision = 0) -> std::string { inline auto FpToString(float v, size_t precision = 0) -> std::string {
return detail::fp_formatting::fp_to_string(v, precision); return detail::fp_formatting::FpToString(v, precision);
} }
inline auto fp_to_string(double v, size_t precision = 0) -> std::string { inline auto FpToString(double v, size_t precision = 0) -> std::string {
return detail::fp_formatting::fp_to_string(v, precision); return detail::fp_formatting::FpToString(v, precision);
} }
/** /**
* dragonbox only works for floats/doubles not long double * dragonbox only works for floats/doubles not long double
*/ */
inline auto fp_to_string(long double v, size_t precision = std::numeric_limits<long double>::max_digits10) -> std::string { inline auto FpToString(long double v, size_t precision = std::numeric_limits<long double>::max_digits10) -> std::string {
std::stringstream ss; std::stringstream ss;
ss.precision(precision); ss.precision(precision);
ss.imbue(std::locale("C")); ss.imbue(std::locale("C"));
......
...@@ -130,7 +130,7 @@ inner_encode(const T& rhs, std::stringstream& stream){ ...@@ -130,7 +130,7 @@ inner_encode(const T& rhs, std::stringstream& stream){
stream << ".inf"; stream << ".inf";
} }
} else { } else {
stream << fp_to_string(rhs, stream.precision()); stream << FpToString(rhs, stream.precision());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment