Skip to content

Commit

Permalink
apacheGH-36433: [C++] Update fast_float version to 3.10.1 (apache#36434)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
Co-authored-by: Ivan Chesnov <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
2 people authored and loicalleyne committed Nov 13, 2023
1 parent 7e09e1a commit c0ea39b
Show file tree
Hide file tree
Showing 13 changed files with 991 additions and 802 deletions.
2 changes: 2 additions & 0 deletions cpp/src/arrow/util/value_parsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#define FASTFLOAT_ALLOWS_LEADING_PLUS 1

#include "arrow/util/value_parsing.h"

#include <string>
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/util/value_parsing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ TEST(StringConversion, ToFloat) {
AssertConversion<FloatType>("0", 0.0f);
AssertConversion<FloatType>("-0.0", -0.0f);
AssertConversion<FloatType>("-1e20", -1e20f);
AssertConversion<FloatType>("+Infinity", std::numeric_limits<float>::infinity());
AssertConversion<FloatType>("-Infinity", -std::numeric_limits<float>::infinity());
AssertConversion<FloatType>("Infinity", std::numeric_limits<float>::infinity());

AssertConversionFails<FloatType>("");
AssertConversionFails<FloatType>("e");
Expand All @@ -135,6 +138,9 @@ TEST(StringConversion, ToDouble) {
AssertConversion<DoubleType>("0", 0);
AssertConversion<DoubleType>("-0.0", -0.0);
AssertConversion<DoubleType>("-1e100", -1e100);
AssertConversion<DoubleType>("+Infinity", std::numeric_limits<double>::infinity());
AssertConversion<DoubleType>("-Infinity", -std::numeric_limits<double>::infinity());
AssertConversion<DoubleType>("Infinity", std::numeric_limits<double>::infinity());

AssertConversionFails<DoubleType>("");
AssertConversionFails<DoubleType>("e");
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/vendored/fast_float/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# fast_float

The files in this directory are vendored from fast_float
git tag `v3.8.1`.
git tag `v3.10.1`.

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

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

You must replace `VERSION` in the command lines with suitable version
such as `3.8.1`.
such as `3.10.1`.

```bash
cpp/src/arrow/vendoered/fast_float/update.sh VERSION
Expand Down
15 changes: 11 additions & 4 deletions cpp/src/arrow/vendored/fast_float/ascii_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace fast_float {

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

fastfloat_really_inline uint64_t byteswap(uint64_t val) {
fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {
return (val & 0xFF00000000000000) >> 56
| (val & 0x00FF000000000000) >> 40
| (val & 0x0000FF0000000000) >> 24
Expand Down Expand Up @@ -45,7 +47,8 @@ fastfloat_really_inline void write_u64(uint8_t *chars, uint64_t val) {
}

// credit @aqrit
fastfloat_really_inline uint32_t parse_eight_digits_unrolled(uint64_t val) {
fastfloat_really_inline FASTFLOAT_CONSTEXPR14
uint32_t parse_eight_digits_unrolled(uint64_t val) {
const uint64_t mask = 0x000000FF000000FF;
const uint64_t mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
const uint64_t mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
Expand All @@ -60,7 +63,7 @@ fastfloat_really_inline uint32_t parse_eight_digits_unrolled(const char *chars)
}

// credit @aqrit
fastfloat_really_inline bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
fastfloat_really_inline constexpr bool is_made_of_eight_digits_fast(uint64_t val) noexcept {
return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) &
0x8080808080808080));
}
Expand Down Expand Up @@ -94,7 +97,11 @@ parsed_number_string parse_number_string(const char *p, const char *pend, parse_
answer.valid = false;
answer.too_many_digits = false;
answer.negative = (*p == '-');
#if FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default
if ((*p == '-') || (*p == '+')) {
#else
if (*p == '-') { // C++17 20.19.3.(7.1) explicitly forbids '+' sign here
#endif
++p;
if (p == pend) {
return answer;
Expand Down
Loading

0 comments on commit c0ea39b

Please sign in to comment.