diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-12-06 18:16:02 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-12-06 18:59:01 +0300 |
commit | 7b54ff800a86d9aa605ba6a42b211ac380beee68 (patch) | |
tree | de435c594ef9c0569e17ed62f224306c8c176e4c | |
parent | d2a0bf3d78be62c7d28bf3de9f3440cafc68b16a (diff) | |
download | ydb-7b54ff800a86d9aa605ba6a42b211ac380beee68.tar.gz |
Update contrib/restricted/fast_float to 7.0.0
commit_hash:7c62ecaa4d09ddb054eabaa7bf99004748257433
10 files changed, 476 insertions, 325 deletions
diff --git a/contrib/restricted/fast_float/.yandex_meta/devtools.licenses.report b/contrib/restricted/fast_float/.yandex_meta/devtools.licenses.report index 02eb43f3ee..8abcfe786e 100644 --- a/contrib/restricted/fast_float/.yandex_meta/devtools.licenses.report +++ b/contrib/restricted/fast_float/.yandex_meta/devtools.licenses.report @@ -29,6 +29,18 @@ # FILE_INCLUDE - include all file data into licenses text file # ======================= +KEEP MIT 0fd56f828db65664f447da50874ce655 +BELONGS ya.make + License text: + 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a + Scancode info: + Original SPDX id: MIT + Score : 100.00 + Match type : TAG + Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT + Files with this license: + README.md [513:513] + KEEP BSL-1.0 2c7a3fa82e66676005cd4ee2608fd7d2 BELONGS ya.make Note: matched license text is too long. Read it in the source files. @@ -64,108 +76,86 @@ FILE_INCLUDE AUTHORS found in files: LICENSE-MIT at line 23 Files with this license: LICENSE-MIT [5:27] -SKIP LicenseRef-scancode-unknown-license-reference 5332daea95b50b06c92625648767000b +KEEP Apache-2.0 AND MIT 5eed35bbf652e4d32c909d95331a0c79 BELONGS ya.make - License text: - Licensed under either of <a href="LICENSE-APACHE">Apache License, Version - Scancode info: - Original SPDX id: LicenseRef-scancode-unknown-license-reference - Score : 11.00 - Match type : INTRO - Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.LICENSE - Files with this license: - README.md [462:462] - -KEEP Apache-2.0 5e7d4154fa46facc827f6086a0b6b5d1 -BELONGS ya.make - License text: - under the Apache 2.0 license. + Note: matched license text is too long. Read it in the source files. Scancode info: Original SPDX id: Apache-2.0 - Score : 100.00 + Score : 49.30 Match type : NOTICE Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0 Files with this license: - README.md [457:457] - -KEEP Apache-2.0 62795c4c9961569de215634277f01a15 -BELONGS ya.make - License text: - Licensed under either of <a href="LICENSE-APACHE">Apache License, Version + README.md [507:520] Scancode info: - Original SPDX id: Apache-2.0 - Score : 90.00 - Match type : TAG - Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0 + Original SPDX id: MIT + Score : 49.30 + Match type : NOTICE + Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT Files with this license: - README.md [462:462] + README.md [507:520] -KEEP Apache-2.0 922a268d401707c0a55929c692c037a5 +KEEP Apache-2.0 79f65f9f30b137f9b03d455de6cfdac9 BELONGS ya.make License text: Licensed under either of <a href="LICENSE-APACHE">Apache License, Version - 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . + 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a Scancode info: Original SPDX id: Apache-2.0 Score : 100.00 Match type : REFERENCE Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0 Files with this license: - README.md [462:463] + README.md [512:513] -KEEP BSL-1.0 923e9cb72b59149633868ff72a9e17c6 +KEEP BSL-1.0 AND BSL-1.0 a8fd7a0ddc7793219e50dfdeb4742dfc BELONGS ya.make License text: - 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . + href="LICENSE-BOOST">BOOST license</a>. Scancode info: Original SPDX id: BSL-1.0 - Score : 99.00 + Score : 95.00 Match type : REFERENCE Links : http://www.boost.org/LICENSE_1_0.txt, http://www.boost.org/users/license.html, https://spdx.org/licenses/BSL-1.0 Files with this license: - README.md [463:463] - -KEEP BSL-1.0 9485675221ae35c9c070b4d380de8e99 -BELONGS ya.make - License text: - 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . + README.md [514:514] Scancode info: Original SPDX id: BSL-1.0 - Score : 95.00 + Score : 99.00 Match type : REFERENCE Links : http://www.boost.org/LICENSE_1_0.txt, http://www.boost.org/users/license.html, https://spdx.org/licenses/BSL-1.0 Files with this license: - README.md [463:463] + README.md [514:514] -KEEP Apache-2.0 AND MIT ac8d921d2bfa0e3a507421ec1e7c3852 +KEEP Apache-2.0 c48d93dbb5419f7a8844879928a2fda7 BELONGS ya.make - Note: matched license text is too long. Read it in the source files. + License text: + was originally published under the Apache 2.0 license. Scancode info: Original SPDX id: Apache-2.0 - Score : 49.30 + Score : 100.00 Match type : NOTICE Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0 Files with this license: - README.md [457:471] - Scancode info: - Original SPDX id: MIT - Score : 49.30 - Match type : NOTICE - Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT - Files with this license: - README.md [457:471] + README.md [507:507] -KEEP MIT cf519141cd6049a5930eb400ab733edc +KEEP Apache-2.0 OR MIT OR BSL-1.0 dbfbb7aa50e4925e728f16d4a8adf7d9 BELONGS ya.make License text: - 2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . + Licensed under either of <a href="LICENSE-APACHE">Apache License, Version Scancode info: - Original SPDX id: MIT - Score : 100.00 + Original SPDX id: LicenseRef-scancode-unknown-license-reference + Score : 11.00 + Match type : INTRO + Links : https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/unknown-license-reference.LICENSE + Files with this license: + README.md [512:512] + Scancode info: + Original SPDX id: Apache-2.0 + Score : 90.00 Match type : TAG - Links : http://opensource.org/licenses/mit-license.php, https://spdx.org/licenses/MIT + Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0 Files with this license: - README.md [463:463] + README.md [512:512] KEEP Apache-2.0 fb21a7d67961597593aefff800484f8d BELONGS ya.make diff --git a/contrib/restricted/fast_float/.yandex_meta/licenses.list.txt b/contrib/restricted/fast_float/.yandex_meta/licenses.list.txt index 24077dbb54..f59f716d84 100644 --- a/contrib/restricted/fast_float/.yandex_meta/licenses.list.txt +++ b/contrib/restricted/fast_float/.yandex_meta/licenses.list.txt @@ -192,37 +192,32 @@ ====================Apache-2.0==================== Licensed under either of <a href="LICENSE-APACHE">Apache License, Version +2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a ====================Apache-2.0==================== -Licensed under either of <a href="LICENSE-APACHE">Apache License, Version -2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . - - -====================Apache-2.0==================== -under the Apache 2.0 license. +was originally published under the Apache 2.0 license. ====================Apache-2.0 AND MIT==================== -under the Apache 2.0 license. +was originally published under the Apache 2.0 license. ## License <sup> Licensed under either of <a href="LICENSE-APACHE">Apache License, Version -2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . +2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a +href="LICENSE-BOOST">BOOST license</a>. </sup> -<br> - <sub> Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this repository by you, as defined in the Apache-2.0 license, shall be triple licensed as above, without any additional terms or conditions. -====================BSL-1.0==================== -2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . +====================Apache-2.0 OR MIT OR BSL-1.0==================== +Licensed under either of <a href="LICENSE-APACHE">Apache License, Version ====================BSL-1.0==================== @@ -250,6 +245,10 @@ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +====================BSL-1.0 AND BSL-1.0==================== +href="LICENSE-BOOST">BOOST license</a>. + + ====================COPYRIGHT==================== Copyright 2021 The fast_float authors @@ -264,7 +263,7 @@ João Paulo Magalhaes ====================MIT==================== -2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . +2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a ====================MIT==================== diff --git a/contrib/restricted/fast_float/.yandex_meta/override.nix b/contrib/restricted/fast_float/.yandex_meta/override.nix index c850f53c32..c919ea16d6 100644 --- a/contrib/restricted/fast_float/.yandex_meta/override.nix +++ b/contrib/restricted/fast_float/.yandex_meta/override.nix @@ -1,11 +1,11 @@ self: super: with self; rec { name = "fast_float"; - version = "6.1.6"; + version = "7.0.0"; src = fetchFromGitHub { owner = "fastfloat"; repo = "fast_float"; rev = "v${version}"; - hash = "sha256-MEJMPQZZZhOFiKlPAKIi0zVzaJBvjAlbSyg3wLOQ1fg="; + hash = "sha256-CG5je117WYyemTe5PTqznDP0bvY5TeXn8Vu1Xh5yUzQ="; }; } diff --git a/contrib/restricted/fast_float/CONTRIBUTORS b/contrib/restricted/fast_float/CONTRIBUTORS index da1e5d6809..4b705554c0 100644 --- a/contrib/restricted/fast_float/CONTRIBUTORS +++ b/contrib/restricted/fast_float/CONTRIBUTORS @@ -8,3 +8,4 @@ Lénárd Szolnoki Jan Pharago Maya Warrier Taha Khokhar +Anders Dalvander diff --git a/contrib/restricted/fast_float/README.md b/contrib/restricted/fast_float/README.md index dfbb68d1af..bf8c3e3e59 100644 --- a/contrib/restricted/fast_float/README.md +++ b/contrib/restricted/fast_float/README.md @@ -1,13 +1,19 @@ ## fast_float number parsing library: 4x faster than strtod + [](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:fast_float) [](https://github.com/fastfloat/fast_float/actions/workflows/ubuntu22.yml) -The fast_float library provides fast header-only implementations for the C++ from_chars -functions for `float` and `double` types as well as integer types. These functions convert ASCII strings representing decimal values (e.g., `1.3e10`) into binary types. We provide exact rounding (including -round to even). In our experience, these `fast_float` functions many times faster than comparable number-parsing functions from existing C++ standard libraries. +The fast_float library provides fast header-only implementations for the C++ +from_chars functions for `float` and `double` types as well as integer types. +These functions convert ASCII strings representing decimal values (e.g., +`1.3e10`) into binary types. We provide exact rounding (including round to +even). In our experience, these `fast_float` functions many times faster than +comparable number-parsing functions from existing C++ standard libraries. -Specifically, `fast_float` provides the following two functions to parse floating-point numbers with a C++17-like syntax (the library itself only requires C++11): +Specifically, `fast_float` provides the following two functions to parse +floating-point numbers with a C++17-like syntax (the library itself only +requires C++11): ```C++ from_chars_result from_chars(const char* first, const char* last, float& value, ...); @@ -16,105 +22,126 @@ from_chars_result from_chars(const char* first, const char* last, double& value, You can also parse integer types: - - +```C++ +from_chars_result from_chars(const char* first, const char* last, int& value, ...); +from_chars_result from_chars(const char* first, const char* last, unsigned& value, ...); +``` The return type (`from_chars_result`) is defined as the struct: + ```C++ struct from_chars_result { - const char* ptr; - std::errc ec; + const char* ptr; + std::errc ec; }; ``` -It parses the character sequence [first,last) for a number. It parses floating-point numbers expecting -a locale-independent format equivalent to the C++17 from_chars function. -The resulting floating-point value is the closest floating-point values (using either float or double), -using the "round to even" convention for values that would otherwise fall right in-between two values. -That is, we provide exact parsing according to the IEEE standard. +It parses the character sequence `[first, last)` for a number. It parses +floating-point numbers expecting a locale-independent format equivalent to the +C++17 from_chars function. The resulting floating-point value is the closest +floating-point values (using either `float` or `double`), using the "round to +even" convention for values that would otherwise fall right in-between two +values. That is, we provide exact parsing according to the IEEE standard. +Given a successful parse, the pointer (`ptr`) in the returned value is set to +point right after the parsed number, and the `value` referenced is set to the +parsed value. In case of error, the returned `ec` contains a representative +error, otherwise the default (`std::errc()`) value is stored. -Given a successful parse, the pointer (`ptr`) in the returned value is set to point right after the -parsed number, and the `value` referenced is set to the parsed value. In case of error, the returned -`ec` contains a representative error, otherwise the default (`std::errc()`) value is stored. - -The implementation does not throw and does not allocate memory (e.g., with `new` or `malloc`). +The implementation does not throw and does not allocate memory (e.g., with `new` +or `malloc`). It will parse infinity and nan values. Example: -``` C++ +```C++ #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::string input = "3.1416 xyz "; - double result; - auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result); - if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } - std::cout << "parsed the number " << result << std::endl; - return EXIT_SUCCESS; + const std::string input = "3.1416 xyz "; + double result; + auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result); + if (answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } + std::cout << "parsed the number " << result << std::endl; + return EXIT_SUCCESS; } ``` You can parse delimited numbers: + ```C++ - const std::string input = "234532.3426362,7869234.9823,324562.645"; + const std::string input = "234532.3426362,7869234.9823,324562.645"; double result; - auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result); - if(answer.ec != std::errc()) { + auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result); + if (answer.ec != std::errc()) { // check error } // we have result == 234532.3426362. - if(answer.ptr[0] != ',') { + if (answer.ptr[0] != ',') { // unexpected delimiter } - answer = fast_float::from_chars(answer.ptr + 1, input.data()+input.size(), result); - if(answer.ec != std::errc()) { + answer = fast_float::from_chars(answer.ptr + 1, input.data() + input.size(), result); + if (answer.ec != std::errc()) { // check error } // we have result == 7869234.9823. - if(answer.ptr[0] != ',') { + if (answer.ptr[0] != ',') { // unexpected delimiter } - answer = fast_float::from_chars(answer.ptr + 1, input.data()+input.size(), result); - if(answer.ec != std::errc()) { + answer = fast_float::from_chars(answer.ptr + 1, input.data() + input.size(), result); + if (answer.ec != std::errc()) { // check error } // we have result == 324562.645. ``` - - -Like the C++17 standard, the `fast_float::from_chars` functions take an optional last argument of -the type `fast_float::chars_format`. It is a bitset value: we check whether -`fmt & fast_float::chars_format::fixed` and `fmt & fast_float::chars_format::scientific` are set -to determine whether we allow the fixed point and scientific notation respectively. -The default is `fast_float::chars_format::general` which allows both `fixed` and `scientific`. - -The library seeks to follow the C++17 (see [20.19.3](http://eel.is/c++draft/charconv.from.chars).(7.1)) specification. -* The `from_chars` function does not skip leading white-space characters. -* [A leading `+` sign](https://en.cppreference.com/w/cpp/utility/from_chars) is forbidden. -* It is generally impossible to represent a decimal value exactly as binary floating-point number (`float` and `double` types). We seek the nearest value. We round to an even mantissa when we are in-between two binary floating-point numbers. +Like the C++17 standard, the `fast_float::from_chars` functions take an optional +last argument of the type `fast_float::chars_format`. It is a bitset value: we +check whether `fmt & fast_float::chars_format::fixed` and `fmt & +fast_float::chars_format::scientific` are set to determine whether we allow the +fixed point and scientific notation respectively. The default is +`fast_float::chars_format::general` which allows both `fixed` and `scientific`. + +The library seeks to follow the C++17 (see +[28.2.3.(6.1)](https://eel.is/c++draft/charconv.from.chars#6.1)) specification. + +* The `from_chars` function does not skip leading white-space characters (unless + `fast_float::chars_format::chars_format` is set). +* [A leading `+` sign](https://en.cppreference.com/w/cpp/utility/from_chars) is + forbidden (unless `fast_float::chars_format::skip_white_space` is set). +* It is generally impossible to represent a decimal value exactly as binary + floating-point number (`float` and `double` types). We seek the nearest value. + We round to an even mantissa when we are in-between two binary floating-point + numbers. Furthermore, we have the following restrictions: -* We only support `float` and `double` types at this time. -* We only support the decimal format: we do not support hexadecimal strings. -* For values that are either very large or very small (e.g., `1e9999`), we represent it using the infinity or negative infinity value and the returned `ec` is set to `std::errc::result_out_of_range`. -We support Visual Studio, macOS, Linux, freeBSD. We support big and little endian. We support 32-bit and 64-bit systems. +* We support `float` and `double`, but not `long double`. We also support + fixed-width floating-point types such as `std::float32_t` and + `std::float64_t`. +* We only support the decimal format: we do not support hexadecimal strings. +* For values that are either very large or very small (e.g., `1e9999`), we + represent it using the infinity or negative infinity value and the returned + `ec` is set to `std::errc::result_out_of_range`. -We assume that the rounding mode is set to nearest (`std::fegetround() == FE_TONEAREST`). +We support Visual Studio, macOS, Linux, freeBSD. We support big and little +endian. We support 32-bit and 64-bit systems. +We assume that the rounding mode is set to nearest (`std::fegetround() == +FE_TONEAREST`). ## Integer types -You can also parse integer types using different bases (e.g., 2, 10, 16). The following code will -print the number 22250738585072012 three times: - +You can also parse integer types using different bases (e.g., 2, 10, 16). The +following code will print the number 22250738585072012 three times: ```C++ +#include "fast_float/fast_float.h" +#include <iostream> + +int main() { uint64_t i; const char str[] = "22250738585072012"; auto answer = fast_float::from_chars(str, str + strlen(str), i); @@ -133,7 +160,6 @@ print the number 22250738585072012 three times: } std::cout << "parsed the number "<< i << std::endl; - const char hexstr[] = "4f0cedc95a718c"; answer = fast_float::from_chars(hexstr, hexstr + strlen(hexstr), i, 16); @@ -142,22 +168,26 @@ print the number 22250738585072012 three times: return EXIT_FAILURE; } std::cout << "parsed the number "<< i << std::endl; + return EXIT_SUCCESS; +} ``` ## Behavior of result_out_of_range -When parsing floating-point values, the numbers can sometimes be too small (e.g., `1e-1000`) or -too large (e.g., `1e1000`). The C language established the precedent that these small values are out of range. -In such cases, it is customary to parse small values to zero and large -values to infinity. That is the behaviour of the C language (e.g., `stdtod`). That is the behaviour followed by the fast_float library. - - +When parsing floating-point values, the numbers can sometimes be too small +(e.g., `1e-1000`) or too large (e.g., `1e1000`). The C language established the +precedent that these small values are out of range. In such cases, it is +customary to parse small values to zero and large values to infinity. That is +the behaviour of the C language (e.g., `stdtod`). That is the behaviour followed +by the fast_float library. Specifically, we follow Jonathan Wakely's interpretation of the standard: -> In any case, the resulting value is one of at most two floating-point values closest to the value of the string matching the pattern. +> In any case, the resulting value is one of at most two floating-point values +> closest to the value of the string matching the pattern. -It is also the approach taken by the [Microsoft C++ library](https://github.com/microsoft/STL/blob/62205ab155d093e71dd9588a78f02c5396c3c14b/tests/std/tests/P0067R5_charconv/test.cpp#L943-L946). +It is also the approach taken by the [Microsoft C++ +library](https://github.com/microsoft/STL/blob/62205ab155d093e71dd9588a78f02c5396c3c14b/tests/std/tests/P0067R5_charconv/test.cpp#L943-L946). Hence, we have the following examples: @@ -170,7 +200,6 @@ Hence, we have the following examples: // result == 0 ``` - ```cpp double result = -1; std::string str = "3e1000"; @@ -180,26 +209,26 @@ Hence, we have the following examples: // result == std::numeric_limits<double>::infinity() ``` -Users who wish for the value to be left unmodified given `std::errc::result_out_of_range` may do so by adding two lines of code: +Users who wish for the value to be left unmodified given +`std::errc::result_out_of_range` may do so by adding two lines of code: ```cpp double old_result = result; // make copy auto r = fast_float::from_chars(start, end, result); - if(r.ec == std::errc::result_out_of_range) { result = old_result; } + if (r.ec == std::errc::result_out_of_range) { result = old_result; } ``` - ## C++20: compile-time evaluation (constexpr) -In C++20, you may use `fast_float::from_chars` to parse strings -at compile-time, as in the following example: +In C++20, you may use `fast_float::from_chars` to parse strings at compile-time, +as in the following example: ```C++ // consteval forces compile-time evaluation of the function in C++20. consteval double parse(std::string_view input) { double result; - auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result); - if(answer.ec != std::errc()) { return -1.0; } + auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result); + if (answer.ec != std::errc()) { return -1.0; } return result; } @@ -212,108 +241,106 @@ constexpr double constexptest() { ## C++23: Fixed width floating-point types -The library also supports fixed-width floating-point types such as `std::float32_t` and `std::float64_t`. E.g., you can write: +The library also supports fixed-width floating-point types such as +`std::float32_t` and `std::float64_t`. E.g., you can write: ```C++ std::float32_t result; auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result); -`````` - +``` ## Non-ASCII Inputs -We also support UTF-16 and UTF-32 inputs, as well as ASCII/UTF-8, as in the following example: +We also support UTF-16 and UTF-32 inputs, as well as ASCII/UTF-8, as in the +following example: -``` C++ +```C++ #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::u16string input = u"3.1416 xyz "; - double result; - auto answer = fast_float::from_chars(input.data(), input.data()+input.size(), result); - if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } - std::cout << "parsed the number " << result << std::endl; - return EXIT_SUCCESS; + const std::u16string input = u"3.1416 xyz "; + double result; + auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result); + if (answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } + std::cout << "parsed the number " << result << std::endl; + return EXIT_SUCCESS; } ``` -## Advanced options: using commas as decimal separator, JSON and Fortran - +## Advanced options: using commas as decimal separator, JSON and Fortran The C++ standard stipulate that `from_chars` has to be locale-independent. In -particular, the decimal separator has to be the period (`.`). However, -some users still want to use the `fast_float` library with in a locale-dependent -manner. Using a separate function called `from_chars_advanced`, we allow the users -to pass a `parse_options` instance which contains a custom decimal separator (e.g., -the comma). You may use it as follows. +particular, the decimal separator has to be the period (`.`). However, some +users still want to use the `fast_float` library with in a locale-dependent +manner. Using a separate function called `from_chars_advanced`, we allow the +users to pass a `parse_options` instance which contains a custom decimal +separator (e.g., the comma). You may use it as follows. ```C++ #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::string input = "3,1416 xyz "; - double result; - fast_float::parse_options options{fast_float::chars_format::general, ','}; - auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options); - if((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } - std::cout << "parsed the number " << result << std::endl; - return EXIT_SUCCESS; + const std::string input = "3,1416 xyz "; + double result; + fast_float::parse_options options{fast_float::chars_format::general, ','}; + auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options); + if ((answer.ec != std::errc()) || ((result != 3.1416))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } + std::cout << "parsed the number " << result << std::endl; + return EXIT_SUCCESS; } ``` -You can also parse Fortran-like inputs: +### You can also parse Fortran-like inputs ```C++ #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::string input = "1d+4"; - double result; - fast_float::parse_options options{ fast_float::chars_format::fortran }; - auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options); - if((answer.ec != std::errc()) || ((result != 10000))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } - std::cout << "parsed the number " << result << std::endl; - return EXIT_SUCCESS; + const std::string input = "1d+4"; + double result; + fast_float::parse_options options{ fast_float::chars_format::fortran }; + auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options); + if ((answer.ec != std::errc()) || ((result != 10000))) { std::cerr << "parsing failure\n"; return EXIT_FAILURE; } + std::cout << "parsed the number " << result << std::endl; + return EXIT_SUCCESS; } ``` -You may also enforce the JSON format ([RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259#section-6)): - +### You may also enforce the JSON format ([RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259#section-6)) ```C++ #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::string input = "+.1"; // not valid - double result; - fast_float::parse_options options{ fast_float::chars_format::json }; - auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options); - if(answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; } - return EXIT_SUCCESS; + const std::string input = "+.1"; // not valid + double result; + fast_float::parse_options options{ fast_float::chars_format::json }; + auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options); + if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; } + return EXIT_SUCCESS; } ``` By default the JSON format does not allow `inf`: ```C++ - #include "fast_float/fast_float.h" #include <iostream> int main() { - const std::string input = "inf"; // not valid in JSON - double result; - fast_float::parse_options options{ fast_float::chars_format::json }; - auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options); - if(answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; } + const std::string input = "inf"; // not valid in JSON + double result; + fast_float::parse_options options{ fast_float::chars_format::json }; + auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options); + if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; } + return EXIT_SUCCESS; } ``` - You can allow it with a non-standard `json_or_infnan` variant: ```C++ @@ -321,54 +348,77 @@ You can allow it with a non-standard `json_or_infnan` variant: #include <iostream> int main() { - const std::string input = "inf"; // not valid in JSON but we allow it with json_or_infnan - double result; - fast_float::parse_options options{ fast_float::chars_format::json_or_infnan }; - auto answer = fast_float::from_chars_advanced(input.data(), input.data()+input.size(), result, options); - if(answer.ec != std::errc() || (!std::isinf(result))) { std::cerr << "should have parsed infinity\n"; return EXIT_FAILURE; } - return EXIT_SUCCESS; + const std::string input = "inf"; // not valid in JSON but we allow it with json_or_infnan + double result; + fast_float::parse_options options{ fast_float::chars_format::json_or_infnan }; + auto answer = fast_float::from_chars_advanced(input.data(), input.data() + input.size(), result, options); + if (answer.ec != std::errc() || (!std::isinf(result))) { std::cerr << "should have parsed infinity\n"; return EXIT_FAILURE; } + return EXIT_SUCCESS; } -`````` +``` ## Users and Related Work The fast_float library is part of: -- GCC (as of version 12): the `from_chars` function in GCC relies on fast_float. -- [Chromium](https://github.com/Chromium/Chromium), the engine behind Google Chrome and Microsoft Edge, -- [WebKit](https://github.com/WebKit/WebKit), the engine behind Safari (Apple's web browser) -- [DuckDB](https://duckdb.org) -- [Apache Arrow](https://github.com/apache/arrow/pull/8494) where it multiplied the number parsing speed by two or three times -- [Google Jsonnet](https://github.com/google/jsonnet) -- [ClickHouse](https://github.com/ClickHouse/ClickHouse) - - -The fastfloat algorithm is part of the [LLVM standard libraries](https://github.com/llvm/llvm-project/commit/87c016078ad72c46505461e4ff8bfa04819fe7ba). There is a [derived implementation part of AdaCore](https://github.com/AdaCore/VSS). - -The fast_float library provides a performance similar to that of the [fast_double_parser](https://github.com/lemire/fast_double_parser) library but using an updated algorithm reworked from the ground up, and while offering an API more in line with the expectations of C++ programmers. The fast_double_parser library is part of the [Microsoft LightGBM machine-learning framework](https://github.com/microsoft/LightGBM). +* GCC (as of version 12): the `from_chars` function in GCC relies on fast_float, +* [Chromium](https://github.com/Chromium/Chromium), the engine behind Google + Chrome, Microsoft Edge, and Opera, +* [WebKit](https://github.com/WebKit/WebKit), the engine behind Safari (Apple's + web browser), +* [DuckDB](https://duckdb.org), +* [Redis](https://github.com/redis/redis), +* [Apache Arrow](https://github.com/apache/arrow/pull/8494) where it multiplied + the number parsing speed by two or three times, +* [Google Jsonnet](https://github.com/google/jsonnet), +* [ClickHouse](https://github.com/ClickHouse/ClickHouse). + +The fastfloat algorithm is part of the [LLVM standard +libraries](https://github.com/llvm/llvm-project/commit/87c016078ad72c46505461e4ff8bfa04819fe7ba). +There is a [derived implementation part of +AdaCore](https://github.com/AdaCore/VSS). + +The fast_float library provides a performance similar to that of the +[fast_double_parser](https://github.com/lemire/fast_double_parser) library but +using an updated algorithm reworked from the ground up, and while offering an +API more in line with the expectations of C++ programmers. The +fast_double_parser library is part of the [Microsoft LightGBM machine-learning +framework](https://github.com/microsoft/LightGBM). ## References -- Daniel Lemire, [Number Parsing at a Gigabyte per Second](https://arxiv.org/abs/2101.11408), Software: Practice and Experience 51 (8), 2021. -- Noble Mushtak, Daniel Lemire, [Fast Number Parsing Without Fallback](https://arxiv.org/abs/2212.06644), Software: Practice and Experience 53 (7), 2023. +* Daniel Lemire, [Number Parsing at a Gigabyte per + Second](https://arxiv.org/abs/2101.11408), Software: Practice and Experience + 51 (8), 2021. +* Noble Mushtak, Daniel Lemire, [Fast Number Parsing Without + Fallback](https://arxiv.org/abs/2212.06644), Software: Practice and Experience + 53 (7), 2023. ## Other programming languages -- [There is an R binding](https://github.com/eddelbuettel/rcppfastfloat) called `rcppfastfloat`. -- [There is a Rust port of the fast_float library](https://github.com/aldanor/fast-float-rust/) called `fast-float-rust`. -- [There is a Java port of the fast_float library](https://github.com/wrandelshofer/FastDoubleParser) called `FastDoubleParser`. It used for important systems such as [Jackson](https://github.com/FasterXML/jackson-core). -- [There is a C# port of the fast_float library](https://github.com/CarlVerret/csFastFloat) called `csFastFloat`. - - - +* [There is an R binding](https://github.com/eddelbuettel/rcppfastfloat) called + `rcppfastfloat`. +* [There is a Rust port of the fast_float + library](https://github.com/aldanor/fast-float-rust/) called + `fast-float-rust`. +* [There is a Java port of the fast_float + library](https://github.com/wrandelshofer/FastDoubleParser) called + `FastDoubleParser`. It used for important systems such as + [Jackson](https://github.com/FasterXML/jackson-core). +* [There is a C# port of the fast_float + library](https://github.com/CarlVerret/csFastFloat) called `csFastFloat`. ## How fast is it? -It can parse random floating-point numbers at a speed of 1 GB/s on some systems. We find that it is often twice as fast as the best available competitor, and many times faster than many standard-library implementations. +It can parse random floating-point numbers at a speed of 1 GB/s on some systems. +We find that it is often twice as fast as the best available competitor, and +many times faster than many standard-library implementations. -<img src="http://lemire.me/blog/wp-content/uploads/2020/11/fastfloat_speed.png" width="400"> +<img src="https://lemire.me/blog/wp-content/uploads/2020/11/fastfloat_speed.png" +width="400" alt="fast_float is many times faster than many standard-library +implementations"> -``` +```bash $ ./build/benchmarks/benchmark # parsing random integers in the range [0,1) volume = 2.09808 MB @@ -379,92 +429,91 @@ abseil : 430.45 MB/s (+/- 2.2 %) 20.52 Mfl fastfloat : 1042.38 MB/s (+/- 9.9 %) 49.68 Mfloat/s ``` -See https://github.com/lemire/simple_fastfloat_benchmark for our benchmarking code. - +See <https://github.com/lemire/simple_fastfloat_benchmark> for our benchmarking +code. ## Video -[](http://www.youtube.com/watch?v=AVXgvlMeIm4)<br /> +[](https://www.youtube.com/watch?v=AVXgvlMeIm4) ## Using as a CMake dependency -This library is header-only by design. The CMake file provides the `fast_float` target -which is merely a pointer to the `include` directory. +This library is header-only by design. The CMake file provides the `fast_float` +target which is merely a pointer to the `include` directory. -If you drop the `fast_float` repository in your CMake project, you should be able to use -it in this manner: +If you drop the `fast_float` repository in your CMake project, you should be +able to use it in this manner: ```cmake add_subdirectory(fast_float) target_link_libraries(myprogram PUBLIC fast_float) ``` -Or you may want to retrieve the dependency automatically if you have a sufficiently recent version of CMake (3.11 or better at least): +Or you may want to retrieve the dependency automatically if you have a +sufficiently recent version of CMake (3.11 or better at least): ```cmake FetchContent_Declare( fast_float - GIT_REPOSITORY https://github.com/lemire/fast_float.git - GIT_TAG tags/v1.1.2 + GIT_REPOSITORY https://github.com/fastfloat/fast_float.git + GIT_TAG tags/v6.1.6 GIT_SHALLOW TRUE) FetchContent_MakeAvailable(fast_float) target_link_libraries(myprogram PUBLIC fast_float) - ``` -You should change the `GIT_TAG` line so that you recover the version you wish to use. +You should change the `GIT_TAG` line so that you recover the version you wish to +use. You may also use [CPM](https://github.com/cpm-cmake/CPM.cmake), like so: -``` +```cmake CPMAddPackage( - NAME fast_float - GITHUB_REPOSITORY "fastfloat/fast_float" - GIT_TAG v6.1.4) + NAME fast_float + GITHUB_REPOSITORY "fastfloat/fast_float" + GIT_TAG v6.1.6) ``` - ## Using as single header The script `script/amalgamate.py` may be used to generate a single header -version of the library if so desired. -Just run the script from the root directory of this repository. -You can customize the license type and output file if desired as described in -the command line help. +version of the library if so desired. Just run the script from the root +directory of this repository. You can customize the license type and output file +if desired as described in the command line help. You may directly download automatically generated single-header files: -https://github.com/fastfloat/fast_float/releases/download/v6.1.6/fast_float.h +<https://github.com/fastfloat/fast_float/releases/download/v7.0.0/fast_float.h> ## Packages -- The fast_float library is part of the [Conan package manager](https://conan.io/center/recipes/fast_float). -- It is part of the [brew package manager](https://formulae.brew.sh/formula/fast_float). -- Some Linux distribution like Fedora include fast_float (e.g., as `fast_float-devel`). - -## RFC 7159 - -If you need support for RFC 7159 (JSON standard), you may want to consider using the [fast_double_parser](https://github.com/lemire/fast_double_parser/) library instead. +* The fast_float library is part of the [Conan package + manager](https://conan.io/center/recipes/fast_float). +* It is part of the [brew package + manager](https://formulae.brew.sh/formula/fast_float). +* Some Linux distribution like Fedora include fast_float (e.g., as + `fast_float-devel`). ## Credit -Though this work is inspired by many different people, this work benefited especially from exchanges with -Michael Eisel, who motivated the original research with his key insights, and with Nigel Tao who provided -invaluable feedback. Rémy Oudompheng first implemented a fast path we use in the case of long digits. +Though this work is inspired by many different people, this work benefited +especially from exchanges with Michael Eisel, who motivated the original +research with his key insights, and with Nigel Tao who provided invaluable +feedback. Rémy Oudompheng first implemented a fast path we use in the case of +long digits. -The library includes code adapted from Google Wuffs (written by Nigel Tao) which was originally published -under the Apache 2.0 license. +The library includes code adapted from Google Wuffs (written by Nigel Tao) which +was originally published under the Apache 2.0 license. ## License <sup> Licensed under either of <a href="LICENSE-APACHE">Apache License, Version -2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a href="LICENSE-BOOST">BOOST license</a> . +2.0</a> or <a href="LICENSE-MIT">MIT license</a> or <a +href="LICENSE-BOOST">BOOST license</a>. </sup> -<br> - <sub> Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this repository by you, as defined in the Apache-2.0 license, diff --git a/contrib/restricted/fast_float/include/fast_float/ascii_number.h b/contrib/restricted/fast_float/include/fast_float/ascii_number.h index c027435e2a..f2484e8486 100644 --- a/contrib/restricted/fast_float/include/fast_float/ascii_number.h +++ b/contrib/restricted/fast_float/include/fast_float/ascii_number.h @@ -283,24 +283,24 @@ template <typename UC> fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC> parse_number_string(UC const *p, UC const *pend, parse_options_t<UC> options) noexcept { - chars_format const fmt = options.format; + chars_format const fmt = detail::adjust_for_feature_macros(options.format); UC const decimal_point = options.decimal_point; parsed_number_string_t<UC> answer; answer.valid = false; answer.too_many_digits = false; + // assume p < pend, so dereference without checks; answer.negative = (*p == UC('-')); -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*p == UC('-')) || (!(fmt & FASTFLOAT_JSONFMT) && *p == UC('+'))) { -#else - if (*p == UC('-')) { // C++17 20.19.3.(7.1) explicitly forbids '+' sign here -#endif + // C++17 20.19.3.(7.1) explicitly forbids '+' sign here + if ((*p == UC('-')) || + (uint64_t(fmt & chars_format::allow_leading_plus) && + !uint64_t(fmt & detail::basic_json_fmt) && *p == UC('+'))) { ++p; if (p == pend) { return report_parse_error<UC>( p, parse_error::missing_integer_or_dot_after_sign); } - if (fmt & FASTFLOAT_JSONFMT) { + if (uint64_t(fmt & detail::basic_json_fmt)) { if (!is_integer(*p)) { // a sign must be followed by an integer return report_parse_error<UC>(p, parse_error::missing_integer_after_sign); @@ -329,7 +329,7 @@ parse_number_string(UC const *p, UC const *pend, UC const *const end_of_integer_part = p; int64_t digit_count = int64_t(end_of_integer_part - start_digits); answer.integer = span<const UC>(start_digits, size_t(digit_count)); - if (fmt & FASTFLOAT_JSONFMT) { + if (uint64_t(fmt & detail::basic_json_fmt)) { // at least 1 digit in integer part, without leading zeros if (digit_count == 0) { return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part); @@ -358,7 +358,7 @@ parse_number_string(UC const *p, UC const *pend, answer.fraction = span<const UC>(before, size_t(p - before)); digit_count -= exponent; } - if (fmt & FASTFLOAT_JSONFMT) { + if (uint64_t(fmt & detail::basic_json_fmt)) { // at least 1 digit in fractional part if (has_decimal_point && exponent == 0) { return report_parse_error<UC>(p, @@ -369,9 +369,9 @@ parse_number_string(UC const *p, UC const *pend, return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa); } int64_t exp_number = 0; // explicit exponential part - if (((fmt & chars_format::scientific) && (p != pend) && + if ((uint64_t(fmt & chars_format::scientific) && (p != pend) && ((UC('e') == *p) || (UC('E') == *p))) || - ((fmt & FASTFLOAT_FORTRANFMT) && (p != pend) && + (uint64_t(fmt & detail::basic_fortran_fmt) && (p != pend) && ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) || (UC('D') == *p)))) { UC const *location_of_e = p; @@ -389,7 +389,7 @@ parse_number_string(UC const *p, UC const *pend, ++p; } if ((p == pend) || !is_integer(*p)) { - if (!(fmt & chars_format::fixed)) { + if (!uint64_t(fmt & chars_format::fixed)) { // The exponential part is invalid for scientific notation, so it must // be a trailing token for fixed notation. However, fixed notation is // disabled, so report a scientific notation error. @@ -412,7 +412,8 @@ parse_number_string(UC const *p, UC const *pend, } } else { // If it scientific and not fixed, we have to bail out. - if ((fmt & chars_format::scientific) && !(fmt & chars_format::fixed)) { + if (uint64_t(fmt & chars_format::scientific) && + !uint64_t(fmt & chars_format::fixed)) { return report_parse_error<UC>(p, parse_error::missing_exponential_part); } } @@ -471,22 +472,23 @@ parse_number_string(UC const *p, UC const *pend, template <typename T, typename UC> fastfloat_really_inline FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> -parse_int_string(UC const *p, UC const *pend, T &value, int base) { +parse_int_string(UC const *p, UC const *pend, T &value, + parse_options_t<UC> options) { + chars_format const fmt = detail::adjust_for_feature_macros(options.format); + int const base = options.base; + from_chars_result_t<UC> answer; UC const *const first = p; - bool negative = (*p == UC('-')); + bool const negative = (*p == UC('-')); if (!std::is_signed<T>::value && negative) { answer.ec = std::errc::invalid_argument; answer.ptr = first; return answer; } -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if ((*p == UC('-')) || (*p == UC('+'))) { -#else - if (*p == UC('-')) { -#endif + if ((*p == UC('-')) || + (uint64_t(fmt & chars_format::allow_leading_plus) && (*p == UC('+')))) { ++p; } diff --git a/contrib/restricted/fast_float/include/fast_float/fast_float.h b/contrib/restricted/fast_float/include/fast_float/fast_float.h index 42a3cdfaf4..a812682b52 100644 --- a/contrib/restricted/fast_float/include/fast_float/fast_float.h +++ b/contrib/restricted/fast_float/include/fast_float/fast_float.h @@ -38,11 +38,13 @@ from_chars(UC const *first, UC const *last, T &value, /** * Like from_chars, but accepts an `options` argument to govern number parsing. + * Both for floating-point types and integer types. */ template <typename T, typename UC = char> FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> from_chars_advanced(UC const *first, UC const *last, T &value, parse_options_t<UC> options) noexcept; + /** * from_chars for integer types. */ diff --git a/contrib/restricted/fast_float/include/fast_float/float_common.h b/contrib/restricted/fast_float/include/fast_float/float_common.h index 82ab7b0c6b..0753904b34 100644 --- a/contrib/restricted/fast_float/include/fast_float/float_common.h +++ b/contrib/restricted/fast_float/include/fast_float/float_common.h @@ -16,20 +16,26 @@ namespace fast_float { -#define FASTFLOAT_JSONFMT (1 << 5) -#define FASTFLOAT_FORTRANFMT (1 << 6) +enum class chars_format : uint64_t; -enum chars_format { +namespace detail { +constexpr chars_format basic_json_fmt = chars_format(1 << 5); +constexpr chars_format basic_fortran_fmt = chars_format(1 << 6); +} // namespace detail + +enum class chars_format : uint64_t { scientific = 1 << 0, fixed = 1 << 2, hex = 1 << 3, no_infnan = 1 << 4, // RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6 - json = FASTFLOAT_JSONFMT | fixed | scientific | no_infnan, + json = uint64_t(detail::basic_json_fmt) | fixed | scientific | no_infnan, // Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed. - json_or_infnan = FASTFLOAT_JSONFMT | fixed | scientific, - fortran = FASTFLOAT_FORTRANFMT | fixed | scientific, - general = fixed | scientific + json_or_infnan = uint64_t(detail::basic_json_fmt) | fixed | scientific, + fortran = uint64_t(detail::basic_fortran_fmt) | fixed | scientific, + general = fixed | scientific, + allow_leading_plus = 1 << 7, + skip_white_space = 1 << 8, }; template <typename UC> struct from_chars_result_t { @@ -40,13 +46,15 @@ using from_chars_result = from_chars_result_t<char>; template <typename UC> struct parse_options_t { constexpr explicit parse_options_t(chars_format fmt = chars_format::general, - UC dot = UC('.')) - : format(fmt), decimal_point(dot) {} + UC dot = UC('.'), int b = 10) + : format(fmt), decimal_point(dot), base(b) {} /** Which number formats are accepted */ chars_format format; /** The character used as decimal point */ UC decimal_point; + /** The base used for integers */ + int base; }; using parse_options = parse_options_t<char>; @@ -214,12 +222,15 @@ fastfloat_really_inline constexpr bool is_supported_char_type() { // Compares two ASCII strings in a case insensitive manner. template <typename UC> inline FASTFLOAT_CONSTEXPR14 bool -fastfloat_strncasecmp(UC const *input1, UC const *input2, size_t length) { - char running_diff{0}; +fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase, + size_t length) { for (size_t i = 0; i < length; ++i) { - running_diff |= (char(input1[i]) ^ char(input2[i])); + UC const actual = actual_mixedcase[i]; + if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) { + return false; + } } - return (running_diff == 0) || (running_diff == 32); + return true; } #ifndef FLT_EVAL_METHOD @@ -670,7 +681,6 @@ to_float(bool negative, adjusted_mantissa am, T &value) { #endif } -#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default template <typename = void> struct space_lut { static constexpr bool value[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -692,8 +702,9 @@ template <typename T> constexpr bool space_lut<T>::value[]; #endif -inline constexpr bool is_space(uint8_t c) { return space_lut<>::value[c]; } -#endif +template <typename UC> constexpr bool is_space(UC c) { + return c < 256 && space_lut<>::value[uint8_t(c)]; +} template <typename UC> static constexpr uint64_t int_cmp_zeros() { static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4), @@ -797,6 +808,58 @@ fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) { return int_luts<>::min_safe_u64[base - 2]; } +constexpr chars_format operator~(chars_format rhs) noexcept { + using int_type = std::underlying_type<chars_format>::type; + return static_cast<chars_format>(~static_cast<int_type>(rhs)); +} + +constexpr chars_format operator&(chars_format lhs, chars_format rhs) noexcept { + using int_type = std::underlying_type<chars_format>::type; + return static_cast<chars_format>(static_cast<int_type>(lhs) & + static_cast<int_type>(rhs)); +} + +constexpr chars_format operator|(chars_format lhs, chars_format rhs) noexcept { + using int_type = std::underlying_type<chars_format>::type; + return static_cast<chars_format>(static_cast<int_type>(lhs) | + static_cast<int_type>(rhs)); +} + +constexpr chars_format operator^(chars_format lhs, chars_format rhs) noexcept { + using int_type = std::underlying_type<chars_format>::type; + return static_cast<chars_format>(static_cast<int_type>(lhs) ^ + static_cast<int_type>(rhs)); +} + +fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format & +operator&=(chars_format &lhs, chars_format rhs) noexcept { + return lhs = (lhs & rhs); +} + +fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format & +operator|=(chars_format &lhs, chars_format rhs) noexcept { + return lhs = (lhs | rhs); +} + +fastfloat_really_inline FASTFLOAT_CONSTEXPR14 chars_format & +operator^=(chars_format &lhs, chars_format rhs) noexcept { + return lhs = (lhs ^ rhs); +} + +namespace detail { +// adjust for deprecated feature macros +constexpr chars_format adjust_for_feature_macros(chars_format fmt) { + return fmt +#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS + | chars_format::allow_leading_plus +#endif +#ifdef FASTFLOAT_SKIP_WHITE_SPACE + | chars_format::skip_white_space +#endif + ; +} +} // namespace detail + } // namespace fast_float #endif diff --git a/contrib/restricted/fast_float/include/fast_float/parse_number.h b/contrib/restricted/fast_float/include/fast_float/parse_number.h index 6d883fb96e..28a23ee414 100644 --- a/contrib/restricted/fast_float/include/fast_float/parse_number.h +++ b/contrib/restricted/fast_float/include/fast_float/parse_number.h @@ -19,24 +19,20 @@ namespace detail { * strings a null-free and fixed. **/ template <typename T, typename UC> -from_chars_result_t<UC> FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, - UC const *last, - T &value) noexcept { +from_chars_result_t<UC> + FASTFLOAT_CONSTEXPR14 parse_infnan(UC const *first, UC const *last, + T &value, chars_format fmt) noexcept { from_chars_result_t<UC> answer{}; answer.ptr = first; answer.ec = std::errc(); // be optimistic - bool minusSign = false; - if (*first == - UC('-')) { // assume first < last, so dereference without checks; - // C++17 20.19.3.(7.1) explicitly forbids '+' here - minusSign = true; + // assume first < last, so dereference without checks; + bool const minusSign = (*first == UC('-')); + // C++17 20.19.3.(7.1) explicitly forbids '+' sign here + if ((*first == UC('-')) || + (uint64_t(fmt & chars_format::allow_leading_plus) && + (*first == UC('+')))) { ++first; } -#ifdef FASTFLOAT_ALLOWS_LEADING_PLUS // disabled by default - if (*first == UC('+')) { - ++first; - } -#endif if (last - first >= 3) { if (fastfloat_strncasecmp(first, str_const_nan<UC>(), 3)) { answer.ptr = (first += 3); @@ -93,7 +89,7 @@ fastfloat_really_inline bool rounds_to_nearest() noexcept { // However, it is expected to be much faster than the fegetround() // function call. // - // The volatile keywoard prevents the compiler from computing the function + // The volatile keyword prevents the compiler from computing the function // at compile-time. // There might be other ways to prevent compile-time optimizations (e.g., // asm). The value does not need to be std::numeric_limits<float>::min(), any @@ -286,20 +282,22 @@ from_chars_advanced(parsed_number_string_t<UC> &pns, T &value) noexcept { template <typename T, typename UC> FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> -from_chars_advanced(UC const *first, UC const *last, T &value, - parse_options_t<UC> options) noexcept { +from_chars_float_advanced(UC const *first, UC const *last, T &value, + parse_options_t<UC> options) noexcept { static_assert(is_supported_float_type<T>(), "only some floating-point types are supported"); static_assert(is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported"); + chars_format const fmt = detail::adjust_for_feature_macros(options.format); + from_chars_result_t<UC> answer; -#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default - while ((first != last) && fast_float::is_space(uint8_t(*first))) { - first++; + if (uint64_t(fmt & chars_format::skip_white_space)) { + while ((first != last) && fast_float::is_space(*first)) { + first++; + } } -#endif if (first == last) { answer.ec = std::errc::invalid_argument; answer.ptr = first; @@ -308,12 +306,12 @@ from_chars_advanced(UC const *first, UC const *last, T &value, parsed_number_string_t<UC> pns = parse_number_string<UC>(first, last, options); if (!pns.valid) { - if (options.format & chars_format::no_infnan) { + if (uint64_t(fmt & chars_format::no_infnan)) { answer.ec = std::errc::invalid_argument; answer.ptr = first; return answer; } else { - return detail::parse_infnan(first, last, value); + return detail::parse_infnan(first, last, value, fmt); } } @@ -324,21 +322,67 @@ from_chars_advanced(UC const *first, UC const *last, T &value, template <typename T, typename UC, typename> FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> from_chars(UC const *first, UC const *last, T &value, int base) noexcept { + + static_assert(std::is_integral<T>::value, "only integer types are supported"); + static_assert(is_supported_char_type<UC>(), + "only char, wchar_t, char16_t and char32_t are supported"); + + parse_options_t<UC> options; + options.base = base; + return from_chars_advanced(first, last, value, options); +} + +template <typename T, typename UC> +FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> +from_chars_int_advanced(UC const *first, UC const *last, T &value, + parse_options_t<UC> options) noexcept { + + static_assert(std::is_integral<T>::value, "only integer types are supported"); static_assert(is_supported_char_type<UC>(), "only char, wchar_t, char16_t and char32_t are supported"); + chars_format const fmt = detail::adjust_for_feature_macros(options.format); + int const base = options.base; + from_chars_result_t<UC> answer; -#ifdef FASTFLOAT_SKIP_WHITE_SPACE // disabled by default - while ((first != last) && fast_float::is_space(uint8_t(*first))) { - first++; + if (uint64_t(fmt & chars_format::skip_white_space)) { + while ((first != last) && fast_float::is_space(*first)) { + first++; + } } -#endif if (first == last || base < 2 || base > 36) { answer.ec = std::errc::invalid_argument; answer.ptr = first; return answer; } - return parse_int_string(first, last, value, base); + + return parse_int_string(first, last, value, options); +} + +template <bool> struct from_chars_advanced_caller { + template <typename T, typename UC> + FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC> + call(UC const *first, UC const *last, T &value, + parse_options_t<UC> options) noexcept { + return from_chars_float_advanced(first, last, value, options); + } +}; + +template <> struct from_chars_advanced_caller<false> { + template <typename T, typename UC> + FASTFLOAT_CONSTEXPR20 static from_chars_result_t<UC> + call(UC const *first, UC const *last, T &value, + parse_options_t<UC> options) noexcept { + return from_chars_int_advanced(first, last, value, options); + } +}; + +template <typename T, typename UC> +FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC> +from_chars_advanced(UC const *first, UC const *last, T &value, + parse_options_t<UC> options) noexcept { + return from_chars_advanced_caller<is_supported_float_type<T>()>::call( + first, last, value, options); } } // namespace fast_float diff --git a/contrib/restricted/fast_float/ya.make b/contrib/restricted/fast_float/ya.make index 3b3c6fa697..32da568f8b 100644 --- a/contrib/restricted/fast_float/ya.make +++ b/contrib/restricted/fast_float/ya.make @@ -3,6 +3,7 @@ LIBRARY() LICENSE( + "(Apache-2.0 OR MIT OR BSL-1.0)" AND Apache-2.0 AND BSL-1.0 AND MIT @@ -10,9 +11,9 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(6.1.6) +VERSION(7.0.0) -ORIGINAL_SOURCE(https://github.com/fastfloat/fast_float/archive/v6.1.6.tar.gz) +ORIGINAL_SOURCE(https://github.com/fastfloat/fast_float/archive/v7.0.0.tar.gz) NO_COMPILER_WARNINGS() |