diff --git a/benchmarks/benchmark.cpp b/benchmarks/benchmark.cpp index 0d045bd..3a9c965 100644 --- a/benchmarks/benchmark.cpp +++ b/benchmarks/benchmark.cpp @@ -1,5 +1,5 @@ -//#define FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN +// #define FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #if defined(__linux__) || (__APPLE__ && __aarch64__) #define USING_COUNTERS @@ -146,8 +146,8 @@ time_it_ns(std::vector> &lines, T const &function, return std::make_pair(min_value, average); } -void pretty_print(size_t volume, size_t number_of_floats, std::string const &name, - std::pair result) { +void pretty_print(size_t volume, size_t number_of_floats, + std::string const &name, std::pair result) { double volumeMB = volume / (1024. * 1024.); printf("%-40s: %8.2f MB/s (+/- %.1f %%) ", name.data(), volumeMB * 1000000000 / result.first, @@ -223,7 +223,8 @@ void fileload(std::string filename) { int main(int argc, char **argv) { #ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - std::cout << "# FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN is enabled" << std::endl; + std::cout << "# FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN is enabled" + << std::endl; #endif #ifdef USING_COUNTERS if (collector.has_events()) { diff --git a/benchmarks/event_counter.h b/benchmarks/event_counter.h index 24c21a8..ee37f08 100644 --- a/benchmarks/event_counter.h +++ b/benchmarks/event_counter.h @@ -37,7 +37,8 @@ struct event_count { event_count() : elapsed(0), event_counts{0, 0, 0, 0} {} event_count(const std::chrono::duration &_elapsed, - const std::array &_event_counts) + const std::array + &_event_counts) : elapsed(_elapsed), event_counts(_event_counts) {} event_count(const event_count &other) diff --git a/benchmarks/linux-perf-events.h b/benchmarks/linux-perf-events.h index 88460da..1076c6d 100644 --- a/benchmarks/linux-perf-events.h +++ b/benchmarks/linux-perf-events.h @@ -22,7 +22,8 @@ template class LinuxEvents { std::vector ids{}; public: - explicit LinuxEvents(std::array config_vec) : fd(0), working(true) { + explicit LinuxEvents(std::array config_vec) + : fd(0), working(true) { memset(&attribs, 0, sizeof(attribs)); attribs.type = TYPE; attribs.size = sizeof(attribs); diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index ec2b6b8..cef36b8 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -301,8 +301,9 @@ parse_number_string(UC const *p, UC const *pend, #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN answer.negative = (*p == UC('-')); // C++17 20.19.3.(7.1) explicitly forbids '+' sign here - if ((*p == UC('-')) || (uint8_t(options.format & chars_format::allow_leading_plus) && - !basic_json_fmt && *p == UC('+'))) { + if ((*p == UC('-')) || + (uint8_t(options.format & chars_format::allow_leading_plus) && + !basic_json_fmt && *p == UC('+'))) { ++p; if (p == pend) { return report_parse_error( @@ -316,8 +317,8 @@ parse_number_string(UC const *p, UC const *pend, } else { if (!is_integer(*p) && - (*p != - options.decimal_point)) { // a sign must be followed by an integer or the dot + (*p != options.decimal_point)) { // a sign must be followed by an + // integer or the dot return report_parse_error( p, parse_error::missing_integer_or_dot_after_sign); } @@ -331,13 +332,15 @@ parse_number_string(UC const *p, UC const *pend, while ((p != pend) && is_integer(*p)) { // a multiplication by 10 is cheaper than an arbitrary integer // multiplication - answer.mantissa = 10 * answer.mantissa + + answer.mantissa = + 10 * answer.mantissa + uint64_t(*p - UC('0')); // might overflow, we will handle the overflow later ++p; } UC const *const end_of_integer_part = p; - uint16_t digit_count = uint16_t(end_of_integer_part - start_digits); + uint16_t digit_count = + static_cast(end_of_integer_part - start_digits); answer.integer = span(start_digits, digit_count); #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { @@ -363,40 +366,42 @@ parse_number_string(UC const *p, UC const *pend, while ((p != pend) && is_integer(*p)) { uint8_t const digit = uint8_t(*p - UC('0')); - answer.mantissa = answer.mantissa * 10 + digit; // in rare cases, this will overflow, but that's ok + answer.mantissa = + answer.mantissa * 10 + + digit; // in rare cases, this will overflow, but that's ok ++p; } - fraction = uint16_t(before - p); - answer.fraction = span(before, uint16_t(p - before)); + fraction = static_cast(before - p); + answer.fraction = span(before, static_cast(p - before)); digit_count -= fraction; #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) { // at least 1 digit in fractional part if (has_decimal_point && fraction == 0) { - return report_parse_error(p, - parse_error::no_digits_in_fractional_part); + return report_parse_error( + p, parse_error::no_digits_in_fractional_part); } } #endif - } - else if (digit_count == 0) { // we must have encountered at least one integer! + } else if (digit_count == + 0) { // we must have encountered at least one integer! return report_parse_error(p, parse_error::no_digits_in_mantissa); } // We have now parsed the integer and the fraction part of the mantissa. - + // Now we can parse the exponent part. - if (p != pend && - (uint8_t(options.format & chars_format::scientific) && - (UC('e') == *p) || (UC('E') == *p)) + if ((p != pend) && (uint8_t(options.format & chars_format::scientific) && + (UC('e') == *p) || + (UC('E') == *p)) #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - || (uint8_t(options.format & detail::basic_fortran_fmt) && - ((UC('+') == *p) || (UC('-') == *p) || - (UC('d') == *p) || (UC('D') == *p))) + || (uint8_t(options.format & detail::basic_fortran_fmt) && + ((UC('+') == *p) || (UC('-') == *p) || (UC('d') == *p) || + (UC('D') == *p))) #endif ) { UC const *location_of_e = p; ++p; - + bool neg_exp = false; if (p != pend) { if (UC('-') == *p) { @@ -467,16 +472,19 @@ parse_number_string(UC const *p, UC const *pend, p = answer.integer.ptr; UC const *int_end = p + answer.integer.len(); uint64_t const minimal_nineteen_digit_integer{1000000000000000000}; - while ((answer.mantissa < minimal_nineteen_digit_integer) && (p != int_end)) { + while ((answer.mantissa < minimal_nineteen_digit_integer) && + (p != int_end)) { answer.mantissa = answer.mantissa * 10 + uint64_t(*p - UC('0')); ++p; } - if (answer.mantissa >= minimal_nineteen_digit_integer) { // We have a big integers + if (answer.mantissa >= + minimal_nineteen_digit_integer) { // We have a big integers answer.exponent += int16_t(end_of_integer_part - p); } else { // We have a value with a fractional component. p = answer.fraction.ptr; UC const *frac_end = p + answer.fraction.len(); - while ((answer.mantissa < minimal_nineteen_digit_integer) && (p != frac_end)) { + while ((answer.mantissa < minimal_nineteen_digit_integer) && + (p != frac_end)) { answer.mantissa = answer.mantissa * 10 + uint64_t(*p - UC('0')); ++p; } @@ -537,12 +545,11 @@ parse_int_string(UC const *p, UC const *pend, T &value, if (digit >= options.base) { break; } - i = uint64_t(options.base) * i + - digit; // might overflow, check this later + i = uint64_t(options.base) * i + digit; // might overflow, check this later p++; } - uint16_t const digit_count = uint16_t(p - start_digits); + uint16_t const digit_count = static_cast(p - start_digits); if (digit_count == 0) { if (has_leading_zeros) { diff --git a/include/fast_float/bigint.h b/include/fast_float/bigint.h index aa18c2f..86c8a2b 100644 --- a/include/fast_float/bigint.h +++ b/include/fast_float/bigint.h @@ -71,9 +71,7 @@ template struct stackvec { } // set the length, without bounds checking. - FASTFLOAT_CONSTEXPR14 void set_len(uint8_t len) noexcept { - length = len; - } + FASTFLOAT_CONSTEXPR14 void set_len(uint8_t len) noexcept { length = len; } constexpr uint8_t len() const noexcept { return length; } @@ -101,7 +99,7 @@ template struct stackvec { FASTFLOAT_CONSTEXPR20 void extend_unchecked(limb_span s) noexcept { limb *ptr = data + length; std::copy_n(s.ptr, s.len(), ptr); - set_len(len() + s.len()); + set_len(uint8_t(len() + s.len())); } // try to add items to the vector, returning if items were added @@ -304,7 +302,7 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec &x, limb_span y, // the effective x buffer is from `xstart..x.len()`, so exit early // if we can't get that current range. if (x.len() < start || y.len() > x.len() - start) { - FASTFLOAT_TRY(x.try_resize(y.len() + start, 0)); + FASTFLOAT_TRY(x.try_resize(uint8_t(y.len() + start), 0)); } bool carry = false; @@ -547,7 +545,7 @@ struct bigint : pow5_tables<> { limb *first = vec.data; limb *last = first + n; ::std::fill(first, last, 0); - vec.set_len(n + vec.len()); + vec.set_len(uint8_t(n + vec.len())); return true; } else { return true; @@ -584,8 +582,8 @@ struct bigint : pow5_tables<> { // get the number of bits in the bigint. FASTFLOAT_CONSTEXPR20 uint16_t bit_length() const noexcept { - uint16_t lz = ctlz(); - return uint16_t(limb_bits * vec.len()) - lz; + uint8_t lz = ctlz(); + return limb_bits * vec.len() - lz; } FASTFLOAT_CONSTEXPR20 bool mul(limb y) noexcept { return small_mul(vec, y); } diff --git a/include/fast_float/constexpr_feature_detect.h b/include/fast_float/constexpr_feature_detect.h index d4399b0..8d409df 100644 --- a/include/fast_float/constexpr_feature_detect.h +++ b/include/fast_float/constexpr_feature_detect.h @@ -58,7 +58,6 @@ #define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1 #endif - // For support attribute [[assume]] is declared in P1774 #if defined(__cpp_attrubute_assume) #define FASTFLOAT_ASSUME(expr) [[assume(expr)]] diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index 82a2953..d772ca1 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -262,7 +262,7 @@ parse_mantissa(bigint &result, const parsed_number_string_t &num) noexcept { // try to minimize the number of big integer and scalar multiplication. // therefore, try to parse 8 digits at a time, and multiply by the largest // scalar value (9 or 19 digits) for each step. - uint16_t const max_digits = uint16_t(binary_format::max_digits()); + uint16_t const max_digits = binary_format::max_digits(); uint16_t counter = 0; uint16_t digits = 0; limb value = 0; @@ -342,14 +342,13 @@ parse_mantissa(bigint &result, const parsed_number_string_t &num) noexcept { } template -inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa -positive_digit_comp(bigint &bigmant, adjusted_mantissa am, - int16_t const exponent) noexcept { +inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa positive_digit_comp( + bigint &bigmant, adjusted_mantissa am, int16_t const exponent) noexcept { FASTFLOAT_ASSERT(bigmant.pow10(exponent)); bool truncated; am.mantissa = bigmant.hi64(truncated); int16_t bias = binary_format::mantissa_explicit_bits() - - binary_format::minimum_exponent(); + binary_format::minimum_exponent(); am.power2 = bigmant.bit_length() - 64 + bias; round(am, [truncated](adjusted_mantissa &a, int16_t shift) { @@ -370,15 +369,15 @@ positive_digit_comp(bigint &bigmant, adjusted_mantissa am, // we then need to scale by `2^(f- e)`, and then the two significant digits // are of the same magnitude. template -inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa -negative_digit_comp(bigint &bigmant, adjusted_mantissa am, - int16_t const exponent) noexcept { +inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa negative_digit_comp( + bigint &bigmant, adjusted_mantissa am, int16_t const exponent) noexcept { bigint &real_digits = bigmant; int16_t const &real_exp = exponent; T b; { - // get the value of `b`, rounded down, and get a bigint representation of b+h + // get the value of `b`, rounded down, and get a bigint representation of + // b+h adjusted_mantissa am_b = am; // gcc7 bug: use a lambda to remove the noexcept qualifier bug with // -Wnoexcept-type. @@ -386,9 +385,9 @@ negative_digit_comp(bigint &bigmant, adjusted_mantissa am, [](adjusted_mantissa &a, int16_t shift) { round_down(a, shift); }); to_float( #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN - false, + false, #endif - am_b, b); + am_b, b); } adjusted_mantissa theor = to_extended_halfway(b); bigint theor_digits(theor.mantissa); @@ -396,7 +395,7 @@ negative_digit_comp(bigint &bigmant, adjusted_mantissa am, // scale real digits and theor digits to be same power. int16_t pow2_exp = theor_exp - real_exp; - uint16_t pow5_exp = uint16_t(-real_exp); + uint16_t pow5_exp = -real_exp; if (pow5_exp != 0) { FASTFLOAT_ASSERT(theor_digits.pow5(pow5_exp)); } @@ -447,7 +446,7 @@ inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa digit_comp( bigint bigmant; int16_t const sci_exp = scientific_exponent(num); - + uint16_t const digits = parse_mantissa(bigmant, num); // can't underflow, since digits is at most max_digits. int16_t const exponent = sci_exp + 1 - digits; diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 7de83f5..780f6d7 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -202,12 +202,18 @@ using parse_options = parse_options_t; #ifndef FASTFLOAT_ASSERT #define FASTFLOAT_ASSERT(x) \ - { ((void)(x)); FASTFLOAT_ASSUME(x); } + { \ + ((void)(x)); \ + FASTFLOAT_ASSUME(x); \ + } #endif #ifndef FASTFLOAT_DEBUG_ASSERT #define FASTFLOAT_DEBUG_ASSERT(x) \ - { ((void)(x)); FASTFLOAT_ASSUME(x); } + { \ + ((void)(x)); \ + FASTFLOAT_ASSUME(x); \ + } #endif // rust style `try!()` macro, or `?` operator @@ -295,7 +301,8 @@ template struct span { T const *ptr; uint16_t length; - constexpr span(T const *_ptr, uint16_t _length) : ptr(_ptr), length(_length) {} + constexpr span(T const *_ptr, uint16_t _length) + : ptr(_ptr), length(_length) {} constexpr span() : ptr(nullptr), length(0) {} @@ -451,23 +458,25 @@ template struct binary_format_lookup_tables; template struct binary_format : binary_format_lookup_tables { using equiv_uint = equiv_uint_t; + // TODO add type for bit shift operations and use it. + // TODO add type for exponent operations and use it. - static constexpr int mantissa_explicit_bits(); - static constexpr int minimum_exponent(); - static constexpr int infinite_power(); - static constexpr int sign_index(); - static constexpr int + static constexpr uint8_t mantissa_explicit_bits(); + static constexpr int16_t minimum_exponent(); + static constexpr int16_t infinite_power(); + static constexpr uint8_t sign_index(); + static constexpr int8_t min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST - static constexpr int max_exponent_fast_path(); - static constexpr int max_exponent_round_to_even(); - static constexpr int min_exponent_round_to_even(); - static constexpr uint64_t max_mantissa_fast_path(int64_t power); - static constexpr uint64_t + static constexpr int8_t max_exponent_fast_path(); + static constexpr int16_t max_exponent_round_to_even(); + static constexpr int16_t min_exponent_round_to_even(); + static constexpr equiv_uint max_mantissa_fast_path(int64_t power); + static constexpr equiv_uint max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST - static constexpr int largest_power_of_ten(); - static constexpr int smallest_power_of_ten(); + static constexpr int16_t largest_power_of_ten(); + static constexpr int16_t smallest_power_of_ten(); static constexpr T exact_power_of_ten(int64_t power); - static constexpr size_t max_digits(); + static constexpr uint16_t max_digits(); static constexpr equiv_uint exponent_mask(); static constexpr equiv_uint mantissa_mask(); static constexpr equiv_uint hidden_bit_mask(); @@ -531,7 +540,7 @@ template struct binary_format_lookup_tables { // Largest integer value v so that (5**index * v) <= 1<<24. // 0x1000000 == 1<<24 - static constexpr uint64_t max_mantissa[] = { + static constexpr uint32_t max_mantissa[] = { 0x1000000, 0x1000000 / 5, 0x1000000 / (5 * 5), @@ -557,7 +566,7 @@ constexpr uint64_t binary_format_lookup_tables::max_mantissa[]; #endif template <> -inline constexpr int binary_format::min_exponent_fast_path() { +inline constexpr int8_t binary_format::min_exponent_fast_path() { #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) return 0; #else @@ -566,7 +575,7 @@ inline constexpr int binary_format::min_exponent_fast_path() { } template <> -inline constexpr int binary_format::min_exponent_fast_path() { +inline constexpr int8_t binary_format::min_exponent_fast_path() { #if (FLT_EVAL_METHOD != 1) && (FLT_EVAL_METHOD != 0) return 0; #else @@ -575,70 +584,70 @@ inline constexpr int binary_format::min_exponent_fast_path() { } template <> -inline constexpr int binary_format::mantissa_explicit_bits() { +inline constexpr uint8_t binary_format::mantissa_explicit_bits() { return 52; } template <> -inline constexpr int binary_format::mantissa_explicit_bits() { +inline constexpr uint8_t binary_format::mantissa_explicit_bits() { return 23; } template <> -inline constexpr int binary_format::max_exponent_round_to_even() { +inline constexpr int16_t binary_format::max_exponent_round_to_even() { return 23; } template <> -inline constexpr int binary_format::max_exponent_round_to_even() { +inline constexpr int16_t binary_format::max_exponent_round_to_even() { return 10; } template <> -inline constexpr int binary_format::min_exponent_round_to_even() { +inline constexpr int16_t binary_format::min_exponent_round_to_even() { return -4; } template <> -inline constexpr int binary_format::min_exponent_round_to_even() { +inline constexpr int16_t binary_format::min_exponent_round_to_even() { return -17; } -template <> inline constexpr int binary_format::minimum_exponent() { +template <> inline constexpr int16_t binary_format::minimum_exponent() { return -1023; } -template <> inline constexpr int binary_format::minimum_exponent() { +template <> inline constexpr int16_t binary_format::minimum_exponent() { return -127; } -template <> inline constexpr int binary_format::infinite_power() { +template <> inline constexpr int16_t binary_format::infinite_power() { return 0x7FF; } -template <> inline constexpr int binary_format::infinite_power() { +template <> inline constexpr int16_t binary_format::infinite_power() { return 0xFF; } #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN -template <> inline constexpr int binary_format::sign_index() { +template <> inline constexpr uint8_t binary_format::sign_index() { return 63; } -template <> inline constexpr int binary_format::sign_index() { +template <> inline constexpr uint8_t binary_format::sign_index() { return 31; } #endif template <> -inline constexpr int binary_format::max_exponent_fast_path() { +inline constexpr int8_t binary_format::max_exponent_fast_path() { return 22; } template <> -inline constexpr int binary_format::max_exponent_fast_path() { +inline constexpr int8_t binary_format::max_exponent_fast_path() { return 10; } @@ -648,8 +657,8 @@ inline constexpr uint64_t binary_format::max_mantissa_fast_path() { } template <> -inline constexpr uint64_t binary_format::max_mantissa_fast_path() { - return uint64_t(2) << mantissa_explicit_bits(); +inline constexpr uint32_t binary_format::max_mantissa_fast_path() { + return uint32_t(2) << mantissa_explicit_bits(); } // credit: Jakub JelĂ­nek @@ -660,7 +669,7 @@ template struct binary_format_lookup_tables { // Largest integer value v so that (5**index * v) <= 1<<11. // 0x800 == 1<<11 - static constexpr uint64_t max_mantissa[] = {0x800, + static constexpr uint16_t max_mantissa[] = {0x800, 0x800 / 5, 0x800 / (5 * 5), 0x800 / (5 * 5 * 5), @@ -675,7 +684,7 @@ constexpr std::float16_t binary_format_lookup_tables::powers_of_ten[]; template -constexpr uint64_t +constexpr uint16_t binary_format_lookup_tables::max_mantissa[]; #endif @@ -706,19 +715,21 @@ binary_format::hidden_bit_mask() { } template <> -inline constexpr int binary_format::max_exponent_fast_path() { +inline constexpr int8_t +binary_format::max_exponent_fast_path() { return 4; } template <> -inline constexpr int binary_format::mantissa_explicit_bits() { +inline constexpr uint8_t +binary_format::mantissa_explicit_bits() { return 10; } template <> -inline constexpr uint64_t +inline constexpr int8_t binary_format::max_mantissa_fast_path() { - return uint64_t(2) << mantissa_explicit_bits(); + return uint16_t(2) << mantissa_explicit_bits(); } template <> @@ -732,52 +743,55 @@ binary_format::max_mantissa_fast_path(int64_t power) { } template <> -inline constexpr int binary_format::min_exponent_fast_path() { +inline constexpr int8_t +binary_format::min_exponent_fast_path() { return 0; } template <> -inline constexpr int +inline constexpr int16_t binary_format::max_exponent_round_to_even() { return 5; } template <> -inline constexpr int +inline constexpr int16_t binary_format::min_exponent_round_to_even() { return -22; } template <> -inline constexpr int binary_format::minimum_exponent() { +inline constexpr int16_t binary_format::minimum_exponent() { return -15; } template <> -inline constexpr int binary_format::infinite_power() { +inline constexpr int16_t binary_format::infinite_power() { return 0x1F; } #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN -template <> inline constexpr unsigned int binary_format::sign_index() { +template <> +inline constexpr uint8_t binary_format::sign_index() { return 15; } #endif template <> -inline constexpr int binary_format::largest_power_of_ten() { +inline constexpr int16_t binary_format::largest_power_of_ten() { return 4; } template <> -inline constexpr int binary_format::smallest_power_of_ten() { +inline constexpr int16_t +binary_format::smallest_power_of_ten() { return -27; } template <> -inline constexpr size_t binary_format::max_digits() { +inline constexpr uint8_t binary_format::max_digits() { return 22; } #endif // __STDCPP_FLOAT16_T__ @@ -815,7 +829,8 @@ binary_format::exact_power_of_ten(int64_t power) { } template <> -inline constexpr int binary_format::max_exponent_fast_path() { +inline constexpr int8_t +binary_format::max_exponent_fast_path() { return 3; } @@ -838,14 +853,16 @@ binary_format::hidden_bit_mask() { } template <> -inline constexpr int binary_format::mantissa_explicit_bits() { +inline constexpr uint8_t +binary_format::mantissa_explicit_bits() { return 7; } template <> -inline constexpr uint64_t +inline constexpr binary_format::equiv_uint binary_format::max_mantissa_fast_path() { - return uint64_t(2) << mantissa_explicit_bits(); + return binary_format::equiv_uint(2) + << mantissa_explicit_bits(); } template <> @@ -859,52 +876,56 @@ binary_format::max_mantissa_fast_path(int64_t power) { } template <> -inline constexpr int binary_format::min_exponent_fast_path() { +inline constexpr int8_t +binary_format::min_exponent_fast_path() { return 0; } template <> -inline constexpr int +inline constexpr int16_t binary_format::max_exponent_round_to_even() { return 3; } template <> -inline constexpr int +inline constexpr int16_t binary_format::min_exponent_round_to_even() { return -24; } template <> -inline constexpr int binary_format::minimum_exponent() { +inline constexpr int16_t binary_format::minimum_exponent() { return -127; } template <> -inline constexpr int binary_format::infinite_power() { +inline constexpr int16_t binary_format::infinite_power() { return 0xFF; } #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN -template <> inline constexpr int binary_format::sign_index() { +template <> +inline constexpr uint8_t binary_format::sign_index() { return 15; } #endif template <> -inline constexpr int binary_format::largest_power_of_ten() { +inline constexpr int16_t +binary_format::largest_power_of_ten() { return 38; } template <> -inline constexpr int binary_format::smallest_power_of_ten() { +inline constexpr int16_t +binary_format::smallest_power_of_ten() { return -60; } template <> -inline constexpr size_t binary_format::max_digits() { +inline constexpr uint16_t binary_format::max_digits() { return 98; } #endif // __STDCPP_BFLOAT16_T__ @@ -920,7 +941,7 @@ binary_format::max_mantissa_fast_path(int64_t power) { } template <> -inline constexpr uint64_t +inline constexpr uint32_t binary_format::max_mantissa_fast_path(int64_t power) { // caller is responsible to ensure that FASTFLOAT_ASSUME(power >= 0 && power <= 10); @@ -948,28 +969,31 @@ inline constexpr float binary_format::exact_power_of_ten(int64_t power) { return (void)powers_of_ten[0], powers_of_ten[power]; } -template <> inline constexpr int binary_format::largest_power_of_ten() { +template <> +inline constexpr int16_t binary_format::largest_power_of_ten() { return 308; } -template <> inline constexpr int binary_format::largest_power_of_ten() { +template <> +inline constexpr int16_t binary_format::largest_power_of_ten() { return 38; } template <> -inline constexpr int binary_format::smallest_power_of_ten() { +inline constexpr int16_t binary_format::smallest_power_of_ten() { return -342; } -template <> inline constexpr int binary_format::smallest_power_of_ten() { +template <> +inline constexpr int16_t binary_format::smallest_power_of_ten() { return -64; } -template <> inline constexpr size_t binary_format::max_digits() { +template <> inline constexpr uint16_t binary_format::max_digits() { return 769; } -template <> inline constexpr size_t binary_format::max_digits() { +template <> inline constexpr uint16_t binary_format::max_digits() { return 114; } diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 8f26902..9b61bdf 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -656,7 +656,8 @@ TEST_CASE("decimal_point_parsing") { answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options({fast_float::chars_format::general, ',', 10})); + fast_float::parse_options( + {fast_float::chars_format::general, ',', 10})); CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success"); CHECK_MESSAGE(answer.ptr == input.data() + input.size(), "Parsing should have stopped at end"); @@ -666,8 +667,8 @@ TEST_CASE("decimal_point_parsing") { std::string const input = "1.25"; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options({fast_float::chars_format::general, ',', - 10})); + fast_float::parse_options( + {fast_float::chars_format::general, ',', 10})); CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success"); CHECK_MESSAGE(answer.ptr == input.data() + 1, "Parsing should have stopped at dot"); @@ -1324,8 +1325,8 @@ TEST_CASE("double.general") { TEST_CASE("double.decimal_point") { constexpr auto options = [] { - return fast_float::parse_options({fast_float::chars_format::general, ',', - 10}); + return fast_float::parse_options( + {fast_float::chars_format::general, ',', 10}); }(); // infinities @@ -1642,8 +1643,8 @@ TEST_CASE("float.general") { TEST_CASE("float.decimal_point") { constexpr auto options = [] { - return fast_float::parse_options({fast_float::chars_format::general, ',', - 10}); + return fast_float::parse_options( + {fast_float::chars_format::general, ',', 10}); }(); // infinity diff --git a/tests/fortran.cpp b/tests/fortran.cpp index 2f49946..ca41986 100644 --- a/tests/fortran.cpp +++ b/tests/fortran.cpp @@ -11,9 +11,9 @@ int main_readme() { double result; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options ({ - fast_float::chars_format::fortran | - fast_float::chars_format::allow_leading_plus})); + fast_float::parse_options( + {fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus})); if ((answer.ec != std::errc()) || ((result != 10000))) { std::cerr << "parsing failure\n" << result << "\n"; return EXIT_FAILURE; @@ -35,11 +35,11 @@ int main() { for (auto const &f : fmt1) { auto d{std::distance(&fmt1[0], &f)}; double result; - auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(), - result, - fast_float::parse_options ({ - fast_float::chars_format::fortran | - fast_float::chars_format::allow_leading_plus}))}; + auto answer{fast_float::from_chars_advanced( + f.data(), f.data() + f.size(), result, + fast_float::parse_options( + {fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus}))}; if (answer.ec != std::errc() || result != expected[std::size_t(d)]) { std::cerr << "parsing failure on " << f << std::endl; return EXIT_FAILURE; @@ -49,11 +49,11 @@ int main() { for (auto const &f : fmt2) { auto d{std::distance(&fmt2[0], &f)}; double result; - auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(), - result, - fast_float::parse_options ({ - fast_float::chars_format::fortran | - fast_float::chars_format::allow_leading_plus}))}; + auto answer{fast_float::from_chars_advanced( + f.data(), f.data() + f.size(), result, + fast_float::parse_options( + {fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus}))}; if (answer.ec != std::errc() || result != expected[std::size_t(d)]) { std::cerr << "parsing failure on " << f << std::endl; return EXIT_FAILURE; @@ -63,11 +63,11 @@ int main() { for (auto const &f : fmt3) { auto d{std::distance(&fmt3[0], &f)}; double result; - auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(), - result, - fast_float::parse_options ({ - fast_float::chars_format::fortran | - fast_float::chars_format::allow_leading_plus}))}; + auto answer{fast_float::from_chars_advanced( + f.data(), f.data() + f.size(), result, + fast_float::parse_options( + {fast_float::chars_format::fortran | + fast_float::chars_format::allow_leading_plus}))}; if (answer.ec != std::errc() || result != expected[std::size_t(d)]) { std::cerr << "parsing failure on " << f << std::endl; return EXIT_FAILURE; diff --git a/tests/json_fmt.cpp b/tests/json_fmt.cpp index bf3b402..70fdef2 100644 --- a/tests/json_fmt.cpp +++ b/tests/json_fmt.cpp @@ -9,10 +9,10 @@ int main_readme() { double result; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options options({ - fast_float::chars_format::json | - fast_float::chars_format::allow_leading_plus}) // should be ignored - ); + fast_float::parse_options options( + {fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus}) // should be ignored + ); if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; @@ -25,10 +25,10 @@ int main_readme2() { double result; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options options({ - fast_float::chars_format::json | - fast_float::chars_format::allow_leading_plus}) // should be ignored - ); + fast_float::parse_options options( + {fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus}) // should be ignored + ); if (answer.ec == std::errc()) { std::cerr << "should have failed\n"; return EXIT_FAILURE; @@ -42,10 +42,10 @@ int main_readme3() { double result; auto answer = fast_float::from_chars_advanced( input.data(), input.data() + input.size(), result, - fast_float::parse_options options({ - fast_float::chars_format::json_or_infnan | - fast_float::chars_format::allow_leading_plus}); // should be ignored - ); + fast_float::parse_options options( + {fast_float::chars_format::json_or_infnan | + fast_float::chars_format::allow_leading_plus}); // should be ignored + ); if (answer.ec != std::errc() || (!std::isinf(result))) { std::cerr << "should have parsed infinity\n"; return EXIT_FAILURE; @@ -136,9 +136,10 @@ int main() { auto const &expected_reason = reject[i].reason; auto answer = fast_float::parse_number_string( f.data(), f.data() + f.size(), - fast_float::parse_options({ - fast_float::chars_format::json | - fast_float::chars_format::allow_leading_plus})); // should be ignored + fast_float::parse_options( + {fast_float::chars_format::json | + fast_float::chars_format::allow_leading_plus})); // should be + // ignored if (answer.valid) { std::cerr << "json parse accepted invalid json " << f << std::endl; return EXIT_FAILURE;