@@ -23,9 +23,7 @@ import { Rational } from "./Rational.mjs";
23
23
import { Decimal } from "./Decimal.mjs" ;
24
24
25
25
const EXPONENT_MIN = - 6176 ;
26
- const NORMAL_EXPONENT_MIN = - 6143 ;
27
26
const EXPONENT_MAX = 6111 ;
28
- const NORMAL_EXPONENT_MAX = 6144 ;
29
27
const MAX_SIGNIFICANT_DIGITS = 34 ;
30
28
31
29
const bigTen = BigInt ( 10 ) ;
@@ -53,6 +51,10 @@ function pickQuantum(
53
51
return EXPONENT_MAX ;
54
52
}
55
53
54
+ if ( d === "0" || d === "-0" ) {
55
+ return preferredQuantum ;
56
+ }
57
+
56
58
return preferredQuantum ;
57
59
}
58
60
@@ -542,36 +544,6 @@ export class Decimal128 {
542
544
return p + lhs + "." + rhs . substring ( 0 , n ) + "e" + exp ;
543
545
}
544
546
545
- private isInteger ( ) : boolean {
546
- let s = this . toString ( ) ;
547
-
548
- let [ _ , rhs ] = s . split ( / [ . ] / ) ;
549
-
550
- if ( rhs === undefined ) {
551
- return true ;
552
- }
553
-
554
- return ! ! rhs . match ( / ^ 0 + $ / ) ;
555
- }
556
-
557
- toBigInt ( ) : bigint {
558
- if ( this . isNaN ( ) ) {
559
- throw new RangeError ( "NaN cannot be converted to a BigInt" ) ;
560
- }
561
-
562
- if ( ! this . isFinite ( ) ) {
563
- throw new RangeError ( "Infinity cannot be converted to a BigInt" ) ;
564
- }
565
-
566
- if ( ! this . isInteger ( ) ) {
567
- throw new RangeError (
568
- "Non-integer decimal cannot be converted to a BigInt"
569
- ) ;
570
- }
571
-
572
- return BigInt ( this . toString ( ) ) ;
573
- }
574
-
575
547
toNumber ( ) : number {
576
548
if ( this . isNaN ( ) ) {
577
549
return NaN ;
@@ -1074,70 +1046,6 @@ export class Decimal128 {
1074
1046
let q = this . divide ( d ) . round ( 0 , ROUNDING_MODE_TRUNCATE ) ;
1075
1047
return this . subtract ( d . multiply ( q ) ) ;
1076
1048
}
1077
-
1078
- isNormal ( ) : boolean {
1079
- if ( this . isNaN ( ) ) {
1080
- throw new RangeError ( "Cannot determine whether NaN is normal" ) ;
1081
- }
1082
-
1083
- if ( ! this . isFinite ( ) ) {
1084
- throw new RangeError (
1085
- "Only finite numbers can be said to be normal or not"
1086
- ) ;
1087
- }
1088
-
1089
- if ( this . isZero ( ) ) {
1090
- throw new RangeError (
1091
- "Only non-zero numbers can be said to be normal or not"
1092
- ) ;
1093
- }
1094
-
1095
- let exp = this . exponent ( ) ;
1096
- return exp >= NORMAL_EXPONENT_MIN && exp <= NORMAL_EXPONENT_MAX ;
1097
- }
1098
-
1099
- isSubnormal ( ) : boolean {
1100
- if ( this . isNaN ( ) ) {
1101
- throw new RangeError ( "Cannot determine whether NaN is subnormal" ) ;
1102
- }
1103
-
1104
- if ( ! this . isFinite ( ) ) {
1105
- throw new RangeError (
1106
- "Only finite numbers can be said to be subnormal or not"
1107
- ) ;
1108
- }
1109
-
1110
- let exp = this . exponent ( ) ;
1111
- return exp < NORMAL_EXPONENT_MIN ;
1112
- }
1113
-
1114
- truncatedExponent ( ) : number {
1115
- if ( this . isZero ( ) || this . isSubnormal ( ) ) {
1116
- return NORMAL_EXPONENT_MIN ;
1117
- }
1118
-
1119
- return this . exponent ( ) ;
1120
- }
1121
-
1122
- scaledSignificand ( ) : bigint {
1123
- if ( this . isNaN ( ) ) {
1124
- throw new RangeError ( "NaN does not have a scaled significand" ) ;
1125
- }
1126
-
1127
- if ( ! this . isFinite ( ) ) {
1128
- throw new RangeError ( "Infinity does not have a scaled significand" ) ;
1129
- }
1130
-
1131
- if ( this . isZero ( ) ) {
1132
- return 0n ;
1133
- }
1134
-
1135
- let v = this . cohort ( ) as Rational ;
1136
- let te = this . truncatedExponent ( ) ;
1137
- let ss = v . scale10 ( MAX_SIGNIFICANT_DIGITS - 1 - te ) ;
1138
-
1139
- return ss . numerator ;
1140
- }
1141
1049
}
1142
1050
1143
1051
Decimal128 . prototype . valueOf = function ( ) {
0 commit comments