Path: blob/master/thirdparty/grisu2/patches/0001-godot-changes.patch
9904 views
diff --git a/thirdparty/grisu2/grisu2.h b/thirdparty/grisu2/grisu2.h1index 19886cce47f..dbc09755fad 1006442--- a/thirdparty/grisu2/grisu2.h3+++ b/thirdparty/grisu2/grisu2.h4@@ -1,15 +1,12 @@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 +23,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 +714,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 +771,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 +800,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@@ -864,10 +860,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@@ -909,8 +902,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@@ -918,19 +909,15 @@ 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*first++ = '-';90}91-92if (value == 0) // +-093{94- *first++ = '0';95- // Make it look like a floating-point number (#362, #378)96- *first++ = '.';97*first++ = '0';98return first;99}100@@ -940,15 +927,13 @@ char *to_chars(char *first, const char *last, double value) {101// len is the length of the buffer, i.e. the number of decimal digits.102int len = 0;103int decimal_exponent = 0;104- dtoa_impl::grisu2(first, len, decimal_exponent, value);105+ grisu2_wrap(first, len, decimal_exponent, value);106// Format the buffer like printf("%.*g", prec, value)107constexpr int kMinExp = -4;108constexpr int kMaxExp = std::numeric_limits<double>::digits10;109110- return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp,111- kMaxExp);112+ return format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);113}114-} // namespace internal115-} // namespace simdjson116+} // namespace grisu2117118-#endif // SIMDJSON_SRC_TO_CHARS_CPP119120121