mirror of
https://github.com/fastfloat/fast_float.git
synced 2026-02-13 21:59:54 +08:00
type usage fixes.
This commit is contained in:
parent
5bc96372bd
commit
5c6a6c2742
@ -604,9 +604,8 @@ parse_int_string(UC const *p, UC const *pend, T &value,
|
|||||||
|
|
||||||
const uint32_t magic =
|
const uint32_t magic =
|
||||||
((digits + 0x46464646u) | (digits - 0x30303030u)) & 0x80808080u;
|
((digits + 0x46464646u) | (digits - 0x30303030u)) & 0x80808080u;
|
||||||
const auto tz =
|
const auto tz = countr_zero_32(magic); // 7, 15, 23, 31, or 32
|
||||||
static_cast<am_digits>(countr_zero_32(magic)); // 7, 15, 23, 31, or 32
|
am_digits nd = (tz == 32) ? 4 : (tz >> 3);
|
||||||
limb_t nd = (tz == 32) ? 4 : (tz >> 3);
|
|
||||||
nd = std::min(nd, len);
|
nd = std::min(nd, len);
|
||||||
if (nd == 0) {
|
if (nd == 0) {
|
||||||
if (has_leading_zeros) {
|
if (has_leading_zeros) {
|
||||||
|
|||||||
@ -567,7 +567,7 @@ struct bigint : pow5_tables<> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the number of leading zeros in the bigint.
|
// get the number of leading zeros in the bigint.
|
||||||
FASTFLOAT_CONSTEXPR20 limb_t ctlz() const noexcept {
|
FASTFLOAT_CONSTEXPR20 bigint_bits_t ctlz() const noexcept {
|
||||||
if (vec.is_empty()) {
|
if (vec.is_empty()) {
|
||||||
// empty vector, no bits, no zeros.
|
// empty vector, no bits, no zeros.
|
||||||
return 0;
|
return 0;
|
||||||
@ -584,7 +584,7 @@ struct bigint : pow5_tables<> {
|
|||||||
|
|
||||||
// get the number of bits in the bigint.
|
// get the number of bits in the bigint.
|
||||||
FASTFLOAT_CONSTEXPR20 bigint_bits_t bit_length() const noexcept {
|
FASTFLOAT_CONSTEXPR20 bigint_bits_t bit_length() const noexcept {
|
||||||
limb_t lz = ctlz();
|
bigint_bits_t lz = ctlz();
|
||||||
return static_cast<fast_float::bigint_bits_t>(limb_bits * vec.len() - lz);
|
return static_cast<fast_float::bigint_bits_t>(limb_bits * vec.len() - lz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,8 +71,8 @@ constexpr fastfloat_really_inline am_pow_t power(am_pow_t q) noexcept {
|
|||||||
// for significant digits already multiplied by 10 ** q.
|
// for significant digits already multiplied by 10 ** q.
|
||||||
template <typename binary>
|
template <typename binary>
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 adjusted_mantissa
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 adjusted_mantissa
|
||||||
compute_error_scaled(int64_t q, uint64_t w, limb_t lz) noexcept {
|
compute_error_scaled(int64_t q, uint64_t w, am_digits lz) noexcept {
|
||||||
auto const hilz = static_cast<limb_t>((w >> 63) ^ 1);
|
auto const hilz = static_cast<am_digits>((w >> 63) ^ 1);
|
||||||
adjusted_mantissa answer;
|
adjusted_mantissa answer;
|
||||||
answer.mantissa = w << hilz;
|
answer.mantissa = w << hilz;
|
||||||
constexpr am_pow_t bias =
|
constexpr am_pow_t bias =
|
||||||
@ -87,7 +87,7 @@ compute_error_scaled(int64_t q, uint64_t w, limb_t lz) noexcept {
|
|||||||
template <typename binary>
|
template <typename binary>
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 adjusted_mantissa
|
||||||
compute_error(int64_t q, uint64_t w) noexcept {
|
compute_error(int64_t q, uint64_t w) noexcept {
|
||||||
limb_t const lz = leading_zeroes(w);
|
am_digits const lz = leading_zeroes(w);
|
||||||
w <<= lz;
|
w <<= lz;
|
||||||
value128 product =
|
value128 product =
|
||||||
compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
|
compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
|
||||||
@ -119,7 +119,7 @@ compute_float(int64_t q, uint64_t w) noexcept {
|
|||||||
// powers::largest_power_of_five].
|
// powers::largest_power_of_five].
|
||||||
|
|
||||||
// We want the most significant bit of i to be 1. Shift if needed.
|
// We want the most significant bit of i to be 1. Shift if needed.
|
||||||
limb_t const lz = leading_zeroes(w);
|
am_digits const lz = leading_zeroes(w);
|
||||||
w <<= lz;
|
w <<= lz;
|
||||||
|
|
||||||
// The required precision is binary::mantissa_explicit_bits() + 3 because
|
// The required precision is binary::mantissa_explicit_bits() + 3 because
|
||||||
|
|||||||
@ -353,7 +353,7 @@ struct alignas(16) value128 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Helper C++14 constexpr generic implementation of leading_zeroes for 64-bit */
|
/* Helper C++14 constexpr generic implementation of leading_zeroes for 64-bit */
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 limb_t
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 am_digits
|
||||||
leading_zeroes_generic(uint64_t input_num, uint32_t last_bit = 0) noexcept {
|
leading_zeroes_generic(uint64_t input_num, uint32_t last_bit = 0) noexcept {
|
||||||
if (input_num & uint64_t(0xffffffff00000000)) {
|
if (input_num & uint64_t(0xffffffff00000000)) {
|
||||||
input_num >>= 32;
|
input_num >>= 32;
|
||||||
@ -378,11 +378,11 @@ leading_zeroes_generic(uint64_t input_num, uint32_t last_bit = 0) noexcept {
|
|||||||
if (input_num & uint64_t(0x2)) { /* input_num >>= 1; */
|
if (input_num & uint64_t(0x2)) { /* input_num >>= 1; */
|
||||||
last_bit |= 1;
|
last_bit |= 1;
|
||||||
}
|
}
|
||||||
return 63 - static_cast<limb_t>(last_bit);
|
return 63 - static_cast<am_digits>(last_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* result might be undefined when input_num is zero */
|
/* result might be undefined when input_num is zero */
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb_t
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 am_digits
|
||||||
leading_zeroes(uint64_t input_num) noexcept {
|
leading_zeroes(uint64_t input_num) noexcept {
|
||||||
assert(input_num > 0);
|
assert(input_num > 0);
|
||||||
FASTFLOAT_ASSUME(input_num > 0);
|
FASTFLOAT_ASSUME(input_num > 0);
|
||||||
@ -395,17 +395,17 @@ leading_zeroes(uint64_t input_num) noexcept {
|
|||||||
// Search the mask data from most significant bit (MSB)
|
// Search the mask data from most significant bit (MSB)
|
||||||
// to least significant bit (LSB) for a set bit (1).
|
// to least significant bit (LSB) for a set bit (1).
|
||||||
_BitScanReverse64(&leading_zero, input_num);
|
_BitScanReverse64(&leading_zero, input_num);
|
||||||
return static_cast<limb_t>(63 - leading_zero);
|
return static_cast<am_digits>(63 - leading_zero);
|
||||||
#else
|
#else
|
||||||
return static_cast<limb_t>(leading_zeroes_generic(input_num));
|
return static_cast<am_digits>(leading_zeroes_generic(input_num));
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
return static_cast<limb_t>(__builtin_clzll(input_num));
|
return static_cast<am_digits>(__builtin_clzll(input_num));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper C++14 constexpr generic implementation of countr_zero for 32-bit */
|
/* Helper C++14 constexpr generic implementation of countr_zero for 32-bit */
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 limb_t
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR14 am_digits
|
||||||
countr_zero_generic_32(uint32_t input_num) {
|
countr_zero_generic_32(uint32_t input_num) {
|
||||||
if (input_num == 0) {
|
if (input_num == 0) {
|
||||||
return 32;
|
return 32;
|
||||||
@ -430,11 +430,11 @@ countr_zero_generic_32(uint32_t input_num) {
|
|||||||
if (!(input_num & 0x1)) {
|
if (!(input_num & 0x1)) {
|
||||||
last_bit |= 1;
|
last_bit |= 1;
|
||||||
}
|
}
|
||||||
return static_cast<limb_t>(last_bit);
|
return static_cast<am_digits>(last_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count trailing zeroes for 32-bit integers */
|
/* count trailing zeroes for 32-bit integers */
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 limb_t
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 am_digits
|
||||||
countr_zero_32(uint32_t input_num) {
|
countr_zero_32(uint32_t input_num) {
|
||||||
if (cpp20_and_in_constexpr()) {
|
if (cpp20_and_in_constexpr()) {
|
||||||
return countr_zero_generic_32(input_num);
|
return countr_zero_generic_32(input_num);
|
||||||
@ -442,11 +442,11 @@ countr_zero_32(uint32_t input_num) {
|
|||||||
#ifdef FASTFLOAT_VISUAL_STUDIO
|
#ifdef FASTFLOAT_VISUAL_STUDIO
|
||||||
unsigned long trailing_zero = 0;
|
unsigned long trailing_zero = 0;
|
||||||
if (_BitScanForward(&trailing_zero, input_num)) {
|
if (_BitScanForward(&trailing_zero, input_num)) {
|
||||||
return static_cast<limb_t>(trailing_zero);
|
return static_cast<am_digits>(trailing_zero);
|
||||||
}
|
}
|
||||||
return 32;
|
return 32;
|
||||||
#else
|
#else
|
||||||
return input_num == 0 ? 32 : static_cast<limb_t>(__builtin_ctz(input_num));
|
return input_num == 0 ? 32 : static_cast<am_digits>(__builtin_ctz(input_num));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user