Skip to content

Commit 0bbfe98

Browse files
authored
GH-35669: [C++] Update to double-conversion 3.3.0, activate new flags, remove patches (#36002)
[double-conversion v3.3.0](https://github.com/google/double-conversion/releases/tag/v3.3.0) adds a [new feature](google/double-conversion#195) that allows us to remove the special code that was added to our vendored copy of double-conversion in #9816. This PR: * Updates vendored double-conversion to v3.3.0 * Activates the new flags `EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL` and `EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL` * Removes the patches in `cpp/src/arrow/vendored/double-conversion/patches` ----- * Closes: #35669 Authored-by: Ian Cook <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 6808bfe commit 0bbfe98

File tree

8 files changed

+41
-77
lines changed

8 files changed

+41
-77
lines changed

cpp/src/arrow/vendored/double-conversion/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
under the License.
1818
-->
1919

20-
The files in this directory are vendored from double-conversion git tag v3.2.1
20+
The files in this directory are vendored from double-conversion git tag v3.3.0
2121

2222
To update, run:
2323

@@ -28,8 +28,5 @@ To update, run:
2828
For example:
2929

3030
```
31-
./update.sh 3.2.1
31+
./update.sh 3.3.0
3232
```
33-
34-
If there are errors patching changes, you may have to manually intervene and resolve patch errors.
35-
If so, please update the patches so the modifications are explicit.

cpp/src/arrow/vendored/double-conversion/bignum.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void Bignum::AssignHexString(Vector<const char> value) {
148148
}
149149
if (tmp > 0) {
150150
DOUBLE_CONVERSION_ASSERT(tmp <= kBigitMask);
151-
RawBigit(used_bigits_++) = (tmp & kBigitMask);
151+
RawBigit(used_bigits_++) = static_cast<Bignum::Chunk>(tmp & kBigitMask);
152152
}
153153
Clamp();
154154
}
@@ -205,7 +205,7 @@ void Bignum::AddBignum(const Bignum& other) {
205205
carry = sum >> kBigitSize;
206206
++bigit_pos;
207207
}
208-
used_bigits_ = (std::max)(bigit_pos, static_cast<int>(used_bigits_));
208+
used_bigits_ = static_cast<int16_t>(std::max(bigit_pos, static_cast<int>(used_bigits_)));
209209
DOUBLE_CONVERSION_ASSERT(IsClamped());
210210
}
211211

@@ -241,7 +241,7 @@ void Bignum::ShiftLeft(const int shift_amount) {
241241
if (used_bigits_ == 0) {
242242
return;
243243
}
244-
exponent_ += (shift_amount / kBigitSize);
244+
exponent_ += static_cast<int16_t>(shift_amount / kBigitSize);
245245
const int local_shift = shift_amount % kBigitSize;
246246
EnsureCapacity(used_bigits_ + 1);
247247
BigitsShiftLeft(local_shift);
@@ -419,7 +419,7 @@ void Bignum::Square() {
419419
DOUBLE_CONVERSION_ASSERT(accumulator == 0);
420420

421421
// Don't forget to update the used_digits and the exponent.
422-
used_bigits_ = product_length;
422+
used_bigits_ = static_cast<int16_t>(product_length);
423423
exponent_ *= 2;
424424
Clamp();
425425
}
@@ -740,8 +740,8 @@ void Bignum::Align(const Bignum& other) {
740740
for (int i = 0; i < zero_bigits; ++i) {
741741
RawBigit(i) = 0;
742742
}
743-
used_bigits_ += zero_bigits;
744-
exponent_ -= zero_bigits;
743+
used_bigits_ += static_cast<int16_t>(zero_bigits);
744+
exponent_ -= static_cast<int16_t>(zero_bigits);
745745

746746
DOUBLE_CONVERSION_ASSERT(used_bigits_ >= 0);
747747
DOUBLE_CONVERSION_ASSERT(exponent_ >= 0);

cpp/src/arrow/vendored/double-conversion/double-to-string.cc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,14 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
8080
StringBuilder* result_builder) const {
8181
DOUBLE_CONVERSION_ASSERT(length != 0);
8282
result_builder->AddCharacter(decimal_digits[0]);
83-
84-
/* If the mantissa of the scientific notation representation is an integer number,
85-
* the EMIT_TRAILING_DECIMAL_POINT flag will add a '.' character at the end of the
86-
* representation:
87-
* - With EMIT_TRAILING_DECIMAL_POINT enabled -> 0.0009 => 9.E-4
88-
* - With EMIT_TRAILING_DECIMAL_POINT disabled -> 0.0009 => 9E-4
89-
*
90-
* If the mantissa is an integer and the EMIT_TRAILING_ZERO_AFTER_POINT flag is enabled
91-
* it will add a '0' character at the end of the mantissa representation. Note that that
92-
* flag depends on EMIT_TRAILING_DECIMAL_POINT flag be enabled.*/
93-
if(length == 1){
94-
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) {
83+
if (length == 1) {
84+
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL) != 0) {
9585
result_builder->AddCharacter('.');
96-
97-
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) {
86+
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL) != 0) {
9887
result_builder->AddCharacter('0');
9988
}
10089
}
101-
} else {
90+
} else {
10291
result_builder->AddCharacter('.');
10392
result_builder->AddSubstring(&decimal_digits[1], length-1);
10493
}

cpp/src/arrow/vendored/double-conversion/double-to-string.h

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ class DoubleToStringConverter {
7979
EMIT_TRAILING_DECIMAL_POINT = 2,
8080
EMIT_TRAILING_ZERO_AFTER_POINT = 4,
8181
UNIQUE_ZERO = 8,
82-
NO_TRAILING_ZERO = 16
82+
NO_TRAILING_ZERO = 16,
83+
EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL = 32,
84+
EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL = 64
8385
};
8486

8587
// Flags should be a bit-or combination of the possible Flags-enum.
@@ -98,6 +100,13 @@ class DoubleToStringConverter {
98100
// of the result in precision mode. Matches printf's %g.
99101
// When EMIT_TRAILING_ZERO_AFTER_POINT is also given, one trailing zero is
100102
// preserved.
103+
// - EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL: when the input number has
104+
// exactly one significant digit and is converted into exponent form then a
105+
// trailing decimal point is appended to the significand in shortest mode
106+
// or in precision mode with one requested digit.
107+
// - EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL: in addition to a trailing
108+
// decimal point emits a trailing '0'-character. This flag requires the
109+
// EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag.
101110
//
102111
// Infinity symbol and nan_symbol provide the string representation for these
103112
// special values. If the string is NULL and the special value is encountered
@@ -132,17 +141,22 @@ class DoubleToStringConverter {
132141
// ToPrecision(230.0, 2) -> "230"
133142
// ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
134143
// ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
135-
// When converting numbers to scientific notation representation, if the mantissa of
136-
// the representation is an integer number, the EMIT_TRAILING_DECIMAL_POINT flag will
137-
// add a '.' character at the end of the representation:
138-
// - With EMIT_TRAILING_DECIMAL_POINT enabled -> 0.0009 => 9.E-4
139-
// - With EMIT_TRAILING_DECIMAL_POINT disabled -> 0.0009 => 9E-4
140-
//
141-
// If the mantissa is an integer and the EMIT_TRAILING_ZERO_AFTER_POINT flag is enabled
142-
// it will add a '0' character at the end of the mantissa representation. Note that that
143-
// flag depends on EMIT_TRAILING_DECIMAL_POINT flag be enabled.
144-
// - With EMIT_TRAILING_ZERO_AFTER_POINT enabled -> 0.0009 => 9.0E-4
145144
//
145+
// When converting numbers with exactly one significant digit to exponent
146+
// form in shortest mode or in precision mode with one requested digit, the
147+
// EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT flags have
148+
// no effect. Use the EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag to
149+
// append a decimal point in this case and the
150+
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL flag to also append a
151+
// '0'-character in this case.
152+
// Example with decimal_in_shortest_low = 0:
153+
// ToShortest(0.0009) -> "9e-4"
154+
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL deactivated.
155+
// ToShortest(0.0009) -> "9.e-4"
156+
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated.
157+
// ToShortest(0.0009) -> "9.0e-4"
158+
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated and
159+
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL activated.
146160
//
147161
// The min_exponent_width is used for exponential representations.
148162
// The converter adds leading '0's to the exponent until the exponent

cpp/src/arrow/vendored/double-conversion/patches/double-to-string.cc.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

cpp/src/arrow/vendored/double-conversion/patches/double-to-string.h.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

cpp/src/arrow/vendored/double-conversion/update.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2323

2424
if [ "$#" -ne 1 ]; then
2525
echo "Usage: $0 VERSION"
26-
echo " e.g.: $0 3.2.1"
26+
echo " e.g.: $0 3.3.0"
2727
exit 1
2828
fi
2929

@@ -49,8 +49,4 @@ namespace arrow_vendored {' \
4949
*.{h,cc}
5050
rm *.bak
5151

52-
# Custom changes for Arrow
53-
patch double-to-string.cc patches/double-to-string.cc.patch
54-
patch double-to-string.h patches/double-to-string.h.patch
55-
5652
popd

cpp/src/gandiva/formatting_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class FloatToStringGdvMixin
4949
explicit FloatToStringGdvMixin(const std::shared_ptr<arrow::DataType>& = NULLPTR)
5050
: arrow::internal::FloatToStringFormatterMixin<ARROW_TYPE>(
5151
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT |
52-
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT,
52+
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
53+
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL |
54+
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL,
5355
"Infinity", "NaN", 'E', -3, 7, 3, 1) {}
5456
};
5557

0 commit comments

Comments
 (0)