Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 4d586e9

Browse files
committed
Expose isFinite, significand, and exponent
1 parent 5272aaa commit 4d586e9

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/decimal128.mts

+26-27
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,9 @@ function toRational(isNegative: boolean, sg: string, exp: number): Rational {
10161016
}
10171017

10181018
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;
10211022
private readonly isNegative: boolean;
10221023
private readonly rat;
10231024

@@ -1044,6 +1045,9 @@ export class Decimal128 {
10441045
this.isNegative = data.isNegative;
10451046
this.exponent = data.exponent;
10461047
this.significand = data.significand;
1048+
this.isFinite =
1049+
data.significand !== POSITIVE_INFINITY &&
1050+
data.significand !== NEGATIVE_INFINITY;
10471051

10481052
this.rat = toRational(this.isNegative, this.significand, this.exponent);
10491053
}
@@ -1052,11 +1056,6 @@ export class Decimal128 {
10521056
return this.significand === NAN;
10531057
}
10541058

1055-
private isFinite(): boolean {
1056-
let sig = this.significand;
1057-
return sig !== POSITIVE_INFINITY && sig !== NEGATIVE_INFINITY;
1058-
}
1059-
10601059
/**
10611060
* Returns a digit string representing this Decimal128.
10621061
*/
@@ -1067,7 +1066,7 @@ export class Decimal128 {
10671066
return NAN;
10681067
}
10691068

1070-
if (!this.isFinite()) {
1069+
if (!this.isFinite) {
10711070
return (this.isNegative ? "-" : "") + POSITIVE_INFINITY;
10721071
}
10731072

@@ -1191,8 +1190,8 @@ export class Decimal128 {
11911190
return undefined;
11921191
}
11931192

1194-
if (!this.isFinite()) {
1195-
if (!x.isFinite()) {
1193+
if (!this.isFinite) {
1194+
if (!x.isFinite) {
11961195
if (this.isNegative === x.isNegative) {
11971196
return 0;
11981197
}
@@ -1207,7 +1206,7 @@ export class Decimal128 {
12071206
return 1;
12081207
}
12091208

1210-
if (!x.isFinite()) {
1209+
if (!x.isFinite) {
12111210
return x.isNegative ? 1 : -1;
12121211
}
12131212

@@ -1258,7 +1257,7 @@ export class Decimal128 {
12581257
return new Decimal128(NAN);
12591258
}
12601259

1261-
if (!this.isFinite()) {
1260+
if (!this.isFinite) {
12621261
if (this.isNegative) {
12631262
return this.negate();
12641263
}
@@ -1284,8 +1283,8 @@ export class Decimal128 {
12841283
return new Decimal128(NAN);
12851284
}
12861285

1287-
if (!this.isFinite()) {
1288-
if (!x.isFinite()) {
1286+
if (!this.isFinite) {
1287+
if (!x.isFinite) {
12891288
if (this.isNegative === x.isNegative) {
12901289
return x.clone();
12911290
}
@@ -1296,7 +1295,7 @@ export class Decimal128 {
12961295
return this.clone();
12971296
}
12981297

1299-
if (!x.isFinite()) {
1298+
if (!x.isFinite) {
13001299
return x.clone();
13011300
}
13021301

@@ -1328,8 +1327,8 @@ export class Decimal128 {
13281327
return new Decimal128(NAN);
13291328
}
13301329

1331-
if (!this.isFinite()) {
1332-
if (!x.isFinite()) {
1330+
if (!this.isFinite) {
1331+
if (!x.isFinite) {
13331332
if (this.isNegative === x.isNegative) {
13341333
return new Decimal128(NAN);
13351334
}
@@ -1340,7 +1339,7 @@ export class Decimal128 {
13401339
return this.clone();
13411340
}
13421341

1343-
if (!x.isFinite()) {
1342+
if (!x.isFinite) {
13441343
return x.negate();
13451344
}
13461345

@@ -1374,7 +1373,7 @@ export class Decimal128 {
13741373
return new Decimal128(NAN);
13751374
}
13761375

1377-
if (!this.isFinite()) {
1376+
if (!this.isFinite) {
13781377
if (x.isZero()) {
13791378
return new Decimal128(NAN);
13801379
}
@@ -1386,7 +1385,7 @@ export class Decimal128 {
13861385
return new Decimal128(NEGATIVE_INFINITY);
13871386
}
13881387

1389-
if (!x.isFinite()) {
1388+
if (!x.isFinite) {
13901389
if (this.isZero()) {
13911390
return new Decimal128(NAN);
13921391
}
@@ -1417,7 +1416,7 @@ export class Decimal128 {
14171416
}
14181417

14191418
private isZero(): boolean {
1420-
return this.isFinite() && !!this.significand.match(/^0+$/);
1419+
return this.isFinite && !!this.significand.match(/^0+$/);
14211420
}
14221421

14231422
private clone(): Decimal128 {
@@ -1443,8 +1442,8 @@ export class Decimal128 {
14431442
return new Decimal128(NAN);
14441443
}
14451444

1446-
if (!this.isFinite()) {
1447-
if (!x.isFinite()) {
1445+
if (!this.isFinite) {
1446+
if (!x.isFinite) {
14481447
return new Decimal128(NAN);
14491448
}
14501449

@@ -1459,7 +1458,7 @@ export class Decimal128 {
14591458
return new Decimal128(NEGATIVE_INFINITY);
14601459
}
14611460

1462-
if (!x.isFinite()) {
1461+
if (!x.isFinite) {
14631462
if (this.isNegative === x.isNegative) {
14641463
return new Decimal128("0");
14651464
}
@@ -1532,7 +1531,7 @@ export class Decimal128 {
15321531
numDecimalDigits: number = 0,
15331532
mode: RoundingMode = ROUNDING_MODE_DEFAULT
15341533
): Decimal128 {
1535-
if (this.isNaN() || !this.isFinite()) {
1534+
if (this.isNaN() || !this.isFinite) {
15361535
return this.clone();
15371536
}
15381537

@@ -1606,11 +1605,11 @@ export class Decimal128 {
16061605
return this.remainder(d.negate());
16071606
}
16081607

1609-
if (!this.isFinite()) {
1608+
if (!this.isFinite) {
16101609
return new Decimal128(NAN);
16111610
}
16121611

1613-
if (!d.isFinite()) {
1612+
if (!d.isFinite) {
16141613
return this.clone();
16151614
}
16161615

0 commit comments

Comments
 (0)