Path: blob/master/thirdparty/grisu2/patches/0001-godot-changes.patch
22122 views
diff --git a/thirdparty/grisu2/grisu2.h b/thirdparty/grisu2/grisu2.h1index f140e1a192..316a727ce0 1006442--- a/thirdparty/grisu2/grisu2.h3+++ b/thirdparty/grisu2/grisu2.h4@@ -1,15 +1,11 @@5-#ifndef SIMDJSON_SRC_TO_CHARS_CPP6-#define SIMDJSON_SRC_TO_CHARS_CPP7-8-#include <base.h>9+#pragma once1011#include <cstring>12#include <cstdint>13#include <array>14#include <cmath>1516-namespace simdjson {17-namespace internal {18+namespace grisu2 {19/*!20implements the Grisu2 algorithm for binary to decimal floating-point21conversion.22@@ -26,7 +22,6 @@ PLDI 2010 [2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and23Accurately", Proceedings of the ACM SIGPLAN 1996 Conference on Programming24Language Design and Implementation, PLDI 199625*/26-namespace dtoa_impl {2728template <typename Target, typename Source>29Target reinterpret_bits(const Source source) {30@@ -718,7 +713,7 @@ v = buf * 10^decimal_exponent31len is the length of the buffer (number of decimal digits)32The buffer must be large enough, i.e. >= max_digits10.33*/34-inline void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus,35+inline void grisu2_core(char *buf, int &len, int &decimal_exponent, diyfp m_minus,36diyfp v, diyfp m_plus) {3738// --------(-----------------------+-----------------------)-------- (A)39@@ -775,7 +770,7 @@ len is the length of the buffer (number of decimal digits)40The buffer must be large enough, i.e. >= max_digits10.41*/42template <typename FloatType>43-void grisu2(char *buf, int &len, int &decimal_exponent, FloatType value) {44+void grisu2_wrap(char *buf, int &len, int &decimal_exponent, FloatType value) {45static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,46"internal error: not enough precision");4748@@ -804,7 +799,7 @@ void grisu2(char *buf, int &len, int &decimal_exponent, FloatType value) {49const boundaries w = compute_boundaries(value);50#endif5152- grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);53+ grisu2_core(buf, len, decimal_exponent, w.minus, w.w, w.plus);54}5556/*!57@@ -858,10 +853,7 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent,58// len <= max_exp + 25960std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));61- // Make it look like a floating-point number (#362, #378)62- buf[n + 0] = '.';63- buf[n + 1] = '0';64- return buf + (static_cast<size_t>(n)) + 2;65+ return buf + (static_cast<size_t>(n));66}6768if (0 < n && n <= max_exp) {69@@ -903,8 +895,6 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent,70return append_exponent(buf, n - 1);71}7273-} // namespace dtoa_impl74-75/*!76The format of the resulting decimal representation is similar to printf's %g77format. Returns an iterator pointing past-the-end of the decimal representation.78@@ -912,8 +902,8 @@ format. Returns an iterator pointing past-the-end of the decimal representation.79@note The buffer must be large enough.80@note The result is NOT null-terminated.81*/82-char *to_chars(char *first, const char *last, double value) {83- static_cast<void>(last); // maybe unused - fix warning84+template <typename FloatType>85+char *to_chars(char *first, FloatType value) {86bool negative = std::signbit(value);87if (negative) {88value = -value;89@@ -922,9 +912,6 @@ char *to_chars(char *first, const char *last, double value) {9091if (value == 0) // +-092{93- *first++ = '0';94- // Make it look like a floating-point number (#362, #378)95- *first++ = '.';96*first++ = '0';97return first;98}99@@ -934,15 +921,11 @@ char *to_chars(char *first, const char *last, double value) {100// len is the length of the buffer, i.e. the number of decimal digits.101int len = 0;102int decimal_exponent = 0;103- dtoa_impl::grisu2(first, len, decimal_exponent, value);104+ grisu2_wrap(first, len, decimal_exponent, value);105// Format the buffer like printf("%.*g", prec, value)106constexpr int kMinExp = -4;107constexpr int kMaxExp = std::numeric_limits<double>::digits10;108109- return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp,110- kMaxExp);111+ return format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);112}113-} // namespace internal114-} // namespace simdjson115-116-#endif // SIMDJSON_SRC_TO_CHARS_CPP117\ No newline at end of file118+} // namespace grisu2119120121