MCPcopy Create free account
hub / github.com/ablab/spades / convertFromDecimalString

Method convertFromDecimalString

ext/src/llvm/APFloat.cpp:2672–2791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2670}
2671
2672Expected<IEEEFloat::opStatus>
2673IEEEFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode) {
2674 decimalInfo D;
2675 opStatus fs;
2676
2677 /* Scan the text. */
2678 StringRef::iterator p = str.begin();
2679 if (Error Err = interpretDecimal(p, str.end(), &D))
2680 return std::move(Err);
2681
2682 /* Handle the quick cases. First the case of no significant digits,
2683 i.e. zero, and then exponents that are obviously too large or too
2684 small. Writing L for log 10 / log 2, a number d.ddddd*10^exp
2685 definitely overflows if
2686
2687 (exp - 1) * L >= maxExponent
2688
2689 and definitely underflows to zero where
2690
2691 (exp + 1) * L <= minExponent - precision
2692
2693 With integer arithmetic the tightest bounds for L are
2694
2695 93/28 < L < 196/59 [ numerator <= 256 ]
2696 42039/12655 < L < 28738/8651 [ numerator <= 65536 ]
2697 */
2698
2699 // Test if we have a zero number allowing for strings with no null terminators
2700 // and zero decimals with non-zero exponents.
2701 //
2702 // We computed firstSigDigit by ignoring all zeros and dots. Thus if
2703 // D->firstSigDigit equals str.end(), every digit must be a zero and there can
2704 // be at most one dot. On the other hand, if we have a zero with a non-zero
2705 // exponent, then we know that D.firstSigDigit will be non-numeric.
2706 if (D.firstSigDigit == str.end() || decDigitValue(*D.firstSigDigit) >= 10U) {
2707 category = fcZero;
2708 fs = opOK;
2709
2710 /* Check whether the normalized exponent is high enough to overflow
2711 max during the log-rebasing in the max-exponent check below. */
2712 } else if (D.normalizedExponent - 1 > INT_MAX / 42039) {
2713 fs = handleOverflow(rounding_mode);
2714
2715 /* If it wasn't, then it also wasn't high enough to overflow max
2716 during the log-rebasing in the min-exponent check. Check that it
2717 won't overflow min in either check, then perform the min-exponent
2718 check. */
2719 } else if (D.normalizedExponent - 1 < INT_MIN / 42039 ||
2720 (D.normalizedExponent + 1) * 28738 <=
2721 8651 * (semantics->minExponent - (int) semantics->precision)) {
2722 /* Underflow to zero and round. */
2723 category = fcNormal;
2724 zeroSignificand();
2725 fs = normalize(rounding_mode, lfLessThanHalf);
2726
2727 /* We can finally safely perform the max-exponent check. */
2728 } else if ((D.normalizedExponent - 1) * 42039
2729 >= 12655 * semantics->maxExponent) {

Callers

nothing calls this directly

Calls 7

interpretDecimalFunction · 0.85
decDigitValueFunction · 0.85
partCountForBitsFunction · 0.85
createErrorFunction · 0.85
normalizeFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected