Lines Matching +full:zero +full:- +full:point
1 //===-- Utilities to convert floating point values to string ----*- C++ -*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
25 // This file has 5 compile-time flags to allow the user to configure the float
33 // multiplying/dividing the written-out number by 10^9 to get blocks. It's
36 // of the digits above the decimal point, making it inefficient for %e calls
47 // Dyadic floats are software floating point numbers, and their accuracy can be
84 // Ulf Adams. 2019. Ryƫ revisited: printf floating point conversion.
92 // We want to calculate a 9 digit segment of a floating point number using this
136 // of -2 (which becomes -54 when we shift the mantissa to be a non-fractional
158 // always accurate. This is used to calculate the maximum number of base-10
159 // digits a given e-bit number could have.
165 return (num + (denom - 1)) / denom;
176 // The formula for the table when i is positive (or zero) is as follows:
177 // floor(10^(-9i) * 2^(e + c_1) + 1) % (10^9 * 2^c_1)
179 // floor(5^(-9i) * 2^(e + c_1 - 9i) + 1) % (10^9 * 2^c_1)
192 static_cast<int>(exponent + CALC_SHIFT_CONST - (BLOCK_SIZE * i));
226 // calculation as above. Due to floating point imprecision it is only accurate
232 static_cast<int>(exponent + CALC_SHIFT_CONST - (9 * i));
246 Sign::POS, -276, FIVE_EXP_MINUS_NINE_MANT);
271 // The formula for the table when i is negative (or zero) is as follows:
272 // floor(10^(-9i) * 2^(c_0 - e)) % (10^9 * 2^c_0)
278 // floor(10^(9*(-i)) * 2^(c_0 + (-e))) % (10^9 * 2^c_0)
281 int shift_amount = CALC_SHIFT_CONST - exponent;
290 int block_shifts = (-shift_amount) / BLOCK_SIZE;
292 ten_blocks = ten_blocks - block_shifts;
320 num = num >> (-shift_amount);
336 // calculation as above. Due to floating point imprecision it is only accurate
342 int shift_amount = CALC_SHIFT_CONST - exponent;
389 // Convert floating point values to their string representation.
396 // of blocks there are before the decimal point. Now the client code can start
398 // zero. This will give all digits before the decimal point. Then the user can
402 // be zero after the decimal point and before the non-zero digits. Additionally,
403 // is_lowest_block will return if the current block is the lowest non-zero
420 exponent -= FRACTION_LEN;
432 if (exponent >= -FRACTION_LEN) {
439 : static_cast<uint32_t>(exponent + (IDX_SIZE - 1)) / IDX_SIZE;
441 // shift_amount = -(c0 - exponent) = c_0 + 16 * ceil(exponent/16) -
449 // ----------------------- DYADIC FLOAT CALC MODE ------------------------
454 // ---------------------------- INT CALC MODE ----------------------------
457 pos_exp + CALC_SHIFT_CONST - (BLOCK_SIZE * block_index);
477 // ----------------------------- TABLE MODE ------------------------------
482 const uint32_t shift_amount = SHIFT_CONST + pos_exp - exponent;
494 const int32_t idx = -exponent / IDX_SIZE;
501 // ----------------------- DYADIC FLOAT CALC MODE ------------------------
505 // ---------------------------- INT CALC MODE ----------------------------
529 // ----------------------------- TABLE MODE ------------------------------
530 // if the requested block is zero
535 const uint32_t p = POW10_OFFSET_2[idx] + block_index - MIN_BLOCK_2[idx];
536 // If every digit after the requested block is zero.
544 SHIFT_CONST + (-exponent - static_cast<int32_t>(pos_exp));
557 return get_negative_block(-1 - block_index);
562 if (exponent < -FRACTION_LEN)
567 : static_cast<uint32_t>(exponent + (IDX_SIZE - 1)) / IDX_SIZE;
571 // This takes the index of a block after the decimal point (a negative block)
572 // and return if it's sure that all of the digits after it are zero.
575 // The decimal representation of 2**(-i) will have exactly i digits after
576 // the decimal point.
580 return num_requested_digits > -exponent;
582 const int32_t idx = -exponent / IDX_SIZE;
584 POW10_OFFSET_2[idx] + negative_block_index - MIN_BLOCK_2[idx];
592 if (exponent < -FRACTION_LEN) {
593 const int pos_exp = -exponent - 1;
595 static_cast<uint32_t>(pos_exp + (IDX_SIZE - 1)) / IDX_SIZE;
596 const int32_t pos_len = ((internal::ceil_log10_pow2(pos_idx * IDX_SIZE) -
598 BLOCK_SIZE) -
604 return MIN_BLOCK_2[-exponent / IDX_SIZE];
611 // --------------------------- LONG DOUBLE FUNCTIONS ---------------------------
615 // constants should be calculated to be correct for any provided floating point
629 internal::div_ceil(fputil::FPBits<long double>::MAX_BIASED_EXPONENT -
639 // float_as_fixed represents the floating point number as a fixed point number
640 // with the point EXTRA_INT_WIDTH bits from the left of the number. This can
677 // point. In this case we represent the float as an integer, then divide
698 // below the decimal point. In this case we represent the float as a fixed
699 // point number with the decimal point after the top EXTRA_INT_WIDTH bits.
706 // If there are still digits above the decimal point, handle those.
720 // Zero all digits above the decimal point.
735 exponent -= FRACTION_LEN;
737 this->init_convert();
741 if (exponent < -FRACTION_LEN)
747 : static_cast<uint32_t>(exponent + (IDX_SIZE - 1)) / IDX_SIZE;
753 return MIN_BLOCK_2[-exponent / IDX_SIZE];
755 if (exponent >= -FRACTION_LEN)
758 const int pos_exp = -exponent - 1;
760 static_cast<uint32_t>(pos_exp + (IDX_SIZE - 1)) / IDX_SIZE;
761 const int32_t pos_len = ((internal::ceil_log10_pow2(pos_idx * IDX_SIZE) -
763 BLOCK_SIZE) -
770 // The decimal representation of 2**(-i) will have exactly i digits after
771 // the decimal point.
775 return num_requested_digits > -exponent;
779 if (exponent < -FRACTION_LEN)
794 // point, and 1 with the second and so on. This converts to the same
797 const int block_index = -1 - negative_block_index;
817 --int_block_index;
828 return get_negative_block(-1 - block_index);