Skip to content

Commit

Permalink
Make defloat error reporting more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Dec 12, 2023
1 parent 52466cc commit 84d68e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/fraction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,10 @@ describe('Fraction', () => {
const fraction = new Fraction(13, 11);
expect(fraction.divisible('conquer')).toBe(false);
});

it('gives the correct error for too large components', () => {
expect(() => new Fraction(1.1231233477899796e16, 1)).toThrowError(
'Numerator above safe limit'
);
});
});
3 changes: 3 additions & 0 deletions src/fraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export class Fraction {
}
x = 1 / (x - coef);
}
if (!coefs.length) {
throw new Error('Numerator above safe limit');
}
let n = coefs.pop()!;
let d = 1;
while (coefs.length) {
Expand Down

0 comments on commit 84d68e8

Please sign in to comment.