@@ -1016,8 +1016,9 @@ function toRational(isNegative: boolean, sg: string, exp: number): Rational {
1016
1016
}
1017
1017
1018
1018
export class Decimal128 {
1019
- private readonly significand : string ;
1020
- private readonly exponent : number ;
1019
+ public readonly significand : string ;
1020
+ public readonly exponent : number ;
1021
+ public readonly isFinite : boolean ;
1021
1022
private readonly isNegative : boolean ;
1022
1023
private readonly rat ;
1023
1024
@@ -1044,6 +1045,9 @@ export class Decimal128 {
1044
1045
this . isNegative = data . isNegative ;
1045
1046
this . exponent = data . exponent ;
1046
1047
this . significand = data . significand ;
1048
+ this . isFinite =
1049
+ data . significand !== POSITIVE_INFINITY &&
1050
+ data . significand !== NEGATIVE_INFINITY ;
1047
1051
1048
1052
this . rat = toRational ( this . isNegative , this . significand , this . exponent ) ;
1049
1053
}
@@ -1052,11 +1056,6 @@ export class Decimal128 {
1052
1056
return this . significand === NAN ;
1053
1057
}
1054
1058
1055
- private isFinite ( ) : boolean {
1056
- let sig = this . significand ;
1057
- return sig !== POSITIVE_INFINITY && sig !== NEGATIVE_INFINITY ;
1058
- }
1059
-
1060
1059
/**
1061
1060
* Returns a digit string representing this Decimal128.
1062
1061
*/
@@ -1067,7 +1066,7 @@ export class Decimal128 {
1067
1066
return NAN ;
1068
1067
}
1069
1068
1070
- if ( ! this . isFinite ( ) ) {
1069
+ if ( ! this . isFinite ) {
1071
1070
return ( this . isNegative ? "-" : "" ) + POSITIVE_INFINITY ;
1072
1071
}
1073
1072
@@ -1191,8 +1190,8 @@ export class Decimal128 {
1191
1190
return undefined ;
1192
1191
}
1193
1192
1194
- if ( ! this . isFinite ( ) ) {
1195
- if ( ! x . isFinite ( ) ) {
1193
+ if ( ! this . isFinite ) {
1194
+ if ( ! x . isFinite ) {
1196
1195
if ( this . isNegative === x . isNegative ) {
1197
1196
return 0 ;
1198
1197
}
@@ -1207,7 +1206,7 @@ export class Decimal128 {
1207
1206
return 1 ;
1208
1207
}
1209
1208
1210
- if ( ! x . isFinite ( ) ) {
1209
+ if ( ! x . isFinite ) {
1211
1210
return x . isNegative ? 1 : - 1 ;
1212
1211
}
1213
1212
@@ -1258,7 +1257,7 @@ export class Decimal128 {
1258
1257
return new Decimal128 ( NAN ) ;
1259
1258
}
1260
1259
1261
- if ( ! this . isFinite ( ) ) {
1260
+ if ( ! this . isFinite ) {
1262
1261
if ( this . isNegative ) {
1263
1262
return this . negate ( ) ;
1264
1263
}
@@ -1284,8 +1283,8 @@ export class Decimal128 {
1284
1283
return new Decimal128 ( NAN ) ;
1285
1284
}
1286
1285
1287
- if ( ! this . isFinite ( ) ) {
1288
- if ( ! x . isFinite ( ) ) {
1286
+ if ( ! this . isFinite ) {
1287
+ if ( ! x . isFinite ) {
1289
1288
if ( this . isNegative === x . isNegative ) {
1290
1289
return x . clone ( ) ;
1291
1290
}
@@ -1296,7 +1295,7 @@ export class Decimal128 {
1296
1295
return this . clone ( ) ;
1297
1296
}
1298
1297
1299
- if ( ! x . isFinite ( ) ) {
1298
+ if ( ! x . isFinite ) {
1300
1299
return x . clone ( ) ;
1301
1300
}
1302
1301
@@ -1328,8 +1327,8 @@ export class Decimal128 {
1328
1327
return new Decimal128 ( NAN ) ;
1329
1328
}
1330
1329
1331
- if ( ! this . isFinite ( ) ) {
1332
- if ( ! x . isFinite ( ) ) {
1330
+ if ( ! this . isFinite ) {
1331
+ if ( ! x . isFinite ) {
1333
1332
if ( this . isNegative === x . isNegative ) {
1334
1333
return new Decimal128 ( NAN ) ;
1335
1334
}
@@ -1340,7 +1339,7 @@ export class Decimal128 {
1340
1339
return this . clone ( ) ;
1341
1340
}
1342
1341
1343
- if ( ! x . isFinite ( ) ) {
1342
+ if ( ! x . isFinite ) {
1344
1343
return x . negate ( ) ;
1345
1344
}
1346
1345
@@ -1374,7 +1373,7 @@ export class Decimal128 {
1374
1373
return new Decimal128 ( NAN ) ;
1375
1374
}
1376
1375
1377
- if ( ! this . isFinite ( ) ) {
1376
+ if ( ! this . isFinite ) {
1378
1377
if ( x . isZero ( ) ) {
1379
1378
return new Decimal128 ( NAN ) ;
1380
1379
}
@@ -1386,7 +1385,7 @@ export class Decimal128 {
1386
1385
return new Decimal128 ( NEGATIVE_INFINITY ) ;
1387
1386
}
1388
1387
1389
- if ( ! x . isFinite ( ) ) {
1388
+ if ( ! x . isFinite ) {
1390
1389
if ( this . isZero ( ) ) {
1391
1390
return new Decimal128 ( NAN ) ;
1392
1391
}
@@ -1417,7 +1416,7 @@ export class Decimal128 {
1417
1416
}
1418
1417
1419
1418
private isZero ( ) : boolean {
1420
- return this . isFinite ( ) && ! ! this . significand . match ( / ^ 0 + $ / ) ;
1419
+ return this . isFinite && ! ! this . significand . match ( / ^ 0 + $ / ) ;
1421
1420
}
1422
1421
1423
1422
private clone ( ) : Decimal128 {
@@ -1443,8 +1442,8 @@ export class Decimal128 {
1443
1442
return new Decimal128 ( NAN ) ;
1444
1443
}
1445
1444
1446
- if ( ! this . isFinite ( ) ) {
1447
- if ( ! x . isFinite ( ) ) {
1445
+ if ( ! this . isFinite ) {
1446
+ if ( ! x . isFinite ) {
1448
1447
return new Decimal128 ( NAN ) ;
1449
1448
}
1450
1449
@@ -1459,7 +1458,7 @@ export class Decimal128 {
1459
1458
return new Decimal128 ( NEGATIVE_INFINITY ) ;
1460
1459
}
1461
1460
1462
- if ( ! x . isFinite ( ) ) {
1461
+ if ( ! x . isFinite ) {
1463
1462
if ( this . isNegative === x . isNegative ) {
1464
1463
return new Decimal128 ( "0" ) ;
1465
1464
}
@@ -1532,7 +1531,7 @@ export class Decimal128 {
1532
1531
numDecimalDigits : number = 0 ,
1533
1532
mode : RoundingMode = ROUNDING_MODE_DEFAULT
1534
1533
) : Decimal128 {
1535
- if ( this . isNaN ( ) || ! this . isFinite ( ) ) {
1534
+ if ( this . isNaN ( ) || ! this . isFinite ) {
1536
1535
return this . clone ( ) ;
1537
1536
}
1538
1537
@@ -1606,11 +1605,11 @@ export class Decimal128 {
1606
1605
return this . remainder ( d . negate ( ) ) ;
1607
1606
}
1608
1607
1609
- if ( ! this . isFinite ( ) ) {
1608
+ if ( ! this . isFinite ) {
1610
1609
return new Decimal128 ( NAN ) ;
1611
1610
}
1612
1611
1613
- if ( ! d . isFinite ( ) ) {
1612
+ if ( ! d . isFinite ) {
1614
1613
return this . clone ( ) ;
1615
1614
}
1616
1615
0 commit comments