Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package fast_float for openSUSE:Factory checked in at 2026-11-24 12:22:42 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/fast_float (Old) and /work/SRC/openSUSE:Factory/.fast_float.new.1340718 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "fast_float" Tue Nov 24 12:22:42 2026 rev:16 rq:1399718 version:8.4.0 Changes: -------- --- /work/SRC/openSUSE:Factory/fast_float/fast_float.changes 2026-11-03 17:54:05.072606423 +0100 +++ /work/SRC/openSUSE:Factory/.fast_float.new.1340718/fast_float.changes 2026-11-24 12:23:10.274169521 +0100 @@ -1,0 +2,9 @@ +Sun Nov 22 08:17:21 UTC 2026 - Jan Engelhardt <[email protected]> + +- Update to release 8.4.0 + * Add FASTFLOAT_ROUNDS_TO_NEAREST to skip the rounding-mode + check. + * Avoid zero-filling bigint buffers in the slow path + (C++26 [[indeterminate]]). + +------------------------------------------------------------------- Old: ---- v8.3.3.tar.gz New: ---- v8.4.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ fast_float.spec ++++++ --- /var/tmp/diff_new_pack.rFHnou/_old 2026-11-24 12:23:12.036244179 +0100 +++ /var/tmp/diff_new_pack.rFHnou/_new 2026-11-24 12:23:12.038244264 +0100 @@ -17,7 +17,7 @@ Name: fast_float -Version: 8.3.3 +Version: 8.4.0 Release: 0 Summary: Re-implementation of std::from_chars for parsing strings into numbers License: Apache-2.0 OR BSL-1.0 OR MIT ++++++ _scmsync.obsinfo ++++++ --- /var/tmp/diff_new_pack.rFHnou/_old 2026-11-24 12:23:12.106247145 +0100 +++ /var/tmp/diff_new_pack.rFHnou/_new 2026-11-24 12:23:12.115247526 +0100 @@ -1,5 +1,5 @@ -mtime: 1793614918 -commit: beac1185734ccb28d1839c2a85e5db31d9621aa6064bb3667a11c13ba3e07693 +mtime: 1795335475 +commit: 2aefbd6856e519192b40b88a878e4c8f1e4edf4ea88102507ccac1e8c8e6b412 url: https://src.opensuse.org/jengelh/fast_float revision: master ++++++ build.specials.obscpio ++++++ ++++++ build.specials.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.gitignore new/.gitignore --- old/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/.gitignore 2026-11-22 09:17:55.000000000 +0100 @@ -0,0 +1 @@ +.osc ++++++ v8.3.3.tar.gz -> v8.4.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/.github/workflows/alpine.yml new/fast_float-8.4.0/.github/workflows/alpine.yml --- old/fast_float-8.3.3/.github/workflows/alpine.yml 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/.github/workflows/alpine.yml 2026-11-22 03:27:55.000000000 +0100 @@ -6,7 +6,9 @@ jobs: build: name: Build on Alpine ${{ matrix.arch }} - runs-on: ubuntu-latest + # ubuntu-latest (26.04) ships a sudo that ignores -E, so setup-alpine v1 + # loses its INPUT_* variables ("INPUT_APK_TOOLS_URL: unbound variable"). + runs-on: ubuntu-24.04 strategy: matrix: arch: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/CMakeLists.txt new/fast_float-8.4.0/CMakeLists.txt --- old/fast_float-8.3.3/CMakeLists.txt 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/CMakeLists.txt 2026-11-22 03:27:55.000000000 +0100 @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.14) -project(fast_float VERSION 8.3.3 LANGUAGES CXX) +project(fast_float VERSION 8.4.0 LANGUAGES CXX) set(FASTFLOAT_CXX_STANDARD 11 CACHE STRING "the C++ standard to use for fastfloat") set(CMAKE_CXX_STANDARD ${FASTFLOAT_CXX_STANDARD}) option(FASTFLOAT_TEST "Enable tests" OFF) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/MODULE.bazel new/fast_float-8.4.0/MODULE.bazel --- old/fast_float-8.3.3/MODULE.bazel 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/MODULE.bazel 2026-11-22 03:27:55.000000000 +0100 @@ -2,7 +2,7 @@ module( name = "fast_float", - version = "8.3.3", + version = "8.4.0", compatibility_level = 8, ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/README.md new/fast_float-8.4.0/README.md --- old/fast_float-8.3.3/README.md 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/README.md 2026-11-22 03:27:55.000000000 +0100 @@ -155,8 +155,9 @@ 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`). +The results are rounded to the nearest floating-point value, whatever the +rounding mode of the thread (`std::fegetround()`). See +[Assuming the default rounding mode](#assuming-the-default-rounding-mode). ## Integer types @@ -485,6 +486,56 @@ signed and unsigned integer types up to 64 bits: `int64_t`, `uint64_t`, etc. +## Assuming the default rounding mode + +The C and C++ languages let a program change the floating-point rounding +mode of a thread with `std::fesetround` (e.g., `FE_UPWARD`). fast_float +returns the value rounded to the nearest floating-point number (ties to +even) whatever the current rounding mode. + +Most numbers that people write, such as `1234.56` or `-0.25`, are converted +with a single multiplication or division by an exact power of ten (Clinger's +fast path). That operation is correctly rounded only in the default mode +(`FE_TONEAREST`), so fast_float checks the rounding mode before it takes the +fast path, every time. The check is cheap (a load from a `volatile` variable, +two additions and a comparison), but when you parse short numbers in a tight +loop, it can be a noticeable fraction of the time, depending on your compiler +and processor. + +If your program never changes the rounding mode, you can skip the check by +defining the `FASTFLOAT_ROUNDS_TO_NEAREST` macro: + +```C++ +#define FASTFLOAT_ROUNDS_TO_NEAREST +#include "fast_float/fast_float.h" +``` + +It affects `from_chars`, `from_chars_advanced` and `integer_times_pow10`. + +Before you define it, consider the tradeoff: + +* **You make a promise.** With the macro, fast_float trusts that the rounding + mode is `FE_TONEAREST`. If some code in your process (yours, or a library + you call) sets another mode, the numbers that take the fast path are + rounded according to that mode, while the other numbers are still rounded + to the nearest value. The results are then not correctly rounded, and not + even consistent with one another. For example, with `FE_UPWARD`, `0.3` + becomes `0.30000000000000004` but `0.30000000000000000000001` becomes + `0.29999999999999999`: the larger input gives the smaller value. Nothing + crashes and nothing warns you. Without the macro, fast_float is correct in + every rounding mode. +* **It is only a speedup on short inputs.** Long numbers (more than about 15 + significant digits, or large exponents) never take the fast path, so they + gain nothing. +* **Define it the same way everywhere.** The macro changes inline functions, + so every translation unit that includes fast_float should see the same + definition. The simplest is to set it for the whole build + (`-DFASTFLOAT_ROUNDS_TO_NEAREST`, or + `target_compile_definitions(myapp PRIVATE FASTFLOAT_ROUNDS_TO_NEAREST)` in + CMake) rather than in a source file. + +If in doubt, leave the macro undefined: the default is always correct. + ## Users and Related Work The fast_float library is part of: @@ -587,7 +638,7 @@ FetchContent_Declare( fast_float GIT_REPOSITORY https://github.com/fastfloat/fast_float.git - GIT_TAG tags/v8.3.3 + GIT_TAG tags/v8.4.0 GIT_SHALLOW TRUE) FetchContent_MakeAvailable(fast_float) @@ -603,7 +654,7 @@ CPMAddPackage( NAME fast_float GITHUB_REPOSITORY "fastfloat/fast_float" - GIT_TAG v8.3.3) + GIT_TAG v8.4.0) ``` ## Using as single header @@ -615,7 +666,7 @@ You may directly download automatically generated single-header files: -<https://github.com/fastfloat/fast_float/releases/download/v8.3.3/fast_float.h> +<https://github.com/fastfloat/fast_float/releases/download/v8.4.0/fast_float.h> ## Benchmarking @@ -630,6 +681,10 @@ Importantly, by default, the benchmark is built in Release mode. +The lines marked `assume nearest` time the same code compiled with +`FASTFLOAT_ROUNDS_TO_NEAREST` (see [Assuming the default rounding +mode](#assuming-the-default-rounding-mode)). + The instructions are similar under Windows. Under Linux and macOS, it is recommended to run the benchmarks in a privileged manner to get access diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/benchmarks/CMakeLists.txt new/fast_float-8.4.0/benchmarks/CMakeLists.txt --- old/fast_float-8.3.3/benchmarks/CMakeLists.txt 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/benchmarks/CMakeLists.txt 2026-11-22 03:27:55.000000000 +0100 @@ -8,7 +8,7 @@ FetchContent_MakeAvailable(counters) -add_executable(realbenchmark benchmark.cpp) +add_executable(realbenchmark benchmark.cpp benchmark_rtn.cpp) target_link_libraries(realbenchmark PRIVATE counters::counters) add_executable(bench_ip bench_ip.cpp) add_executable(bench_uint16 bench_uint16.cpp) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/benchmarks/benchmark.cpp new/fast_float-8.4.0/benchmarks/benchmark.cpp --- old/fast_float-8.3.3/benchmarks/benchmark.cpp 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/benchmarks/benchmark.cpp 2026-11-22 03:27:55.000000000 +0100 @@ -50,6 +50,12 @@ return answer; } +// Defined in benchmark_rtn.cpp, with FASTFLOAT_ROUNDS_TO_NEAREST. +template <typename CharT> +double findmax_fastfloat64_rtn(std::vector<std::basic_string<CharT>> &s); +template <typename CharT> +double findmax_fastfloat32_rtn(std::vector<std::basic_string<CharT>> &s); + counters::event_collector collector{}; #ifdef USING_COUNTERS @@ -193,8 +199,12 @@ std::cout << "ASCII volume = " << volumeMB << " MB " << std::endl; pretty_print(volume, lines.size(), "fastfloat (64)", time_it_ns(lines, findmax_fastfloat64<char>, repeat)); + pretty_print(volume, lines.size(), "fastfloat (64, assume nearest)", + time_it_ns(lines, findmax_fastfloat64_rtn<char>, repeat)); pretty_print(volume, lines.size(), "fastfloat (32)", time_it_ns(lines, findmax_fastfloat32<char>, repeat)); + pretty_print(volume, lines.size(), "fastfloat (32, assume nearest)", + time_it_ns(lines, findmax_fastfloat32_rtn<char>, repeat)); std::vector<std::u16string> lines16 = widen(lines); volume = 2 * volume; @@ -202,8 +212,12 @@ std::cout << "UTF-16 volume = " << volumeMB << " MB " << std::endl; pretty_print(volume, lines.size(), "fastfloat (64)", time_it_ns(lines16, findmax_fastfloat64<char16_t>, repeat)); + pretty_print(volume, lines.size(), "fastfloat (64, assume nearest)", + time_it_ns(lines16, findmax_fastfloat64_rtn<char16_t>, repeat)); pretty_print(volume, lines.size(), "fastfloat (32)", time_it_ns(lines16, findmax_fastfloat32<char16_t>, repeat)); + pretty_print(volume, lines.size(), "fastfloat (32, assume nearest)", + time_it_ns(lines16, findmax_fastfloat32_rtn<char16_t>, repeat)); } void fileload(std::string filename) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/benchmarks/benchmark_rtn.cpp new/fast_float-8.4.0/benchmarks/benchmark_rtn.cpp --- old/fast_float-8.3.3/benchmarks/benchmark_rtn.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/fast_float-8.4.0/benchmarks/benchmark_rtn.cpp 2026-11-22 03:27:55.000000000 +0100 @@ -0,0 +1,49 @@ +// The same parsing loops as findmax_fastfloat64 and findmax_fastfloat32 in +// benchmark.cpp, but compiled with FASTFLOAT_ROUNDS_TO_NEAREST: fast_float +// assumes the default rounding mode and skips its check before the fast path. +// +// We rename the fast_float namespace in this file. Otherwise, the two +// configurations would define the same inline functions differently, and the +// linker could keep either one (an ODR violation). +#include <stdexcept> +#include <string> +#include <vector> + +#define FASTFLOAT_ROUNDS_TO_NEAREST +#define fast_float fast_float_rtn +#include "fast_float/fast_float.h" + +template <typename CharT> +double findmax_fastfloat64_rtn(std::vector<std::basic_string<CharT>> &s) { + double answer = 0; + double x = 0; + for (auto &st : s) { + auto [p, ec] = fast_float::from_chars(st.data(), st.data() + st.size(), x); + if (p == st.data()) { + throw std::runtime_error("bug in findmax_fastfloat_rtn"); + } + answer = answer > x ? answer : x; + } + return answer; +} + +template <typename CharT> +double findmax_fastfloat32_rtn(std::vector<std::basic_string<CharT>> &s) { + float answer = 0; + float x = 0; + for (auto &st : s) { + auto [p, ec] = fast_float::from_chars(st.data(), st.data() + st.size(), x); + if (p == st.data()) { + throw std::runtime_error("bug in findmax_fastfloat_rtn"); + } + answer = answer > x ? answer : x; + } + return answer; +} + +template double findmax_fastfloat64_rtn<char>(std::vector<std::string> &); +template double findmax_fastfloat32_rtn<char>(std::vector<std::string> &); +template double +findmax_fastfloat64_rtn<char16_t>(std::vector<std::u16string> &); +template double +findmax_fastfloat32_rtn<char16_t>(std::vector<std::u16string> &); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/include/fast_float/bigint.h new/fast_float-8.4.0/include/fast_float/bigint.h --- old/fast_float-8.3.3/include/fast_float/bigint.h 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/include/fast_float/bigint.h 2026-11-22 03:27:55.000000000 +0100 @@ -42,7 +42,10 @@ // we never need more than 150 limbs uint16_t length{0}; - stackvec() = default; + // user-provided, so that value-initialization (stackvec()) does not zero + // data: only the first length limbs are ever read. + FASTFLOAT_CONSTEXPR20 stackvec() noexcept {} + stackvec(stackvec const &) = delete; stackvec &operator=(stackvec const &) = delete; stackvec(stackvec &&) = delete; @@ -339,7 +342,7 @@ template <uint16_t size> FASTFLOAT_CONSTEXPR20 bool long_mul(stackvec<size> &x, limb_span y) noexcept { limb_span xs = limb_span(x.data, x.len()); - stackvec<size> z(xs); + FASTFLOAT_INDETERMINATE stackvec<size> z(xs); limb_span zs = limb_span(z.data, z.len()); if (y.len() != 0) { @@ -347,7 +350,7 @@ FASTFLOAT_TRY(small_mul(x, y0)); for (size_t index = 1; index < y.len(); index++) { limb yi = y[index]; - stackvec<size> zi; + FASTFLOAT_INDETERMINATE stackvec<size> zi; if (yi != 0) { // re-use the same buffer throughout zi.set_len(0); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/include/fast_float/digit_comparison.h new/fast_float-8.4.0/include/fast_float/digit_comparison.h --- old/fast_float-8.3.3/include/fast_float/digit_comparison.h 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/include/fast_float/digit_comparison.h 2026-11-22 03:27:55.000000000 +0100 @@ -375,7 +375,7 @@ T b; to_float(false, am_b, b); adjusted_mantissa theor = to_extended_halfway(b); - bigint theor_digits(theor.mantissa); + FASTFLOAT_INDETERMINATE bigint theor_digits(theor.mantissa); int32_t theor_exp = theor.power2; // scale real digits and theor digits to be same power. @@ -434,7 +434,7 @@ scientific_exponent(num.mantissa, static_cast<int32_t>(num.exponent)); size_t max_digits = binary_format<T>::max_digits(); size_t digits = 0; - bigint bigmant; + FASTFLOAT_INDETERMINATE bigint bigmant; parse_mantissa(bigmant, num, max_digits, digits); // can't underflow, since digits is at most max_digits. int32_t exponent = sci_exp + 1 - int32_t(digits); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/include/fast_float/float_common.h new/fast_float-8.4.0/include/fast_float/float_common.h --- old/fast_float-8.3.3/include/fast_float/float_common.h 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/include/fast_float/float_common.h 2026-11-22 03:27:55.000000000 +0100 @@ -17,8 +17,8 @@ #include "constexpr_feature_detect.h" #define FASTFLOAT_VERSION_MAJOR 8 -#define FASTFLOAT_VERSION_MINOR 3 -#define FASTFLOAT_VERSION_PATCH 3 +#define FASTFLOAT_VERSION_MINOR 4 +#define FASTFLOAT_VERSION_PATCH 0 #define FASTFLOAT_STRINGIZE_IMPL(x) #x #define FASTFLOAT_STRINGIZE(x) FASTFLOAT_STRINGIZE_IMPL(x) @@ -228,6 +228,23 @@ #define fastfloat_never_inline #endif +// C++26 (P2795R5) and -ftrivial-auto-var-init zero-fill local variables that +// have no initializer. FASTFLOAT_INDETERMINATE opts a local out of that. Use +// it only on buffers that the code writes before it reads them. +#if defined(__has_cpp_attribute) && __cplusplus > 202302L +#if __has_cpp_attribute(indeterminate) +#define FASTFLOAT_INDETERMINATE [[indeterminate]] +#endif +#endif +#if !defined(FASTFLOAT_INDETERMINATE) && defined(__has_attribute) +#if __has_attribute(uninitialized) +#define FASTFLOAT_INDETERMINATE __attribute__((uninitialized)) +#endif +#endif +#ifndef FASTFLOAT_INDETERMINATE +#define FASTFLOAT_INDETERMINATE +#endif + // fastfloat_really_inline under clang only, a no-op elsewhere. Clang declines // to inline the parser into its callers, so the parser instantiation with a // compile-time format (from_chars_fixed_format) must force the one thin diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/include/fast_float/parse_number.h new/fast_float-8.4.0/include/fast_float/parse_number.h --- old/fast_float-8.3.3/include/fast_float/parse_number.h 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/include/fast_float/parse_number.h 2026-11-22 03:27:55.000000000 +0100 @@ -74,12 +74,20 @@ * Returns true if the floating-pointing rounding mode is to 'nearest'. * It is the default on most system. This function is meant to be inexpensive. * Credit : @mwalcott3 + * + * If FASTFLOAT_ROUNDS_TO_NEAREST is defined, we trust the user that the + * rounding mode is always 'nearest' and we skip the check (see README). */ fastfloat_really_inline bool rounds_to_nearest() noexcept { // https://lemire.me/blog/2020/06/26/gcc-not-nearest/ #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) + // The arithmetic may be carried out with excess precision (e.g., x87): + // Clinger's fast path could then round twice. FASTFLOAT_ROUNDS_TO_NEAREST + // does not change this. return false; -#endif +#elif defined(FASTFLOAT_ROUNDS_TO_NEAREST) + return true; +#else // See // A fast function to check your floating-point rounding mode // https://lemire.me/blog/2022/11/16/a-fast-function-to-check-your-floating-point-rounding-mode/ @@ -133,6 +141,7 @@ #elif defined(__GNUC__) #pragma GCC diagnostic pop #endif +#endif // FASTFLOAT_ROUNDS_TO_NEAREST } } // namespace detail diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/tests/CMakeLists.txt new/fast_float-8.4.0/tests/CMakeLists.txt --- old/fast_float-8.3.3/tests/CMakeLists.txt 2026-10-31 14:45:33.000000000 +0100 +++ new/fast_float-8.4.0/tests/CMakeLists.txt 2026-11-22 03:27:55.000000000 +0100 @@ -67,6 +67,7 @@ fast_float_add_cpp_test(example_test) fast_float_add_cpp_test(example_comma_test) fast_float_add_cpp_test(example_integer_times_pow10) +fast_float_add_cpp_test(rounds_to_nearest_test) fast_float_add_cpp_test(basictest) option(FASTFLOAT_CONSTEXPR_TESTS "Require constexpr tests (build will fail if the compiler won't support it)" OFF) if (FASTFLOAT_CONSTEXPR_TESTS) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fast_float-8.3.3/tests/rounds_to_nearest_test.cpp new/fast_float-8.4.0/tests/rounds_to_nearest_test.cpp --- old/fast_float-8.3.3/tests/rounds_to_nearest_test.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/fast_float-8.4.0/tests/rounds_to_nearest_test.cpp 2026-11-22 03:27:55.000000000 +0100 @@ -0,0 +1,107 @@ +// Checks that defining FASTFLOAT_ROUNDS_TO_NEAREST does not change the results +// when the rounding mode is the default (round to nearest). +#define FASTFLOAT_ROUNDS_TO_NEAREST +#include "fast_float/fast_float.h" + +#include <cfloat> +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <random> + +namespace { + +bool check_double(char const *s) { + double const expected = std::strtod(s, nullptr); + double result = 0; + auto const answer = fast_float::from_chars(s, s + std::strlen(s), result); + if (answer.ec != std::errc() || + std::memcmp(&result, &expected, sizeof(double)) != 0) { + std::cerr << "mismatch on " << s << "\n"; + return false; + } + return true; +} + +bool check_float(char const *s) { + float const expected = std::strtof(s, nullptr); + float result = 0; + auto const answer = fast_float::from_chars(s, s + std::strlen(s), result); + if (answer.ec != std::errc() || + std::memcmp(&result, &expected, sizeof(float)) != 0) { + std::cerr << "mismatch on " << s << " (float)\n"; + return false; + } + return true; +} + +} // namespace + +int main() { +#if (FLT_EVAL_METHOD == 0) || (FLT_EVAL_METHOD == 1) + if (!fast_float::detail::rounds_to_nearest()) { + std::cerr << "FASTFLOAT_ROUNDS_TO_NEAREST is ignored\n"; + return EXIT_FAILURE; + } +#endif + char const *cases[] = {"0", + "-0", + "1", + "-1", + "0.1", + "-0.1", + "1e10", + "-1e10", + "1e-10", + "16777216", + "16777217", + "9007199254740992", + "9007199254740993", + "123456.789", + "-1234.56", + "1e23"}; + for (char const *s : cases) { + if (!check_double(s) || !check_float(s)) { + return EXIT_FAILURE; + } + } + char const *double_cases[] = {"1e22", "-1e22", "1e-22", + "2.2250738585072014e-308", + "1.7976931348623157e308"}; + for (char const *s : double_cases) { + if (!check_double(s)) { + return EXIT_FAILURE; + } + } + std::mt19937_64 gen(1234); + std::uniform_real_distribution<double> prices(-1e6, 1e6); + std::uniform_int_distribution<uint64_t> bits; + char buffer[64]; + for (size_t i = 0; i < 100000; i++) { + // short decimals: they take Clinger's fast path + std::snprintf(buffer, sizeof(buffer), "%.2f", prices(gen)); + if (!check_double(buffer) || !check_float(buffer)) { + return EXIT_FAILURE; + } + // arbitrary doubles: most take the other paths + uint64_t const word = bits(gen); + double d; + std::memcpy(&d, &word, sizeof(d)); + if (d != d || d - d != 0) { // NaN or infinity + continue; + } + std::snprintf(buffer, sizeof(buffer), "%.17g", d); + if (!check_double(buffer)) { + return EXIT_FAILURE; + } + } + if (fast_float::integer_times_pow10(uint64_t(123456), -2) != 1234.56 || + fast_float::integer_times_pow10(int64_t(-123456), -2) != -1234.56) { + std::cerr << "integer_times_pow10 mismatch\n"; + return EXIT_FAILURE; + } + std::cout << "ok\n"; + return EXIT_SUCCESS; +}
