Compare commits

...

4 Commits

Author SHA1 Message Date
HedgehogInTheCPP
168e0a294b
Merge c9d0ac0084ca7cf203c0eae815acf47d4ff911ba into 7b21183a93c4a8943a2d384f207537d7330547e1 2025-11-10 00:49:34 +00:00
IRainman
c9d0ac0084 # cleanup. 2025-11-10 03:49:27 +03:00
IRainman
597c239218 # test fixed. 2025-11-10 03:13:05 +03:00
IRainman
b8163709f5 * type usage fix for better performance in any hardware. 2025-11-10 02:41:26 +03:00
6 changed files with 44 additions and 46 deletions

View File

@ -369,7 +369,7 @@ FASTFLOAT_CONSTEXPR20 bool large_mul(stackvec<size> &x, limb_span y) noexcept {
}
template <typename = void> struct pow5_tables {
static constexpr uint8_t large_step = 135;
static constexpr uint_fast8_t large_step = 135;
static constexpr uint64_t small_power_of_5[] = {
1UL,
5UL,
@ -413,7 +413,7 @@ template <typename = void> struct pow5_tables {
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
template <typename T> constexpr uint8_t pow5_tables<T>::large_step;
template <typename T> constexpr uint_fast8_t pow5_tables<T>::large_step;
template <typename T> constexpr uint64_t pow5_tables<T>::small_power_of_5[];

View File

@ -60,10 +60,10 @@ from_chars_advanced(UC const *first, UC const *last, T &value,
*/
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(uint64_t const mantissa,
int16_t const decimal_exponent) noexcept;
int_fast16_t const decimal_exponent) noexcept;
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(int64_t const mantissa,
int16_t const decimal_exponent) noexcept;
int_fast16_t const decimal_exponent) noexcept;
/**
* This function is a template overload of `integer_times_pow10()`
@ -74,12 +74,12 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(uint64_t const mantissa,
int16_t const decimal_exponent) noexcept;
int_fast16_t const decimal_exponent) noexcept;
template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(int64_t const mantissa,
int16_t const decimal_exponent) noexcept;
int_fast16_t const decimal_exponent) noexcept;
/**
* from_chars for integer types.
@ -88,7 +88,7 @@ template <typename T, typename UC = char,
typename = FASTFLOAT_ENABLE_IF(is_supported_integer_type<T>::value)>
FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
from_chars(UC const *first, UC const *last, T &value,
int const base = 10) noexcept;
uint_fast8_t const base = 10) noexcept;
} // namespace fast_float

View File

@ -45,8 +45,8 @@ enum class chars_format : chars_format_t;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
namespace detail {
constexpr chars_format basic_json_fmt = chars_format(1 << 4);
constexpr chars_format basic_fortran_fmt = chars_format(1 << 5);
constexpr chars_format basic_json_fmt = chars_format(1 << 6);
constexpr chars_format basic_fortran_fmt = chars_format(1 << 7);
} // namespace detail
#endif
@ -57,13 +57,13 @@ enum class chars_format : chars_format_t {
hex = 1 << 2,
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
no_infnan = 1 << 3,
allow_leading_plus = 1 << 4,
skip_white_space = 1 << 5,
// RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6
json = chars_format_t(detail::basic_json_fmt) | general | no_infnan,
// Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed.
json_or_infnan = chars_format_t(detail::basic_json_fmt) | general,
fortran = chars_format_t(detail::basic_fortran_fmt) | general,
allow_leading_plus = 1 << 6,
skip_white_space = 1 << 7,
#endif
};
@ -83,9 +83,7 @@ template <typename UC> struct parse_options_t {
constexpr explicit parse_options_t(
chars_format const fmt = chars_format::general, UC const dot = UC('.'),
uint_fast8_t const b = 10) noexcept
: format(fmt), decimal_point(dot), base(b) {
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
}
: format(fmt), decimal_point(dot), base(b) {}
/** Which number formats are accepted */
chars_format format;
@ -287,8 +285,8 @@ struct is_supported_char_type
template <typename UC>
inline FASTFLOAT_CONSTEXPR14 bool
fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
uint8_t const length) noexcept {
for (uint8_t i = 0; i++ != length;) {
uint_fast8_t const length) noexcept {
for (uint_fast8_t i = 0; i++ != length;) {
UC const actual = actual_mixedcase[i];
if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) {
return false;
@ -1059,7 +1057,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
template <typename = void> struct space_lut {
static constexpr uint8_t value[] = {
static constexpr uint_fast8_t 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,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -1075,12 +1073,12 @@ template <typename = void> struct space_lut {
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
template <typename T> constexpr uint8_t space_lut<T>::value[];
template <typename T> constexpr uint_fast8_t space_lut<T>::value[];
#endif
template <typename UC> constexpr bool is_space(UC c) {
return c < 256 && space_lut<>::value[uint8_t(c)];
return c < 256 && space_lut<>::value[uint_fast8_t(c)];
}
#endif
@ -1166,7 +1164,7 @@ template <typename = void> struct int_luts {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255};
static constexpr uint8_t maxdigits_u64[] = {
static constexpr uint_fast8_t maxdigits_u64[] = {
64, 41, 32, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 16, 16, 16, 16,
15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13};
@ -1187,9 +1185,9 @@ template <typename = void> struct int_luts {
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
template <typename T> constexpr uint8_t int_luts<T>::chdigit[];
template <typename T> constexpr uint_fast8_t int_luts<T>::chdigit[];
template <typename T> constexpr uint8_t int_luts<T>::maxdigits_u64[];
template <typename T> constexpr uint_fast8_t int_luts<T>::maxdigits_u64[];
template <typename T> constexpr uint64_t int_luts<T>::min_safe_u64[];

View File

@ -374,15 +374,15 @@ from_chars_float_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 const base) noexcept {
from_chars(UC const *first, UC const *last, T &value,
uint_fast8_t const base) noexcept {
static_assert(is_supported_integer_type<T>::value,
"only integer types are supported");
static_assert(is_supported_char_type<UC>::value,
"only char, wchar_t, char16_t and char32_t are supported");
parse_options_t<UC> const options(chars_format::general, UC('.'),
static_cast<uint_fast8_t>(base));
parse_options_t<UC> const options(chars_format::general, UC('.'), base);
return from_chars_advanced(first, last, value, options);
}
@ -390,7 +390,7 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(uint64_t const mantissa,
int16_t const decimal_exponent) noexcept {
int_fast16_t const decimal_exponent) noexcept {
T value;
if (clinger_fast_path_impl(mantissa, decimal_exponent,
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
@ -413,7 +413,7 @@ template <typename T>
FASTFLOAT_CONSTEXPR20
typename std::enable_if<is_supported_float_type<T>::value, T>::type
integer_times_pow10(int64_t const mantissa,
int16_t const decimal_exponent) noexcept {
int_fast16_t const decimal_exponent) noexcept {
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
FASTFLOAT_ASSUME(mantissa > 0);
const am_mant_t m = static_cast<am_mant_t>(mantissa);
@ -442,13 +442,13 @@ FASTFLOAT_CONSTEXPR20
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(uint64_t const mantissa,
int16_t const decimal_exponent) noexcept {
int_fast16_t const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent);
}
FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(int64_t const mantissa,
int16_t const decimal_exponent) noexcept {
int_fast16_t const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent);
}
@ -460,7 +460,7 @@ FASTFLOAT_CONSTEXPR20
std::is_integral<Int>::value &&
!std::is_signed<Int>::value,
T>::type
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept {
return integer_times_pow10<T>(static_cast<uint64_t>(mantissa),
decimal_exponent);
}
@ -471,7 +471,7 @@ FASTFLOAT_CONSTEXPR20
std::is_integral<Int>::value &&
std::is_signed<Int>::value,
T>::type
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept {
return integer_times_pow10<T>(static_cast<int64_t>(mantissa),
decimal_exponent);
}
@ -479,14 +479,14 @@ FASTFLOAT_CONSTEXPR20
template <typename Int>
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
std::is_integral<Int>::value && !std::is_signed<Int>::value, double>::type
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept {
return integer_times_pow10(static_cast<uint64_t>(mantissa), decimal_exponent);
}
template <typename Int>
FASTFLOAT_CONSTEXPR20 typename std::enable_if<
std::is_integral<Int>::value && std::is_signed<Int>::value, double>::type
integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept {
integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept {
return integer_times_pow10(static_cast<int64_t>(mantissa), decimal_exponent);
}

View File

@ -2127,7 +2127,7 @@ TEST_CASE("bfloat16.general") {
template <typename Int, typename T, typename U>
void verify_integer_times_pow10_result(Int const mantissa,
int16_t const decimal_exponent,
int_fast16_t const decimal_exponent,
T const actual, U const expected) {
static_assert(std::is_same<T, U>::value,
"expected and actual types must match");
@ -2146,7 +2146,7 @@ void verify_integer_times_pow10_result(Int const mantissa,
template <typename T, typename Int>
T calculate_integer_times_pow10_expected_result(
Int const mantissa, int16_t const decimal_exponent) {
Int const mantissa, int_fast16_t const decimal_exponent) {
std::string constructed_string =
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
T expected_result;
@ -2160,7 +2160,7 @@ T calculate_integer_times_pow10_expected_result(
template <typename Int>
void verify_integer_times_pow10_dflt(Int const mantissa,
int16_t const decimal_exponent,
int_fast16_t const decimal_exponent,
double const expected) {
static_assert(std::is_integral<Int>::value);
@ -2174,7 +2174,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
template <typename Int>
void verify_integer_times_pow10_dflt(Int const mantissa,
int16_t const decimal_exponent) {
int_fast16_t const decimal_exponent) {
static_assert(std::is_integral<Int>::value);
const auto expected_result =
@ -2186,7 +2186,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa,
template <typename T, typename Int>
void verify_integer_times_pow10(Int const mantissa,
int16_t const decimal_exponent,
int_fast16_t const decimal_exponent,
T const expected) {
static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value);
@ -2201,7 +2201,7 @@ void verify_integer_times_pow10(Int const mantissa,
template <typename T, typename Int>
void verify_integer_times_pow10(Int const mantissa,
int16_t const decimal_exponent) {
int_fast16_t const decimal_exponent) {
static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value);
@ -2214,7 +2214,7 @@ void verify_integer_times_pow10(Int const mantissa,
namespace all_supported_types {
template <typename Int>
void verify_integer_times_pow10(Int const mantissa,
int16_t const decimal_exponent) {
int_fast16_t const decimal_exponent) {
static_assert(std::is_integral<Int>::value);
// verify the "default" overload

View File

@ -466,7 +466,7 @@ int main() {
auto const &f = invalid_base_test_1[i];
int result;
auto answer =
fast_float::from_chars(f.data(), f.data() + f.size(), result, -1);
fast_float::from_chars(f.data(), f.data() + f.size(), result, 1);
if (answer.ec != std::errc::invalid_argument) {
std::cerr << "expected error should be 'invalid_argument' for: \"" << f
<< "\"" << std::endl;
@ -567,7 +567,7 @@ int main() {
auto const &f = int_out_of_range_base_test[i];
int64_t result;
auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result,
int(2 + (i / 2)));
uint_fast8_t(2 + (i / 2)));
if (answer.ec != std::errc::result_out_of_range) {
std::cerr << "expected error for should be 'result_out_of_range': \"" << f
<< "\"" << std::endl;
@ -612,7 +612,7 @@ int main() {
"7ORP63SH4DPHI",
"5G24A25TWKWFG",
"3W5E11264SGSG"};
int base_unsigned = 2;
uint_fast8_t base_unsigned = 2;
for (std::size_t i = 0; i < unsigned_out_of_range_base_test.size(); ++i) {
auto const &f = unsigned_out_of_range_base_test[i];
uint64_t result;
@ -703,7 +703,7 @@ int main() {
auto const &f = int_within_range_base_test[i];
int64_t result;
auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result,
int(2 + (i / 2)));
uint_fast8_t(2 + (i / 2)));
if (answer.ec != std::errc()) {
std::cerr << "converting " << f
<< " to int failed (most likely out of range)" << std::endl;
@ -748,7 +748,7 @@ int main() {
"7ORP63SH4DPHH",
"5G24A25TWKWFF",
"3W5E11264SGSF"};
int base_unsigned2 = 2;
uint_fast8_t base_unsigned2 = 2;
for (std::size_t i = 0; i < unsigned_within_range_base_test.size(); ++i) {
auto const &f = unsigned_within_range_base_test[i];
uint64_t result;
@ -806,7 +806,7 @@ int main() {
auto const &f = int_leading_zeros_test[i];
int result;
auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result,
int(i + 2));
uint_fast8_t(i + 2));
if (answer.ec != std::errc()) {
std::cerr << "could not convert to int for input: \"" << f << "\""
<< std::endl;