mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
Merge branch 'main' of https://github.com/fastfloat/fast_float into fastfloat-main
This commit is contained in:
commit
681346fde1
3
.github/pull_request_template.md
vendored
3
.github/pull_request_template.md
vendored
@ -1,4 +1,5 @@
|
|||||||
We have benchmarks, please consider running them: see our README for details.
|
We have benchmarks, please consider running them: [see our README for details](https://github.com/fastfloat/fast_float/blob/main/README.md#benchmarking). We expect you to run our benchmarks if you make claims with respect to the performance.
|
||||||
|
|
||||||
|
|
||||||
Our CI tests check formatting automating. If such a test fails, please consider running the bash script:
|
Our CI tests check formatting automating. If such a test fails, please consider running the bash script:
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/vs17-ci.yml
vendored
2
.github/workflows/vs17-ci.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: configure
|
- name: configure
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_TEST=ON -DCMAKE_INSTALL_PREFIX:PATH=destination
|
cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_BENCHMARKS=ON -DFASTFLOAT_TEST=ON -DCMAKE_INSTALL_PREFIX:PATH=destination
|
||||||
- name: build
|
- name: build
|
||||||
run: |
|
run: |
|
||||||
cmake --build build --verbose --config ${{matrix.cfg}} --parallel
|
cmake --build build --verbose --config ${{matrix.cfg}} --parallel
|
||||||
|
|||||||
2
.github/workflows/vs17-clang-ci.yml
vendored
2
.github/workflows/vs17-clang-ci.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -T ClangCL -DFASTFLOAT_TEST=ON
|
cmake -S . -B build -G "${{matrix.gen}}" -A ${{matrix.arch}} -DFASTFLOAT_BENCHMARKS=ON -T ClangCL -DFASTFLOAT_TEST=ON
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --config ${{matrix.cfg}} --parallel --verbose
|
run: cmake --build build --config ${{matrix.cfg}} --parallel --verbose
|
||||||
- name: Run basic tests
|
- name: Run basic tests
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.9)
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
|
||||||
project(fast_float VERSION 8.0.0 LANGUAGES CXX)
|
project(fast_float VERSION 8.0.2 LANGUAGES CXX)
|
||||||
set(FASTFLOAT_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for fastfloat")
|
set(FASTFLOAT_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for fastfloat")
|
||||||
set(CMAKE_CXX_STANDARD ${FASTFLOAT_CXX_STANDARD})
|
set(CMAKE_CXX_STANDARD ${FASTFLOAT_CXX_STANDARD})
|
||||||
option(FASTFLOAT_TEST "Enable tests" OFF)
|
option(FASTFLOAT_TEST "Enable tests" OFF)
|
||||||
@ -55,11 +55,15 @@ if(FASTFLOAT_SANITIZE)
|
|||||||
target_link_libraries(fast_float INTERFACE -fuse-ld=gold)
|
target_link_libraries(fast_float INTERFACE -fuse-ld=gold)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(MSVC_VERSION GREATER 1910)
|
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
unset(FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE)
|
||||||
|
CHECK_CXX_COMPILER_FLAG(/permissive- FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE)
|
||||||
|
|
||||||
|
if(FASTFLOAT_COMPILER_SUPPORTS_PERMISSIVE)
|
||||||
target_compile_options(fast_float INTERFACE /permissive-)
|
target_compile_options(fast_float INTERFACE /permissive-)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(FASTFLOAT_INSTALL)
|
if(FASTFLOAT_INSTALL)
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
|||||||
16
README.md
16
README.md
@ -472,7 +472,7 @@ abseil : 430.45 MB/s (+/- 2.2 %) 20.52 Mfl
|
|||||||
fastfloat : 1042.38 MB/s (+/- 9.9 %) 49.68 Mfloat/s
|
fastfloat : 1042.38 MB/s (+/- 9.9 %) 49.68 Mfloat/s
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [Benchmarking](#benchmarking) Section for instructions on how to run our benchmarks.
|
See the [Benchmarking](#benchmarking) section for instructions on how to run our benchmarks.
|
||||||
|
|
||||||
## Video
|
## Video
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ sufficiently recent version of CMake (3.11 or better at least):
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
fast_float
|
fast_float
|
||||||
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
|
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
|
||||||
GIT_TAG tags/v8.0.0
|
GIT_TAG tags/v8.0.2
|
||||||
GIT_SHALLOW TRUE)
|
GIT_SHALLOW TRUE)
|
||||||
|
|
||||||
FetchContent_MakeAvailable(fast_float)
|
FetchContent_MakeAvailable(fast_float)
|
||||||
@ -514,7 +514,7 @@ You may also use [CPM](https://github.com/cpm-cmake/CPM.cmake), like so:
|
|||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME fast_float
|
NAME fast_float
|
||||||
GITHUB_REPOSITORY "fastfloat/fast_float"
|
GITHUB_REPOSITORY "fastfloat/fast_float"
|
||||||
GIT_TAG v8.0.0)
|
GIT_TAG v8.0.2)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using as single header
|
## Using as single header
|
||||||
@ -526,7 +526,7 @@ if desired as described in the command line help.
|
|||||||
|
|
||||||
You may directly download automatically generated single-header files:
|
You may directly download automatically generated single-header files:
|
||||||
|
|
||||||
<https://github.com/fastfloat/fast_float/releases/download/v8.0.0/fast_float.h>
|
<https://github.com/fastfloat/fast_float/releases/download/v8.0.2/fast_float.h>
|
||||||
|
|
||||||
## Benchmarking
|
## Benchmarking
|
||||||
|
|
||||||
@ -551,6 +551,14 @@ in some cases:
|
|||||||
sudo ./build/benchmarks/realbenchmark
|
sudo ./build/benchmarks/realbenchmark
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you have a text file containing one number per line (`myfile.txt`), you can run a benchmark over it like so:
|
||||||
|
```
|
||||||
|
cmake -B build -D FASTFLOAT_BENCHMARKS=ON
|
||||||
|
cmake --build build
|
||||||
|
./build/benchmarks/realbenchmark myfile.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Packages
|
## Packages
|
||||||
|
|
||||||
* The fast_float library is part of the [Conan package
|
* The fast_float library is part of the [Conan package
|
||||||
|
|||||||
@ -282,7 +282,11 @@ int main(int argc, char **argv) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (argc > 1) {
|
||||||
|
fileload(argv[1]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
fileload(std::string(BENCHMARK_DATA_DIR) + "/canada.txt");
|
fileload(std::string(BENCHMARK_DATA_DIR) + "/canada.txt");
|
||||||
fileload(std::string(BENCHMARK_DATA_DIR) + "/mesh.txt");
|
fileload(std::string(BENCHMARK_DATA_DIR) + "/mesh.txt");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -289,7 +289,7 @@ report_parse_error(UC const *p, parse_error error) noexcept {
|
|||||||
|
|
||||||
// Assuming that you use no more than 19 digits, this will
|
// Assuming that you use no more than 19 digits, this will
|
||||||
// parse an ASCII string.
|
// parse an ASCII string.
|
||||||
template <typename UC>
|
template <bool basic_json_fmt, typename UC>
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
|
||||||
parse_number_string(UC const *p, UC const *pend,
|
parse_number_string(UC const *p, UC const *pend,
|
||||||
parse_options_t<UC> const &options) noexcept {
|
parse_options_t<UC> const &options) noexcept {
|
||||||
@ -314,7 +314,8 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
return report_parse_error<UC>(p,
|
return report_parse_error<UC>(p,
|
||||||
parse_error::missing_integer_after_sign);
|
parse_error::missing_integer_after_sign);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (!is_integer(*p) &&
|
if (!is_integer(*p) &&
|
||||||
(*p !=
|
(*p !=
|
||||||
options.decimal_point)) { // a sign must be followed by an integer or the dot
|
options.decimal_point)) { // a sign must be followed by an integer or the dot
|
||||||
@ -340,8 +341,7 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
UC const *const end_of_integer_part = p;
|
UC const *const end_of_integer_part = p;
|
||||||
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
|
int64_t digit_count = int64_t(end_of_integer_part - start_digits);
|
||||||
answer.integer = span<UC const>(start_digits, size_t(digit_count));
|
answer.integer = span<UC const>(start_digits, size_t(digit_count));
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
||||||
if (uint64_t(options.format & detail::basic_json_fmt)) {
|
|
||||||
// at least 1 digit in integer part, without leading zeros
|
// at least 1 digit in integer part, without leading zeros
|
||||||
if (digit_count == 0) {
|
if (digit_count == 0) {
|
||||||
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
|
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
|
||||||
@ -351,7 +351,6 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
parse_error::leading_zeros_in_integer_part);
|
parse_error::leading_zeros_in_integer_part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int64_t exponent = 0;
|
int64_t exponent = 0;
|
||||||
bool const has_decimal_point = (p != pend) && (*p == options.decimal_point);
|
bool const has_decimal_point = (p != pend) && (*p == options.decimal_point);
|
||||||
@ -371,17 +370,14 @@ parse_number_string(UC const *p, UC const *pend,
|
|||||||
answer.fraction = span<UC const>(before, size_t(p - before));
|
answer.fraction = span<UC const>(before, size_t(p - before));
|
||||||
digit_count -= exponent;
|
digit_count -= exponent;
|
||||||
}
|
}
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
|
||||||
if (uint64_t(options.format & detail::basic_json_fmt)) {
|
|
||||||
// at least 1 digit in fractional part
|
// at least 1 digit in fractional part
|
||||||
if (has_decimal_point && exponent == 0) {
|
if (has_decimal_point && exponent == 0) {
|
||||||
return report_parse_error<UC>(p,
|
return report_parse_error<UC>(p,
|
||||||
parse_error::no_digits_in_fractional_part);
|
parse_error::no_digits_in_fractional_part);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
#endif
|
else if (digit_count == 0) { // we must have encountered at least one integer!
|
||||||
if (digit_count ==
|
|
||||||
0) { // we must have encountered at least one integer!
|
|
||||||
return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa);
|
return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa);
|
||||||
}
|
}
|
||||||
int64_t exp_number = 0; // explicit exponential part
|
int64_t exp_number = 0; // explicit exponential part
|
||||||
|
|||||||
@ -33,6 +33,12 @@
|
|||||||
#define FASTFLOAT_HAS_BYTESWAP 0
|
#define FASTFLOAT_HAS_BYTESWAP 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
|
||||||
|
#define FASTFLOAT_IF_CONSTEXPR17(x) if constexpr (x)
|
||||||
|
#else
|
||||||
|
#define FASTFLOAT_IF_CONSTEXPR17(x) if (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Testing for relevant C++20 constexpr library features
|
// Testing for relevant C++20 constexpr library features
|
||||||
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
|
#if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED && FASTFLOAT_HAS_BIT_CAST && \
|
||||||
defined(__cpp_lib_constexpr_algorithms) && \
|
defined(__cpp_lib_constexpr_algorithms) && \
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#define FASTFLOAT_VERSION_MAJOR 8
|
#define FASTFLOAT_VERSION_MAJOR 8
|
||||||
#define FASTFLOAT_VERSION_MINOR 0
|
#define FASTFLOAT_VERSION_MINOR 0
|
||||||
#define FASTFLOAT_VERSION_PATCH 0
|
#define FASTFLOAT_VERSION_PATCH 2
|
||||||
|
|
||||||
#define FASTFLOAT_STRINGIZE_IMPL(x) #x
|
#define FASTFLOAT_STRINGIZE_IMPL(x) #x
|
||||||
#define FASTFLOAT_STRINGIZE(x) FASTFLOAT_STRINGIZE_IMPL(x)
|
#define FASTFLOAT_STRINGIZE(x) FASTFLOAT_STRINGIZE_IMPL(x)
|
||||||
|
|||||||
@ -324,7 +324,12 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
|
|||||||
FASTFLOAT_ASSUME(first < last);
|
FASTFLOAT_ASSUME(first < last);
|
||||||
#endif
|
#endif
|
||||||
parsed_number_string_t<UC> const pns =
|
parsed_number_string_t<UC> const pns =
|
||||||
parse_number_string<UC>(first, last, options);
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
|
uint64_t(options.format & detail::basic_json_fmt)
|
||||||
|
? parse_number_string<true, UC>(first, last, options)
|
||||||
|
:
|
||||||
|
#endif
|
||||||
|
parse_number_string<false, UC>(first, last, options);
|
||||||
if (!pns.valid) {
|
if (!pns.valid) {
|
||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
if (uint64_t(options.format & chars_format::no_infnan)) {
|
if (uint64_t(options.format & chars_format::no_infnan)) {
|
||||||
|
|||||||
@ -131,7 +131,7 @@ int main() {
|
|||||||
for (std::size_t i = 0; i < reject.size(); ++i) {
|
for (std::size_t i = 0; i < reject.size(); ++i) {
|
||||||
auto const &f = reject[i].input;
|
auto const &f = reject[i].input;
|
||||||
auto const &expected_reason = reject[i].reason;
|
auto const &expected_reason = reject[i].reason;
|
||||||
auto answer = fast_float::parse_number_string(
|
auto answer = fast_float::parse_number_string<true>(
|
||||||
f.data(), f.data() + f.size(),
|
f.data(), f.data() + f.size(),
|
||||||
fast_float::parse_options(
|
fast_float::parse_options(
|
||||||
fast_float::chars_format::json |
|
fast_float::chars_format::json |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user