Lines Matching +full:conversion +full:- +full:interval
1 //===----------------------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
15 // Boost Software License - Version 1.0 - August 17th, 2003
21 // Software, and to permit third-parties to whom the Software is furnished to
28 // works are solely in the form of machine-executable object code generated by
33 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
40 // clang-format off
111 return (__value & ((1u << __p) - 1)) == 0;
125 // On 32-bit platforms we can avoid a 64-bit shift-right since we only
132 const int32_t __s = __shift - 32;
133 return (__bits1Hi << (32 - __s)) | (__bits1Lo >> __s);
134 #else // ^^^ 32-bit ^^^ / vvv 64-bit vvv
136 const uint64_t __shiftedSum = __sum >> (__shift - 32);
139 #endif // ^^^ 64-bit ^^^
161 __e2 = 1 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
164 __e2 = static_cast<int32_t>(__ieeeExponent) - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS - 2;
170 // Step 2: Determine the interval of valid decimal representations.
173 // Implicit bool -> int conversion. True is 1, false is 0.
175 const uint32_t __mm = 4 * __m2 - 1 - __mmShift;
177 // Step 3: Convert to a decimal power base using 64-bit arithmetic.
186 const int32_t __k = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q)) - 1;
187 const int32_t __i = -__e2 + static_cast<int32_t>(__q) + __k;
191 if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
193 // __q = X - 1 above, except that would require 33 bits for the result, and we've found that
194 // 32-bit arithmetic is faster even on 64-bit machines.
195 const int32_t __l = __FLOAT_POW5_INV_BITCOUNT + __pow5bits(static_cast<int32_t>(__q - 1)) - 1;
196 __lastRemovedDigit = static_cast<uint8_t>(__mulPow5InvDivPow2(__mv, __q - 1,
197 -__e2 + static_cast<int32_t>(__q) - 1 + __l) % 10);
207 __vp -= __multipleOfPowerOf5(__mp, __q);
211 const uint32_t __q = __log10Pow5(-__e2);
213 const int32_t __i = -__e2 - static_cast<int32_t>(__q);
214 const int32_t __k = __pow5bits(__i) - __FLOAT_POW5_BITCOUNT;
215 int32_t __j = static_cast<int32_t>(__q) - __k;
219 if (__q != 0 && (__vp - 1) / 10 <= __vm / 10) {
220 __j = static_cast<int32_t>(__q) - 1 - (__pow5bits(__i + 1) - __FLOAT_POW5_BITCOUNT);
228 // __mm = __mv - 1 - __mmShift, so it has 1 trailing 0 bit iff __mmShift == 1.
232 --__vp;
235 __vrIsTrailingZeros = __multipleOfPowerOf2(__mv, __q - 1);
239 // Step 4: Find the shortest decimal representation in the interval of valid representations.
245 #ifdef __clang__ // TRANSITION, LLVM-23106
246 __vmIsTrailingZeros &= __vm - (__vm / 10) * 10 == 0;
300 // For nonzero integers, _Exponent2 >= -23. (The minimum value occurs when _Mantissa2 * 2^_Exponent2 is 1.
301 // In that case, _Mantissa2 is the implicit 1 bit followed by 23 zeros, so _Exponent2 is -23 to shift away
303 // (as positive exponents make the range non-dense). For that dense range, Ryu will always be used:
306 // Positive exponents are the non-dense range of exactly representable integers.
307 // This contains all of the values for which Ryu can't be used (and a few Ryu-friendly values).
317 // 24 + 104 equals 128 equals 4 * 32, so we need exactly 4 32-bit elements.
318 // We use a little-endian representation, visualized like this:
330 uint32_t _Maxidx = ((24 + static_cast<uint32_t>(_Exponent2) + 31) / 32) - 1;
337 _Data[_Maxidx - 1] = _Mantissa2 << _Bit_shift;
338 _Data[_Maxidx] = _Mantissa2 >> (32 - _Bit_shift);
348 // _Blocks[_Filled_blocks - 1], ..., _Blocks[0] will be 0-filled 9-digit blocks.
364 --_Idx; // Initially, _Remainder is at most 10^9 - 1.
366 // Now, _Remainder is at most (10^9 - 1) * 2^32 + 2^32 - 1, simplified to 10^9 * 2^32 - 1.
369 // floor((10^9 * 2^32 - 1) / 10^9) == 2^32 - 1, so uint32_t _Quotient is lossless.
372 // _Remainder is at most 10^9 - 1 again.
374 _Remainder = static_cast<uint32_t>(_Remainder) - 1000000000u * _Quotient;
379 // Store a 0-filled 9-digit block.
383 --_Maxidx; // log2(10^9) is 29.9, so we can't shrink by more than one element.
399 if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
410 // Print 0-filled 9-digit blocks.
411 for (int32_t _Idx = _Filled_blocks - 1; _Idx >= 0; --_Idx) {
425 int32_t _Scientific_exponent = _Ryu_exponent + static_cast<int32_t>(__olength) - 1;
433 // 1e-3 | "0.001" | "1e-03"
435 _Lower = -3;
439 // 1234e-7 | "0.0001234" | "1.234e-04"
441 _Lower = -static_cast<int32_t>(__olength + 3);
453 // Then, if a conversion with style E would have an exponent of X:
454 // - if P > X >= -4, the conversion is with style f [...].
455 // - otherwise, the conversion is with style e [...]."
456 if (-4 <= _Scientific_exponent && _Scientific_exponent < 6) {
467 // --------------|----------|---------------|----------------------|---------------------------------------
470 // --------------|----------|---------------|----------------------|---------------------------------------
472 // --------------|----------|---------------|----------------------|---------------------------------------
473 // -1 | 172.9 | 3 | __olength + 1 | This case can't happen for
474 // -2 | 17.29 | 2 | | __olength == 1, but no additional
475 // -3 | 1.729 | 1 | | code is needed to avoid it.
476 // --------------|----------|---------------|----------------------|---------------------------------------
477 // -4 | 0.1729 | 0 | 2 - _Ryu_exponent | C11 7.21.6.1 "The fprintf function"/8:
478 // -5 | 0.01729 | -1 | | "If a decimal-point character appears,
479 // -6 | 0.001729 | -2 | | at least one digit appears before it."
492 _Total_fixed_length -= _Adjustment[_Ryu_exponent];
498 _Total_fixed_length = static_cast<uint32_t>(2 - _Ryu_exponent);
501 if (_Last - _First < static_cast<ptrdiff_t>(_Total_fixed_length)) {
517 // with 9 decimal digits, which is float's round-trip limit.)
519 // Normalization adds [2, 23] (aside: at least 2 because the pre-normalized mantissa is at least 5).
525 // (That's not a problem for round-tripping, because X is close enough to the original float,
526 // but X isn't mathematically equal to the original float.) This requires a high-precision fallback.
529 // need to re-synthesize it; the original float must have been X, because Ryu wouldn't produce the
530 // same output for two different floats X and Y). This allows Ryu's output to be used (zero-filled).
532 // (2^24 - 1) / 5^0 (for indexing), (2^24 - 1) / 5^1, ..., (2^24 - 1) / 5^10
545 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
552 // Print the decimal digits, left-aligned within [_First, _First + _Total_fixed_length).
555 // Print the decimal digits, right-aligned within [_First, _First + _Total_fixed_length).
560 #ifdef __clang__ // TRANSITION, LLVM-38217
561 const uint32_t __c = _Output - 10000 * (_Output / 10000);
568 std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c0, 2);
569 std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c1, 2);
574 std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
578 std::memcpy(_Mid -= 2, __DIGIT_TABLE + __c, 2);
580 *--_Mid = static_cast<char>('0' + _Output);
596 std::memset(_First + 2, '0', static_cast<size_t>(-_Whole_digits));
604 if (_Last - _First < static_cast<ptrdiff_t>(_Total_scientific_length)) {
612 #ifdef __clang__ // TRANSITION, LLVM-38217
613 const uint32_t __c = _Output - 10000 * (_Output / 10000);
620 std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c0, 2);
621 std::memcpy(__result + __olength - __i - 3, __DIGIT_TABLE + __c1, 2);
627 std::memcpy(__result + __olength - __i - 1, __DIGIT_TABLE + __c, 2);
651 __result[__index++] = '-';
652 _Scientific_exponent = -_Scientific_exponent;
666 // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
672 if (_Last - _First < 5) {
692 const uint32_t __ieeeMantissa = __bits & ((1u << __FLOAT_MANTISSA_BITS) - 1);
695 // When _Fmt == chars_format::fixed and the floating-point number is a large integer,
700 - __FLOAT_BIAS - __FLOAT_MANTISSA_BITS; // bias and normalization
716 // clang-format on