1.1.1 RoundToDecimal128Domain ( v [ , roundingMode ] )
The abstract operation RoundToDecimal128Domain takes argument v (a mathematical value) and optional argument roundingMode (a Decimal128 rounding mode) and returns +∞𝔻, -∞𝔻, +0𝔻, −0𝔻, or a mathematical value. It computes the closest approximation to a given mathematical value, rounded according to the given rounding mode, that is available within the limits of Decimal128. It performs the following steps when called:
- - If v = 0, return +0𝔻.
- If v < 0, then
- Let reverseRoundingMode be roundingMode.
- If roundingMode is "floor", set reverseRoundingMode to "ceil".
- If roundingMode is "ceil", set reverseRoundingMode to "floor".
- Let d be RoundToDecimal128Domain(–v, reverseRoundingMode).
- If d is +∞𝔻, return –∞𝔻.
- If d is +0𝔻, return −0𝔻.
- Assert: d is a mathematical value.
- Return –d.
- Let e be the unique integer such that 10e ≤ v < 10e+1.
- Let te be e − 33.
- If te < –6176, set te to –6176.
- Let m be v × 10–te.
- Let rounded be ApplyRoundingModeToPositive(m, roundingMode).
- If rounded = 1034, then
- Set te to te + 1.
- Set rounded = to 1033.
- If te > 6111, return +∞𝔻.
- If rounded = 0, return +0𝔻.
- Return rounded × 10te.
+ - If v = 0, return +0𝔻.
- If v < 0, then
- Let reverseRoundingMode be roundingMode.
- If roundingMode is "floor", set reverseRoundingMode to "ceil".
- If roundingMode is "ceil", set reverseRoundingMode to "floor".
- Let d be RoundToDecimal128Domain(–v, reverseRoundingMode).
- If d is +∞𝔻, return –∞𝔻.
- If d is +0𝔻, return −0𝔻.
- Assert: d is a mathematical value.
- Return –d.
- Let e be the unique integer such that 10e ≤ v < 10e+1.
- Let te be e − 33.
- If te < –6176, set te to –6176.
- Let m be v × 10–te.
- Let rounded be ApplyRoundingModeToPositive(m, roundingMode).
- If rounded = 1034, then
- Set te to te + 1.
- Set rounded to 1033.
- If te > 6111, return +∞𝔻.
- If rounded = 0, return +0𝔻.
- Return rounded × 10te.
1.1.1.1 ApplyRoundingModeToPositive ( m, roundingMode )