refactor ToExponentAndMantissa to use StrFormat instead of std::stringstream#2138
refactor ToExponentAndMantissa to use StrFormat instead of std::stringstream#2138
Conversation
src/string_util.cc
Outdated
| void ToExponentAndMantissa(double val, int precision, double one_k, | ||
| std::string* mantissa, int64_t* exponent) { |
There was a problem hiding this comment.
IMHO this should be returning std::pair<std::string, int64_t>
There was a problem hiding this comment.
i don't hate output parameters, but they should at least be non-const references i think. but i'm also with returning a pair which does make sense for this API.
There was a problem hiding this comment.
(No strong opinion, consider it a suggestion)
src/string_util.cc
Outdated
| } | ||
| } | ||
| mantissa_stream << val; | ||
| *mantissa += StrFormat("%g", val); |
There was a problem hiding this comment.
I'd suggest extracting StrFormat("%g", x) into a lambda
There was a problem hiding this comment.
that might make it less explicit/less readable. i'd rather not.
There was a problem hiding this comment.
My point is that all these calls are meant to have the same format specifier,
but now each call site provides it's own format string.
If not a lambda, i'd suggest to at least define a macro for "%d"
No description provided.