1#ifndef FASTFLOAT_DECIMAL_TO_BINARY_H
2#define FASTFLOAT_DECIMAL_TO_BINARY_H
19template <
int bit_precision>
27 static_assert((bit_precision >= 0) && (bit_precision <= 64),
" precision should be in (0,64]");
28 constexpr uint64_t precision_mask = (bit_precision < 64) ?
29 (uint64_t(0xFFFFFFFFFFFFFFFF) >> bit_precision)
30 : uint64_t(0xFFFFFFFFFFFFFFFF);
31 if((firstproduct.
high & precision_mask) == precision_mask) {
34 firstproduct.
low += secondproduct.
high;
35 if(secondproduct.
high > firstproduct.
low) {
59 return (((152170 + 65536) * q) >> 16) + 63;
65template <
typename binary>
68 int hilz = int(w >> 63) ^ 1;
71 int bias = binary::mantissa_explicit_bits() - binary::minimum_exponent();
78template <
typename binary>
83 value128 product = compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
84 return compute_error_scaled<binary>(q, product.
high, lz);
92template <
typename binary>
96 if ((w == 0) || (q < binary::smallest_power_of_ten())) {
102 if (q > binary::largest_power_of_ten()) {
104 answer.
power2 = binary::infinite_power();
119 value128 product = compute_product_approximation<binary::mantissa_explicit_bits() + 3>(q, w);
120 if(product.
low == 0xFFFFFFFFFFFFFFFF) {
124 const bool inside_safe_exponent = (q >= -27) && (q <= 55);
126 if(!inside_safe_exponent) {
127 return compute_error_scaled<binary>(q, product.
high, lz);
134 int upperbit = int(product.
high >> 63);
136 answer.
mantissa = product.
high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
138 answer.
power2 = int32_t(
detail::power(int32_t(q)) + upperbit - lz - binary::minimum_exponent());
141 if(-answer.
power2 + 1 >= 64) {
160 answer.
power2 = (answer.
mantissa < (uint64_t(1) << binary::mantissa_explicit_bits())) ? 0 : 1;
167 if ((product.
low <= 1) && (q >= binary::min_exponent_round_to_even()) && (q <= binary::max_exponent_round_to_even()) &&
172 if((answer.
mantissa << (upperbit + 64 - binary::mantissa_explicit_bits() - 3)) == product.
high) {
179 if (answer.
mantissa >= (uint64_t(2) << binary::mantissa_explicit_bits())) {
180 answer.
mantissa = (uint64_t(1) << binary::mantissa_explicit_bits());
184 answer.
mantissa &= ~(uint64_t(1) << binary::mantissa_explicit_bits());
185 if (answer.
power2 >= binary::infinite_power()) {
186 answer.
power2 = binary::infinite_power();
#define fastfloat_really_inline
constexpr fastfloat_really_inline int32_t power(int32_t q) noexcept
fastfloat_really_inline int leading_zeroes(uint64_t input_num)
static constexpr int32_t invalid_am_bias
fastfloat_really_inline value128 compute_product_approximation(int64_t q, uint64_t w)
fastfloat_really_inline adjusted_mantissa compute_error(int64_t q, uint64_t w) noexcept
fastfloat_really_inline adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept
fastfloat_really_inline value128 full_multiplication(uint64_t a, uint64_t b)
fastfloat_really_inline adjusted_mantissa compute_error_scaled(int64_t q, uint64_t w, int lz) noexcept
static constexpr int smallest_power_of_five
static const uint64_t power_of_five_128[number_of_entries]