Skip to content

Commit ea24658

Browse files
✨ feat(limits): Rely on existing constants.
1 parent 674a275 commit ea24658

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/_limits.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// The range of valid numbers is -2^53 to 2^53 - 1
2-
export const MAX_NUMBER = Math.pow(2,53) - 1 ;
3-
export const MIN_NUMBER = -Math.pow(2,53) ;
1+
export const MAX_NUMBER = Number.MAX_SAFE_INTEGER ;
2+
export const MIN_NUMBER = Number.MIN_SAFE_INTEGER ;
43
export const MIN_BASE = 2 ;
54
export const MAX_BASE = Math.floor(Math.sqrt(MAX_NUMBER+1)) | 0;

test/src/Integer/toNumber.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function macro ( t , number ) {
1313

1414
macro.title = ( providedTitle , number ) => `toNumber: ${number}` ;
1515

16-
function throws ( t , string ) {
17-
const integer = ZZ.from(string) ;
18-
t.is(string, integer.toString()) ;
16+
function throws ( t , string , plus ) {
17+
const integer = ZZ.from(string).addn(plus) ;
18+
t.is(string, integer.subn(plus).toString()) ;
1919
t.throws(() => integer.toNumber(), { instanceOf: ValueError }) ;
2020
}
2121

@@ -34,12 +34,14 @@ once(1);
3434
once(-1);
3535
once(MIN_NUMBER);
3636
once(MAX_NUMBER);
37+
once(MIN_NUMBER+1);
38+
once(MAX_NUMBER-1);
3739

3840
while ( tested.size < N ) {
3941
const number = randint(MIN_NUMBER, MAX_NUMBER + 1) ;
4042
if ( tested.has(number) ) continue ;
4143
once(number) ;
4244
}
4345

44-
test( throws , '9007199254740992' ) ;
45-
test( throws , '-9007199254740993' ) ;
46+
test( throws , MAX_NUMBER.toString() , +1 ) ;
47+
test( throws , MIN_NUMBER.toString() , -1 ) ;

0 commit comments

Comments
 (0)