# const and constexpr fixes

# types fixes.
# FASTFLOAT_ASSERT fix.
This commit is contained in:
IRainman 2025-10-21 21:08:08 +03:00
parent 1dc13a91f1
commit fe0bce5eb7
5 changed files with 29 additions and 24 deletions

View File

@ -270,9 +270,9 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num) noexcept {
am_digits digits = 0; am_digits digits = 0;
limb value = 0; limb value = 0;
#ifdef FASTFLOAT_64BIT_LIMB #ifdef FASTFLOAT_64BIT_LIMB
am_digits const step = 19; constexpr am_digits step = 19;
#else #else
am_digits const step = 9; constexpr am_digits step = 9;
#endif #endif
// process all integer digits. // process all integer digits.

View File

@ -31,14 +31,14 @@ namespace fast_float {
*/ */
template <class unused = void> struct powers_template { template <class unused = void> struct powers_template {
constexpr static int smallest_power_of_five = constexpr static am_pow_t smallest_power_of_five =
binary_format<double>::smallest_power_of_ten(); binary_format<double>::smallest_power_of_ten();
constexpr static int largest_power_of_five = constexpr static am_pow_t largest_power_of_five =
binary_format<double>::largest_power_of_ten(); binary_format<double>::largest_power_of_ten();
constexpr static int number_of_entries = constexpr static am_digits number_of_entries =
2 * (largest_power_of_five - smallest_power_of_five + 1); 2 * (largest_power_of_five - smallest_power_of_five + 1);
// Powers of five from 5^-342 all the way to 5^308 rounded toward one. // Powers of five from 5^-342 all the way to 5^308 rounded toward one.
constexpr static uint64_t power_of_five_128[number_of_entries] = { constexpr static am_mant_t power_of_five_128[number_of_entries] = {
0xeef453d6923bd65a, 0x113faa2906a13b3f, 0xeef453d6923bd65a, 0x113faa2906a13b3f,
0x9558b4661b6565f8, 0x4ac7ca59a424c507, 0x9558b4661b6565f8, 0x4ac7ca59a424c507,
0xbaaee17fa23ebf76, 0x5d79bcf00d2df649, 0xbaaee17fa23ebf76, 0x5d79bcf00d2df649,
@ -696,7 +696,7 @@ template <class unused = void> struct powers_template {
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE #if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
template <class unused> template <class unused>
constexpr uint64_t constexpr am_mant_t
powers_template<unused>::power_of_five_128[number_of_entries]; powers_template<unused>::power_of_five_128[number_of_entries];
#endif #endif

View File

@ -83,7 +83,9 @@ template <typename UC> struct parse_options_t {
constexpr explicit parse_options_t( constexpr explicit parse_options_t(
chars_format const fmt = chars_format::general, UC const dot = UC('.'), chars_format const fmt = chars_format::general, UC const dot = UC('.'),
uint_fast8_t const b = 10) noexcept uint_fast8_t const b = 10) noexcept
: format(fmt), decimal_point(dot), base(b) {} : format(fmt), decimal_point(dot), base(b) {
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
}
/** Which number formats are accepted */ /** Which number formats are accepted */
chars_format format; chars_format format;
@ -91,7 +93,6 @@ template <typename UC> struct parse_options_t {
UC decimal_point; UC decimal_point;
/** The base used for integers */ /** The base used for integers */
uint_fast8_t base; /* only allowed from 2 to 36 */ uint_fast8_t base; /* only allowed from 2 to 36 */
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
}; };
using parse_options = parse_options_t<char>; using parse_options = parse_options_t<char>;
@ -214,7 +215,6 @@ using parse_options = parse_options_t<char>;
#define FASTFLOAT_ASSERT(x) \ #define FASTFLOAT_ASSERT(x) \
{ \ { \
((void)(x)); \ ((void)(x)); \
FASTFLOAT_ASSUME(x); \
} }
#endif #endif
@ -222,7 +222,6 @@ using parse_options = parse_options_t<char>;
#define FASTFLOAT_DEBUG_ASSERT(x) \ #define FASTFLOAT_DEBUG_ASSERT(x) \
{ \ { \
((void)(x)); \ ((void)(x)); \
FASTFLOAT_ASSUME(x); \
} }
#endif #endif

View File

@ -437,12 +437,13 @@ FASTFLOAT_CONSTEXPR20
} }
FASTFLOAT_CONSTEXPR20 inline double FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(uint64_t mantissa, int const decimal_exponent) noexcept { integer_times_pow10(uint64_t const mantissa,
int const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent); return integer_times_pow10<double>(mantissa, decimal_exponent);
} }
FASTFLOAT_CONSTEXPR20 inline double FASTFLOAT_CONSTEXPR20 inline double
integer_times_pow10(int64_t mantissa, int const decimal_exponent) noexcept { integer_times_pow10(int64_t const mantissa, int const decimal_exponent) noexcept {
return integer_times_pow10<double>(mantissa, decimal_exponent); return integer_times_pow10<double>(mantissa, decimal_exponent);
} }

View File

@ -2126,8 +2126,9 @@ TEST_CASE("bfloat16.general") {
#endif #endif
template <typename Int, typename T, typename U> template <typename Int, typename T, typename U>
void verify_integer_times_pow10_result(Int mantissa, int decimal_exponent, void verify_integer_times_pow10_result(Int const mantissa,
T actual, U expected) { int const decimal_exponent,
T const actual, U const expected) {
static_assert(std::is_same<T, U>::value, static_assert(std::is_same<T, U>::value,
"expected and actual types must match"); "expected and actual types must match");
@ -2144,8 +2145,8 @@ void verify_integer_times_pow10_result(Int mantissa, int decimal_exponent,
} }
template <typename T, typename Int> template <typename T, typename Int>
T calculate_integer_times_pow10_expected_result(Int mantissa, T calculate_integer_times_pow10_expected_result(Int const mantissa,
int decimal_exponent) { int const decimal_exponent) {
std::string constructed_string = std::string constructed_string =
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent); std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
T expected_result; T expected_result;
@ -2158,8 +2159,9 @@ T calculate_integer_times_pow10_expected_result(Int mantissa,
} }
template <typename Int> template <typename Int>
void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent, void verify_integer_times_pow10_dflt(Int const mantissa,
double expected) { int const decimal_exponent,
double const expected) {
static_assert(std::is_integral<Int>::value); static_assert(std::is_integral<Int>::value);
// the "default" overload // the "default" overload
@ -2171,7 +2173,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent,
} }
template <typename Int> template <typename Int>
void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent) { void verify_integer_times_pow10_dflt(Int const mantissa,
int const decimal_exponent) {
static_assert(std::is_integral<Int>::value); static_assert(std::is_integral<Int>::value);
const auto expected_result = const auto expected_result =
@ -2182,8 +2185,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent) {
} }
template <typename T, typename Int> template <typename T, typename Int>
void verify_integer_times_pow10(Int mantissa, int decimal_exponent, void verify_integer_times_pow10(Int const mantissa, int const decimal_exponent,
T expected) { T const expected) {
static_assert(std::is_floating_point<T>::value); static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value); static_assert(std::is_integral<Int>::value);
@ -2196,7 +2199,8 @@ void verify_integer_times_pow10(Int mantissa, int decimal_exponent,
} }
template <typename T, typename Int> template <typename T, typename Int>
void verify_integer_times_pow10(Int mantissa, int decimal_exponent) { void verify_integer_times_pow10(Int const mantissa,
int const decimal_exponent) {
static_assert(std::is_floating_point<T>::value); static_assert(std::is_floating_point<T>::value);
static_assert(std::is_integral<Int>::value); static_assert(std::is_integral<Int>::value);
@ -2208,7 +2212,8 @@ void verify_integer_times_pow10(Int mantissa, int decimal_exponent) {
namespace all_supported_types { namespace all_supported_types {
template <typename Int> template <typename Int>
void verify_integer_times_pow10(Int mantissa, int decimal_exponent) { void verify_integer_times_pow10(Int const mantissa,
int const decimal_exponent) {
static_assert(std::is_integral<Int>::value); static_assert(std::is_integral<Int>::value);
// verify the "default" overload // verify the "default" overload