|
2 | 2 | #define ALGORITHMS_H |
3 | 3 |
|
4 | 4 | #ifndef __CYGWIN__ |
5 | | -#include "absl/strings/str_cat.h" |
| 5 | +#include "absl/strings/str_format.h" |
6 | 6 | #endif |
7 | 7 |
|
8 | 8 | #if ERROL_SUPPORTED |
@@ -155,7 +155,7 @@ int netlib(T d, std::span<char>& buffer) { |
155 | 155 |
|
156 | 156 | template<arithmetic_float T> |
157 | 157 | int snprintf(T d, std::span<char>& buffer) { |
158 | | - return std::snprintf(buffer.data(), buffer.size(), "%g", d); |
| 158 | + return std::snprintf(buffer.data(), buffer.size(), "%.17g", d); |
159 | 159 | } |
160 | 160 |
|
161 | 161 | // grisu2::dtoa_impl::grisu2 can take a template type |
@@ -219,11 +219,12 @@ int double_conversion(T d, std::span<char>& buffer) { |
219 | 219 |
|
220 | 220 | template<arithmetic_float T> |
221 | 221 | int abseil(T d, std::span<char>& buffer) { |
222 | | - std::string s; |
223 | | - absl::StrAppend(&s, d); |
224 | | - std::copy(s.begin(), s.end(), buffer.begin()); |
225 | | - return size(s); |
226 | | - // return absl::SNPrintF(buffer.data(), buffer.size(), "%g", d); |
| 222 | + // StrAppend is faster but only outputs 6 digits after the decimal point |
| 223 | + // std::string s; |
| 224 | + // absl::StrAppend(&s, d); |
| 225 | + // std::copy(s.begin(), s.end(), buffer.begin()); |
| 226 | + // return size(s); |
| 227 | + return absl::SNPrintF(buffer.data(), buffer.size(), "%.17g", d); |
227 | 228 | } |
228 | 229 |
|
229 | 230 | template<arithmetic_float T> |
|
0 commit comments