You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. If _d_ is *-∞*<sub>𝔻</sub>, return *"-Infinity"*.
1035
1037
1. If sign(_d_) = 1, let _signPrefix_ be *""*, else let _signPrefix_ be *"-"*.
1036
1038
1. If _d_ is *+0*<sub>𝔻</sub> or *-0*<sub>𝔻</sub>, then
1037
-
1. If _precision_ = 0, then
1038
-
1. Return *"0"*.
1039
+
1. If _precision_ = 1, then
1040
+
1. Return the string concatenation of _signPrefix_ and *"0"*.
1041
+
1. Else,
1042
+
1. Let _additionalZeroes_ be the string *"0"* repeated _precision_ times.
1043
+
1. Return the string concatenation of *"0"*, *"."*, and _additionalZeroes_.
1044
+
1. Let _q_ be the largest integer such that _d_ × 10<sup>−_q_</sup> is an integer.
1045
+
1. Let _n_ be _d_ × 10<sup>−_q_</sup>.
1046
+
1. Let _coefficient_ be the unique decimal representation of _n_ without leading zeroes.
1047
+
1. Let _numDigits_ be the string length of _coefficient_.
1048
+
1. If _numDigits_ < _precision_, then
1049
+
1. Let _s_ be Decimal128ToDecimalString(_d_).
1050
+
1. If _d_ is an integer, then
1051
+
1. Let _additionalZeroes_ be the string *"0"* repeated _precision_ - _numDigits_ times.
1052
+
1. Return the string concatenationof _coefficient_, *"."*, and _additionalZeroes_.
1039
1053
1. Otherwise:
1040
-
1. Let _extraZeroes_ be the string *"0"* repeated _precision_ times.
1041
-
1. Return the string concatenation of *"0"*, *"."*, and _extraZeroes_.
1042
-
1. Set _d_ to abs(_d_).
1043
-
1. Let _coefficient_ be _d_ × 10<sup>-q</sup>.
1044
-
1. Assert: _coefficient_ is an integer.
1045
-
1. Let _coefficientStr_ be the unique decimal string representation of _coefficient_ without leading zeroes.
1046
-
1. Let _firstDigit_ be the substring of _coefficientStr_ from 0 to 1.
1047
-
1. Let _remainingDigits_ be the substring of _coefficientStr_ from 1.
1048
-
1. Let _numCoefficientDigits_ be the length of _coefficientStr_.
1049
-
1. Let _m_ be the mantissa of _d_.
1050
-
1. Let _scaledM_ be _m_ × 10<sup>_numCoefficientDigits_</sup>.
1051
-
1. Let _fractionalPart_ be _scaledM_ mod 1.
1052
-
1. Let _e_ be the exponent of _d_.
1053
-
1. Let _eStr_ be the unique decimal string representation of _e_ without leading zeroes.
1054
-
1. If _numCoefficientDigits_ ≤ _numCoefficientDigits_, then
1055
-
1. Let _adjustedMantissa_ be _m_ - (_fractionalPart_ × 10<sup>-_numDigits</sup>).
1056
-
1. Assert: _adjustedMantissa_ is an integer.
1057
-
1. Let _adjustedMantissaStr_ be the unique decimal string representation of _adjustedMantissa_ without leading zeroes and without trailing zeroes.
1058
-
1. If _e_ ≥ 0, set _eStr_ to the concation of *"+"* and _eStr_.
1059
-
1. Return the concation of _signPrefix_, _adjustedMantissaStr_, *"e"*, and _eStr_.
1054
+
1. Let _additionalZeroes_ be the string *"0"* repeated _precision_ - _numDigits_ times.
1055
+
1. Return the string concatenationof _signPrefix, _s_ and _additionalZeroes_.
1056
+
1. Else if _numDigits_ = _precision_, then
1057
+
1. Return _coefficient_.
1060
1058
1. Otherwise:
1061
-
1. Let _extraZeroes_ be the string *"0"* repeated _numCoefficientDigits_ - 1 - _numCoefficientDigits_ times.
1062
-
1. Let _s_ be the string concatenation of _firstDigit_, *"."*, _remainingDigits_, _extraZeroes_, *"e"*, and _eStr_.
1063
-
1. Return _s_.
1059
+
1. Let _exp_ be _q_ + _precision_.
1060
+
1. Let _scaled_ be _d_ × 10<sup>-_exp_</sup>.
1061
+
1. Let _scaledAndRounded_ be ApplyRoundingModeToPositive(_scaled_, _roundingMode_).
1062
+
1. Assert: _scaledAndRounded_ is not an integer.
1063
+
1. Let _s_ be Decimal128ToDecimalString(_scaledAndRounded_).
1064
+
1. Let _renderedQ_ be the unique decimal string representation of _q_.
1065
+
1. Return the string concatenation of _signPrefix_, _s_, *"e"*, and _renderedQ_.
1064
1066
</emu-alg>
1065
1067
<emu-note>
1066
1068
<p>This operation follows the specification of the conversion of IEEE 754-2019 Decimal128 values to strings (external character sequences) discussed in Section 5.12 of <emu-xref href="#sec-bibliography">IEEE 754-2019</emu-xref>.</p>
0 commit comments