Skip to content

Commit a5fba16

Browse files
committed
Fix bugs in toFixed
1 parent 87e7520 commit a5fba16

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

spec.emu

+6-15
Original file line numberDiff line numberDiff line change
@@ -988,21 +988,12 @@ location: https://github.com/tc39/proposal-decimal/
988988
1. Set _d_ to abs(_d_).
989989
1. Let _scaledV_ be _d_ × 10<sup>_numDigits_</sup>.
990990
1. Let _roundedScaledV_ be ApplyRoundingModeToPositive(_scaledV_, _roundingMode_).
991-
1. Let _s_ be the unique decimal string representation of _roundedScaledV_ without leading zeroes.
992-
1. Let _integerDigits_ be _s_.
993-
1. Let _nonIntegerDigits_ be *""*.
994-
1. If _s_ contains an occurrence of *"."*, then
995-
1. Let _i_ be the index of the first occurrence of *"."* in _s_.
996-
1. Set _integerDigits_ to the substring of _s_ from 0 to _i_.
997-
1. Set _nonIntegerDigits_ to the substring of _s_ from _i_ + 1.
998-
1. If _numDigits_ = 0, return _integerDigits_.
999-
1. Let _numNonIntegerDigits_ be the length of _nonIntegerDigits_.
1000-
1. If the _numNonIntegerDigits_ < _numDigits_, then
1001-
1. Let _additionalZeroes_ be the string *"0"* repeated _numDigits_ - _numNonIntegerDigits_ times.
1002-
1. Set _nonIntegerDigits_ to the concatenation of _nonIntegerDigits_ and _additionalZeroes_.
1003-
1. Else if _numNonIntegerDigits_ > _numDigits_, then
1004-
1. Set _nonIntegerDigits_ to the substring of _nonIntegerDigits_ from 0 to _numDigits_.
1005-
1. Return the concatenation of _signPrefix_, _integerDigits_, *"."*, and _nonIntegerDigits_.
991+
1. Let _remainder_ be _scaledV_ - _roundedScaledV_.
992+
1. Let _remainderStr_ be Decimal128ToDecimalString(_remainder_).
993+
1. Let _integerDigits_ be the unique decimal string representation of _roundedScaledV_ without leading zeroes.
994+
1. Let _nonIntegerDigits_ be the substring of _remainderStr_ from 0 to _numDigits_ + 1.
995+
1. Let _s_ be the concatenation of _signPrefix_, _integerDigits_, *"."*, and _nonIntegerDigits_.
996+
1. Return CanonicalizeDecimalString(_s_).
1006997
</emu-alg>
1007998
<emu-note>
1008999
<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

Comments
 (0)