File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -1293,6 +1293,15 @@ function getBI(obj) {
1293
1293
return obj . $$getBignum ( ) ;
1294
1294
}
1295
1295
1296
+ function getIntFromBI ( bignum ) {
1297
+ const bits = bignum . bitLength ( ) ;
1298
+ if ( bits >= 64 ) {
1299
+ throw new NQPException ( `Cannot unbox ${ bits } bit wide bigint into native integer` ) ;
1300
+ } else {
1301
+ return bignum . toNumber ( ) | 0 ;
1302
+ }
1303
+ }
1304
+
1296
1305
class P6bigint extends REPR {
1297
1306
setupSTable ( STable ) {
1298
1307
STable . addInternalMethods ( class {
@@ -1301,7 +1310,7 @@ class P6bigint extends REPR {
1301
1310
}
1302
1311
1303
1312
$$getInt ( ) {
1304
- return this . value . toNumber ( ) | 0 ;
1313
+ return getIntFromBI ( this . value ) ;
1305
1314
}
1306
1315
1307
1316
$$setBignum ( value ) {
@@ -1313,7 +1322,7 @@ class P6bigint extends REPR {
1313
1322
}
1314
1323
1315
1324
$$decont_i ( ctx ) {
1316
- return this . value . toNumber ( ) | 0 ;
1325
+ return getIntFromBI ( this . value ) ;
1317
1326
}
1318
1327
} ) ;
1319
1328
}
@@ -1377,11 +1386,11 @@ class P6bigint extends REPR {
1377
1386
}
1378
1387
1379
1388
$$getInt ( ) {
1380
- return this [ name ] . toNumber ( ) | 0 ;
1389
+ return getIntFromBI ( this [ name ] ) ;
1381
1390
}
1382
1391
1383
1392
$$decont_i ( ctx ) {
1384
- return this [ name ] . toNumber ( ) | 0 ;
1393
+ return getIntFromBI ( this [ name ] ) ;
1385
1394
}
1386
1395
1387
1396
$$getBignum ( ) {
You can’t perform that action at this time.
0 commit comments