mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-07 01:06:48 +08:00
# const and constexpr fixes
# types fixes. # FASTFLOAT_ASSERT fix.
This commit is contained in:
parent
1dc13a91f1
commit
fe0bce5eb7
@ -270,9 +270,9 @@ parse_mantissa(bigint &result, const parsed_number_string_t<UC> &num) noexcept {
|
||||
am_digits digits = 0;
|
||||
limb value = 0;
|
||||
#ifdef FASTFLOAT_64BIT_LIMB
|
||||
am_digits const step = 19;
|
||||
constexpr am_digits step = 19;
|
||||
#else
|
||||
am_digits const step = 9;
|
||||
constexpr am_digits step = 9;
|
||||
#endif
|
||||
|
||||
// process all integer digits.
|
||||
|
||||
@ -31,14 +31,14 @@ namespace fast_float {
|
||||
*/
|
||||
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();
|
||||
constexpr static int largest_power_of_five =
|
||||
constexpr static am_pow_t largest_power_of_five =
|
||||
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);
|
||||
// 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,
|
||||
0x9558b4661b6565f8, 0x4ac7ca59a424c507,
|
||||
0xbaaee17fa23ebf76, 0x5d79bcf00d2df649,
|
||||
@ -696,7 +696,7 @@ template <class unused = void> struct powers_template {
|
||||
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
|
||||
|
||||
template <class unused>
|
||||
constexpr uint64_t
|
||||
constexpr am_mant_t
|
||||
powers_template<unused>::power_of_five_128[number_of_entries];
|
||||
|
||||
#endif
|
||||
|
||||
@ -83,7 +83,9 @@ 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) {}
|
||||
: format(fmt), decimal_point(dot), base(b) {
|
||||
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
||||
}
|
||||
|
||||
/** Which number formats are accepted */
|
||||
chars_format format;
|
||||
@ -91,7 +93,6 @@ template <typename UC> struct parse_options_t {
|
||||
UC decimal_point;
|
||||
/** The base used for integers */
|
||||
uint_fast8_t base; /* only allowed from 2 to 36 */
|
||||
FASTFLOAT_ASSUME(base >= 2 && base <= 36);
|
||||
};
|
||||
|
||||
using parse_options = parse_options_t<char>;
|
||||
@ -214,7 +215,6 @@ using parse_options = parse_options_t<char>;
|
||||
#define FASTFLOAT_ASSERT(x) \
|
||||
{ \
|
||||
((void)(x)); \
|
||||
FASTFLOAT_ASSUME(x); \
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -222,7 +222,6 @@ using parse_options = parse_options_t<char>;
|
||||
#define FASTFLOAT_DEBUG_ASSERT(x) \
|
||||
{ \
|
||||
((void)(x)); \
|
||||
FASTFLOAT_ASSUME(x); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -437,12 +437,13 @@ FASTFLOAT_CONSTEXPR20
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -2126,8 +2126,9 @@ TEST_CASE("bfloat16.general") {
|
||||
#endif
|
||||
|
||||
template <typename Int, typename T, typename U>
|
||||
void verify_integer_times_pow10_result(Int mantissa, int decimal_exponent,
|
||||
T actual, U expected) {
|
||||
void verify_integer_times_pow10_result(Int const mantissa,
|
||||
int const decimal_exponent,
|
||||
T const actual, U const expected) {
|
||||
static_assert(std::is_same<T, U>::value,
|
||||
"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>
|
||||
T calculate_integer_times_pow10_expected_result(Int mantissa,
|
||||
int decimal_exponent) {
|
||||
T calculate_integer_times_pow10_expected_result(Int const mantissa,
|
||||
int const decimal_exponent) {
|
||||
std::string constructed_string =
|
||||
std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
|
||||
T expected_result;
|
||||
@ -2158,8 +2159,9 @@ T calculate_integer_times_pow10_expected_result(Int mantissa,
|
||||
}
|
||||
|
||||
template <typename Int>
|
||||
void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent,
|
||||
double expected) {
|
||||
void verify_integer_times_pow10_dflt(Int const mantissa,
|
||||
int const decimal_exponent,
|
||||
double const expected) {
|
||||
static_assert(std::is_integral<Int>::value);
|
||||
|
||||
// the "default" overload
|
||||
@ -2171,7 +2173,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
const auto expected_result =
|
||||
@ -2182,8 +2185,8 @@ void verify_integer_times_pow10_dflt(Int mantissa, int decimal_exponent) {
|
||||
}
|
||||
|
||||
template <typename T, typename Int>
|
||||
void verify_integer_times_pow10(Int mantissa, int decimal_exponent,
|
||||
T expected) {
|
||||
void verify_integer_times_pow10(Int const mantissa, int const decimal_exponent,
|
||||
T const expected) {
|
||||
static_assert(std::is_floating_point<T>::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>
|
||||
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_integral<Int>::value);
|
||||
|
||||
@ -2208,7 +2212,8 @@ void verify_integer_times_pow10(Int mantissa, int decimal_exponent) {
|
||||
|
||||
namespace all_supported_types {
|
||||
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);
|
||||
|
||||
// verify the "default" overload
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user