Skip to content

Commit bbec8d5

Browse files
xxlaykxxkou
andauthored
apacheGH-36433: [C++] Update fast_float version to 3.10.1 (apache#36434) (#34)
### Rationale for this change Need this for parsing Infinity values with + sign. ### What changes are included in this PR? updated version of fast_float to version 3.10.1 (used this version because in higher versions c++ 20 started using that cause a lot of build errors) ### Are these changes tested? in scope of fast_float. ### Are there any user-facing changes? no * Closes: apache#36433 Lead-authored-by: Ivan Chesnov <ivan.chesnov@dremio.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent 03f3105 commit bbec8d5

13 files changed

+991
-802
lines changed

cpp/src/arrow/util/value_parsing.cc

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
#define FASTFLOAT_ALLOWS_LEADING_PLUS 1
19+
1820
#include "arrow/util/value_parsing.h"
1921

2022
#include <string>

cpp/src/arrow/util/value_parsing_test.cc

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ TEST(StringConversion, ToFloat) {
119119
AssertConversion<FloatType>("0", 0.0f);
120120
AssertConversion<FloatType>("-0.0", -0.0f);
121121
AssertConversion<FloatType>("-1e20", -1e20f);
122+
AssertConversion<FloatType>("+Infinity", std::numeric_limits<float>::infinity());
123+
AssertConversion<FloatType>("-Infinity", -std::numeric_limits<float>::infinity());
124+
AssertConversion<FloatType>("Infinity", std::numeric_limits<float>::infinity());
122125

123126
AssertConversionFails<FloatType>("");
124127
AssertConversionFails<FloatType>("e");
@@ -135,6 +138,9 @@ TEST(StringConversion, ToDouble) {
135138
AssertConversion<DoubleType>("0", 0);
136139
AssertConversion<DoubleType>("-0.0", -0.0);
137140
AssertConversion<DoubleType>("-1e100", -1e100);
141+
AssertConversion<DoubleType>("+Infinity", std::numeric_limits<double>::infinity());
142+
AssertConversion<DoubleType>("-Infinity", -std::numeric_limits<double>::infinity());
143+
AssertConversion<DoubleType>("Infinity", std::numeric_limits<double>::infinity());
138144

139145
AssertConversionFails<DoubleType>("");
140146
AssertConversionFails<DoubleType>("e");

cpp/src/arrow/vendored/fast_float/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# fast_float
2121

2222
The files in this directory are vendored from fast_float
23-
git tag `v3.8.1`.
23+
git tag `v3.10.1`.
2424

2525
See https://github.com/fastfloat/fast_float
2626

@@ -31,7 +31,7 @@ See https://github.com/fastfloat/fast_float
3131
## How to update
3232

3333
You must replace `VERSION` in the command lines with suitable version
34-
such as `3.8.1`.
34+
such as `3.10.1`.
3535

3636
```bash
3737
cpp/src/arrow/vendoered/fast_float/update.sh VERSION

cpp/src/arrow/vendored/fast_float/ascii_number.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ namespace fast_float {
1313

1414
// Next function can be micro-optimized, but compilers are entirely
1515
// able to optimize it well.
16-
fastfloat_really_inline bool is_integer(char c) noexcept { return c >= '0' && c <= '9'; }
16+
fastfloat_really_inline constexpr bool is_integer(char c) noexcept {
17+
return c >= '0' && c <= '9';
18+
}
1719

18-
fastfloat_really_inline uint64_t byteswap(uint64_t val) {
20+
fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {
1921
return (val & 0xFF00000000000000) >> 56
2022
| (val & 0x00FF000000000000) >> 40
2123
| (val & 0x0000FF0000000000) >> 24
@@ -45,7 +47,8 @@ fastfloat_really_inline void write_u64(uint8_t *chars, uint64_t val) {
4547
}
4648

4749
// credit @aqrit
48-
fastfloat_really_inline uint32_t parse_eight_digits_unrolled(uint64_t val) {
50+
fastfloat_really_inline FASTFLOAT_CONSTEXPR14
51+
uint32_t parse_eight_digits_unrolled(uint64_t val) {
4952
const uint64_t mask = 0x000000FF000000FF;
5053
const uint64_t mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
5154
const uint64_t mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
@@ -60,7 +63,7 @@ fastfloat_really_inline uint32_t parse_eight_digits_unrolled(const char *chars)
6063
}
6164

6265
// credit @aqrit
63-
fastfloat_really_inline bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
66+
fastfloat_really_inline constexpr bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
6467
return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) &
6568
0x8080808080808080));
6669
}
@@ -94,7 +97,11 @@ parsed_number_string parse_number_string(const char *p, const char *pend, parse_
9497
answer.valid = false;
9598
answer.too_many_digits = false;
9699
answer.negative = (*p == '-');
100+
#if FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
101+
if ((*p == '-') || (*p == '+')) {
102+
#else
97103
if (*p == '-') { // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
104+
#endif
98105
++p;
99106
if (p == pend) {
100107
return answer;

0 commit comments

Comments
 (0)