Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compat/_internal/decimalAdjust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function decimalAdjust(
number = '-0';
}
precision = Math.min(Number.parseInt(precision as string, 10), 292);
if (precision) {
if (precision && Number.isFinite(Number(number))) {
const [magnitude, exponent = 0] = number.toString().split('e');
let adjustedValue: string | number = Math[type](Number(`${magnitude}e${Number(exponent) + precision}`));
if (Object.is(adjustedValue, -0)) {
Expand Down
8 changes: 8 additions & 0 deletions src/compat/math/ceil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@
const expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];

// eslint-disable-next-line prefer-spread
const actual = values.map(args => 1 / ceil.apply(undefined, args as any));

Check warning on line 67 in src/compat/math/ceil.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

expect(actual).toEqual(expected);
});

it(`\`ceil\` should return \`Infinity\` for infinite values regardless of \`precision\``, () => {
expect(ceil(Infinity)).toBe(Infinity);
expect(ceil(Infinity, 2)).toBe(Infinity);
expect(ceil(-Infinity, 2)).toBe(-Infinity);
expect(ceil(Infinity, -2)).toBe(Infinity);
expect(ceil(-Infinity, -2)).toBe(-Infinity);
});

it(`\`ceil\` should handle edge cases`, () => {
expect(ceil(1.797, 295)).toBe(1.797);
expect(ceil(1.797, -295)).toBe(1e295);
Expand Down
8 changes: 8 additions & 0 deletions src/compat/math/floor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@
const expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];

// eslint-disable-next-line prefer-spread
const actual = values.map(args => 1 / floor.apply(undefined, args as any));

Check warning on line 67 in src/compat/math/floor.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

expect(actual).toEqual(expected);
});

it(`\`floor\` should return \`Infinity\` for infinite values regardless of \`precision\``, () => {
expect(floor(Infinity)).toBe(Infinity);
expect(floor(Infinity, 2)).toBe(Infinity);
expect(floor(-Infinity, 2)).toBe(-Infinity);
expect(floor(Infinity, -2)).toBe(Infinity);
expect(floor(-Infinity, -2)).toBe(-Infinity);
});

it(`\`floor\` should handle edge cases`, () => {
expect(floor(1.797, 295)).toBe(1.797);
expect(floor(1.797, -295)).toBe(0);
Expand Down
8 changes: 8 additions & 0 deletions src/compat/math/round.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
const expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity];

// eslint-disable-next-line prefer-spread
const actual = values.map(args => 1 / round.apply(undefined, args as any));

Check warning on line 64 in src/compat/math/round.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

expect(actual).toEqual(expected);
});
Expand All @@ -75,6 +75,14 @@
expect(actual).toEqual(expected);
});

it(`\`round\` should return \`Infinity\` for infinite values regardless of \`precision\``, () => {
expect(round(Infinity)).toBe(Infinity);
expect(round(Infinity, 2)).toBe(Infinity);
expect(round(-Infinity, 2)).toBe(-Infinity);
expect(round(Infinity, -2)).toBe(Infinity);
expect(round(-Infinity, -2)).toBe(-Infinity);
});

it(`\`round\` should handle edge cases`, () => {
expect(round(1.797, 295)).toBe(1.797);
expect(round(1.797, -295)).toBe(0);
Expand Down