Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
Use proper rounding name
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama committed May 7, 2024
1 parent 5ead135 commit 02c0f5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/decimal128.mts
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ function adjustNonInteger(
options: FullySpecifiedConstructorOptions
): SignedSignificandExponent {
switch (options.roundingMode) {
case ROUNDING_MODE_HALF_EVEN:
return roundHalfEven(x);
case ROUNDING_MODE_CEILING:
return roundCeiling(x);
case ROUNDING_MODE_FLOOR:
Expand Down
4 changes: 2 additions & 2 deletions tests/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ describe("rounding options", () => {
roundTowardNegative: "-1234567890123456789012345678901235",
roundTowardZero: "-1234567890123456789012345678901234",
roundTiesToEven: "-1234567890123456789012345678901234",
roundTiesAway: "-1234567890123456789012345678901234",
roundTiesToAway: "-1234567890123456789012345678901235",
};
for (const [mode, expected] of Object.entries(answers)) {
test(`constructor with rounding mode "${mode}"`, () => {
Expand All @@ -483,7 +483,7 @@ describe("rounding options", () => {
roundTowardNegative: "-1234567890123456789012345678901240",
roundTowardZero: "-1234567890123456789012345678901239",
roundTiesToEven: "-1234567890123456789012345678901240",
roundTiesAway: "-1234567890123456789012345678901240",
roundTiesToAway: "-1234567890123456789012345678901240",
};
for (const [mode, expected] of Object.entries(roundUpAnswers)) {
test(`constructor with rounding mode "${mode}"`, () => {
Expand Down
27 changes: 27 additions & 0 deletions tests/round.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,33 @@ describe("Intl.NumberFormat examples", () => {
).toStrictEqual("1");
});
});
describe("halfExpand", () => {
test("-1.5", () => {
expect(
minusOnePointFive.round(0, "roundTiesToAway").toString()
).toStrictEqual("-2");
});
test("0.4", () => {
expect(
zeroPointFour.round(0, "roundTiesToAway").toString()
).toStrictEqual("0");
});
test("0.5", () => {
expect(
zeroPointFive.round(0, "roundTiesToAway").toString()
).toStrictEqual("1");
});
test("0.6", () => {
expect(
zeroPointSix.round(0, "roundTiesToAway").toString()
).toStrictEqual("1");
});
test("1.5", () => {
expect(
onePointFive.round(0, "roundTiesToAway").toString()
).toStrictEqual("2");
});
});
describe("halfEven", () => {
test("-1.5", () => {
expect(
Expand Down

0 comments on commit 02c0f5a

Please sign in to comment.