Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add missing typename for older c++ versions/compiler, rename type to …
…parsing_type
  • Loading branch information
jrahlf committed Sep 12, 2021
commit fe2be46deda95e63c4ec0fd9b58b32f663ac6f65
8 changes: 4 additions & 4 deletions include/fast_float/decimal_to_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ namespace fast_float {
template <int bit_precision>
CXX20_CONSTEXPR fastfloat_really_inline
value128 compute_product_approximation(int64_t q, uint64_t w) {
using type = std::conditional<bit_precision <= 26, float, double>::type;
const int index = 2 * int(q - powers_of_five_count<type>::smallest_power_of_five);
using parsing_type = typename std::conditional<bit_precision <= 26, float, double>::type;
const int index = 2 * int(q - powers_of_five_count<parsing_type>::smallest_power_of_five);
// For small values of q, e.g., q in [0,27], the answer is always exact because
// The line value128 firstproduct = full_multiplication(w, power_of_five_128[index]);
// gives the exact answer.
value128 firstproduct = full_multiplication(w, powers<type>::power_of_five_128[index]);
value128 firstproduct = full_multiplication(w, powers<parsing_type>::power_of_five_128[index]);
static_assert((bit_precision >= 0) && (bit_precision <= 64), " precision should be in (0,64]");
constexpr uint64_t precision_mask = (bit_precision < 64) ?
(uint64_t(0xFFFFFFFFFFFFFFFF) >> bit_precision)
: uint64_t(0xFFFFFFFFFFFFFFFF);
if((firstproduct.high & precision_mask) == precision_mask) { // could further guard with (lower + w < lower)
// regarding the second product, we only need secondproduct.high, but our expectation is that the compiler will optimize this extra work away if needed.
value128 secondproduct = full_multiplication(w, powers<type>::power_of_five_128[index + 1]);
value128 secondproduct = full_multiplication(w, powers<parsing_type>::power_of_five_128[index + 1]);
firstproduct.low += secondproduct.high;
if(secondproduct.high > firstproduct.low) {
firstproduct.high++;
Expand Down