| 3687 | } |
| 3688 | |
| 3689 | void IEEEFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision, |
| 3690 | unsigned FormatMaxPadding, bool TruncateZero) const { |
| 3691 | switch (category) { |
| 3692 | case fcInfinity: |
| 3693 | if (isNegative()) |
| 3694 | return append(Str, "-Inf"); |
| 3695 | else |
| 3696 | return append(Str, "+Inf"); |
| 3697 | |
| 3698 | case fcNaN: return append(Str, "NaN"); |
| 3699 | |
| 3700 | case fcZero: |
| 3701 | if (isNegative()) |
| 3702 | Str.push_back('-'); |
| 3703 | |
| 3704 | if (!FormatMaxPadding) { |
| 3705 | if (TruncateZero) |
| 3706 | append(Str, "0.0E+0"); |
| 3707 | else { |
| 3708 | append(Str, "0.0"); |
| 3709 | if (FormatPrecision > 1) |
| 3710 | Str.append(FormatPrecision - 1, '0'); |
| 3711 | append(Str, "e+00"); |
| 3712 | } |
| 3713 | } else |
| 3714 | Str.push_back('0'); |
| 3715 | return; |
| 3716 | |
| 3717 | case fcNormal: |
| 3718 | break; |
| 3719 | } |
| 3720 | |
| 3721 | if (isNegative()) |
| 3722 | Str.push_back('-'); |
| 3723 | |
| 3724 | // Decompose the number into an APInt and an exponent. |
| 3725 | int exp = exponent - ((int) semantics->precision - 1); |
| 3726 | APInt significand(semantics->precision, |
| 3727 | makeArrayRef(significandParts(), |
| 3728 | partCountForBits(semantics->precision))); |
| 3729 | |
| 3730 | // Set FormatPrecision if zero. We want to do this before we |
| 3731 | // truncate trailing zeros, as those are part of the precision. |
| 3732 | if (!FormatPrecision) { |
| 3733 | // We use enough digits so the number can be round-tripped back to an |
| 3734 | // APFloat. The formula comes from "How to Print Floating-Point Numbers |
| 3735 | // Accurately" by Steele and White. |
| 3736 | // FIXME: Using a formula based purely on the precision is conservative; |
| 3737 | // we can print fewer digits depending on the actual value being printed. |
| 3738 | |
| 3739 | // FormatPrecision = 2 + floor(significandBits / lg_2(10)) |
| 3740 | FormatPrecision = 2 + semantics->precision * 59 / 196; |
| 3741 | } |
| 3742 | |
| 3743 | // Ignore trailing binary zeros. |
| 3744 | int trailingZeros = significand.countTrailingZeros(); |
| 3745 | exp += trailingZeros; |
| 3746 | significand.lshrInPlace(trailingZeros); |
nothing calls this directly
no test coverage detected