Merge pull request #113982 from akien-mga/grisu2-2025-11

grisu2: Rediff patch and sync with latest upstream commit
This commit is contained in:
Thaddeus Crews 2025-12-15 08:01:05 -06:00
commit 14d8c55cfa
No known key found for this signature in database
GPG Key ID: 8C6E5FEB5FC03CCC
3 changed files with 21 additions and 26 deletions

View File

@ -437,7 +437,7 @@ Files extracted from upstream source:
## grisu2 ## grisu2
- Upstream: https://github.com/simdjson/simdjson/blob/master/src/to_chars.cpp - Upstream: https://github.com/simdjson/simdjson/blob/master/src/to_chars.cpp
- Version: git (4f4e81668ecb9d4d37fd5f59a1556d492507421d, 2023) - Version: git (667d0ed3c77f55cbda2082b034168d69898d1f88, 2025)
- License: Apache and MIT - License: Apache and MIT
Files extracted from upstream source: Files extracted from upstream source:

View File

@ -809,20 +809,14 @@ void grisu2_wrap(char *buf, int &len, int &decimal_exponent, FloatType value) {
*/ */
inline char *append_exponent(char *buf, int e) { inline char *append_exponent(char *buf, int e) {
if (e < 0) { bool isNegative = e < 0;
e = -e; e = isNegative ? -e : e;
*buf++ = '-'; *buf++ = isNegative ? '-' : '+';
} else {
*buf++ = '+';
}
auto k = static_cast<std::uint32_t>(e); auto k = static_cast<std::uint32_t>(e);
if (k < 10) { if (k < 100) {
// Always print at least two digits in the exponent. // Always print at least two digits in the exponent.
// This is for compatibility with printf("%g"). // This is for compatibility with printf("%g").
*buf++ = '0';
*buf++ = static_cast<char>('0' + k);
} else if (k < 100) {
*buf++ = static_cast<char>('0' + k / 10); *buf++ = static_cast<char>('0' + k / 10);
k %= 10; k %= 10;
*buf++ = static_cast<char>('0' + k); *buf++ = static_cast<char>('0' + k);
@ -915,6 +909,7 @@ char *to_chars(char *first, FloatType value) {
value = -value; value = -value;
*first++ = '-'; *first++ = '-';
} }
if (value == 0) // +-0 if (value == 0) // +-0
{ {
*first++ = '0'; *first++ = '0';

View File

@ -1,8 +1,8 @@
diff --git a/thirdparty/grisu2/grisu2.h b/thirdparty/grisu2/grisu2.h diff --git a/thirdparty/grisu2/grisu2.h b/thirdparty/grisu2/grisu2.h
index 19886cce47f..dbc09755fad 100644 index f140e1a192..316a727ce0 100644
--- a/thirdparty/grisu2/grisu2.h --- a/thirdparty/grisu2/grisu2.h
+++ b/thirdparty/grisu2/grisu2.h +++ b/thirdparty/grisu2/grisu2.h
@@ -1,15 +1,12 @@ @@ -1,15 +1,11 @@
-#ifndef SIMDJSON_SRC_TO_CHARS_CPP -#ifndef SIMDJSON_SRC_TO_CHARS_CPP
-#define SIMDJSON_SRC_TO_CHARS_CPP -#define SIMDJSON_SRC_TO_CHARS_CPP
- -
@ -20,7 +20,7 @@ index 19886cce47f..dbc09755fad 100644
/*! /*!
implements the Grisu2 algorithm for binary to decimal floating-point implements the Grisu2 algorithm for binary to decimal floating-point
conversion. conversion.
@@ -26,7 +23,6 @@ PLDI 2010 [2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and @@ -26,7 +22,6 @@ PLDI 2010 [2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and
Accurately", Proceedings of the ACM SIGPLAN 1996 Conference on Programming Accurately", Proceedings of the ACM SIGPLAN 1996 Conference on Programming
Language Design and Implementation, PLDI 1996 Language Design and Implementation, PLDI 1996
*/ */
@ -28,7 +28,7 @@ index 19886cce47f..dbc09755fad 100644
template <typename Target, typename Source> template <typename Target, typename Source>
Target reinterpret_bits(const Source source) { Target reinterpret_bits(const Source source) {
@@ -718,7 +714,7 @@ v = buf * 10^decimal_exponent @@ -718,7 +713,7 @@ v = buf * 10^decimal_exponent
len is the length of the buffer (number of decimal digits) len is the length of the buffer (number of decimal digits)
The buffer must be large enough, i.e. >= max_digits10. The buffer must be large enough, i.e. >= max_digits10.
*/ */
@ -37,7 +37,7 @@ index 19886cce47f..dbc09755fad 100644
diyfp v, diyfp m_plus) { diyfp v, diyfp m_plus) {
// --------(-----------------------+-----------------------)-------- (A) // --------(-----------------------+-----------------------)-------- (A)
@@ -775,7 +771,7 @@ len is the length of the buffer (number of decimal digits) @@ -775,7 +770,7 @@ len is the length of the buffer (number of decimal digits)
The buffer must be large enough, i.e. >= max_digits10. The buffer must be large enough, i.e. >= max_digits10.
*/ */
template <typename FloatType> template <typename FloatType>
@ -46,7 +46,7 @@ index 19886cce47f..dbc09755fad 100644
static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3, static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
"internal error: not enough precision"); "internal error: not enough precision");
@@ -804,7 +800,7 @@ void grisu2(char *buf, int &len, int &decimal_exponent, FloatType value) { @@ -804,7 +799,7 @@ void grisu2(char *buf, int &len, int &decimal_exponent, FloatType value) {
const boundaries w = compute_boundaries(value); const boundaries w = compute_boundaries(value);
#endif #endif
@ -55,7 +55,7 @@ index 19886cce47f..dbc09755fad 100644
} }
/*! /*!
@@ -864,10 +860,7 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent, @@ -858,10 +853,7 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent,
// len <= max_exp + 2 // len <= max_exp + 2
std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k)); std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
@ -67,7 +67,7 @@ index 19886cce47f..dbc09755fad 100644
} }
if (0 < n && n <= max_exp) { if (0 < n && n <= max_exp) {
@@ -909,8 +902,6 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent, @@ -903,8 +895,6 @@ inline char *format_buffer(char *buf, int len, int decimal_exponent,
return append_exponent(buf, n - 1); return append_exponent(buf, n - 1);
} }
@ -76,7 +76,7 @@ index 19886cce47f..dbc09755fad 100644
/*! /*!
The format of the resulting decimal representation is similar to printf's %g The format of the resulting decimal representation is similar to printf's %g
format. Returns an iterator pointing past-the-end of the decimal representation. format. Returns an iterator pointing past-the-end of the decimal representation.
@@ -918,19 +909,15 @@ format. Returns an iterator pointing past-the-end of the decimal representation. @@ -912,8 +902,8 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
@note The buffer must be large enough. @note The buffer must be large enough.
@note The result is NOT null-terminated. @note The result is NOT null-terminated.
*/ */
@ -87,9 +87,8 @@ index 19886cce47f..dbc09755fad 100644
bool negative = std::signbit(value); bool negative = std::signbit(value);
if (negative) { if (negative) {
value = -value; value = -value;
*first++ = '-'; @@ -922,9 +912,6 @@ char *to_chars(char *first, const char *last, double value) {
}
-
if (value == 0) // +-0 if (value == 0) // +-0
{ {
- *first++ = '0'; - *first++ = '0';
@ -98,7 +97,7 @@ index 19886cce47f..dbc09755fad 100644
*first++ = '0'; *first++ = '0';
return first; return first;
} }
@@ -940,15 +927,13 @@ char *to_chars(char *first, const char *last, double value) { @@ -934,15 +921,11 @@ char *to_chars(char *first, const char *last, double value) {
// len is the length of the buffer, i.e. the number of decimal digits. // len is the length of the buffer, i.e. the number of decimal digits.
int len = 0; int len = 0;
int decimal_exponent = 0; int decimal_exponent = 0;
@ -114,6 +113,7 @@ index 19886cce47f..dbc09755fad 100644
} }
-} // namespace internal -} // namespace internal
-} // namespace simdjson -} // namespace simdjson
+} // namespace grisu2 -
-#endif // SIMDJSON_SRC_TO_CHARS_CPP -#endif // SIMDJSON_SRC_TO_CHARS_CPP
\ No newline at end of file
+} // namespace grisu2