@@ -605,9 +605,7 @@ function adjustNonInteger(
605
605
case ROUNDING_MODE_HALF_TRUNCATE :
606
606
return roundHalfTrunc ( x ) ;
607
607
default :
608
- throw new Error (
609
- `Unsupported rounding mode "${ options . roundingMode } "`
610
- ) ;
608
+ return roundHalfEven ( x ) ;
611
609
}
612
610
}
613
611
@@ -677,7 +675,7 @@ function handleDecimalNotation(
677
675
}
678
676
679
677
if ( "-." === withoutUnderscores ) {
680
- throw new SyntaxError ( "Lone minus sign and period not permitted" ) ;
678
+ throw new SyntaxError ( "Lone minus sign and period anot permitted" ) ;
681
679
}
682
680
683
681
let isNegative = ! ! withoutUnderscores . match ( / ^ - / ) ;
@@ -993,12 +991,8 @@ function ensureFullySpecifiedCmpOptions(
993
991
return opts ;
994
992
}
995
993
996
- function toRational ( isNegative : boolean , sg : string , exp : number ) : Rational {
997
- if ( sg === NAN || sg === POSITIVE_INFINITY ) {
998
- return new Rational ( 0n , 1n ) ;
999
- }
1000
-
1001
- if ( "1" === sg ) {
994
+ function toRational ( isNegative : boolean , sg : bigint , exp : number ) : Rational {
995
+ if ( 1n === sg ) {
1002
996
// power of ten
1003
997
if ( exp < 0 ) {
1004
998
return new Rational (
@@ -1069,24 +1063,13 @@ export class Decimal128 {
1069
1063
1070
1064
this . rat =
1071
1065
this . isFinite && ! this . isNaN
1072
- ? toRational (
1073
- this . isNegative ,
1074
- this . significand . toString ( ) ,
1075
- this . exponent
1076
- )
1066
+ ? toRational ( this . isNegative , this . significand , this . exponent )
1077
1067
: new Rational ( 0n , 1n ) ;
1078
1068
}
1079
1069
1080
1070
private emitExponential ( ) : string {
1081
1071
let prefix = this . isNegative ? "-" : "" ;
1082
- let originalSg = this . significand ;
1083
-
1084
- if ( typeof originalSg == "undefined" ) {
1085
- throw new Error ( "Significand is undefined" ) ;
1086
- }
1087
-
1088
- let sg = originalSg . toString ( ) ;
1089
-
1072
+ let sg = this . significand . toString ( ) ;
1090
1073
let exp = this . exponent ;
1091
1074
1092
1075
let adjustedExponent = exp + sg . length - 1 ;
@@ -1108,13 +1091,7 @@ export class Decimal128 {
1108
1091
1109
1092
private emitDecimal ( options : FullySpecifiedToStringOptions ) : string {
1110
1093
let prefix = this . isNegative ? "-" : "" ;
1111
- let originalSg = this . significand ;
1112
-
1113
- if ( typeof originalSg == "undefined" ) {
1114
- throw new Error ( "Significand is undefined" ) ;
1115
- }
1116
-
1117
- let sg = originalSg . toString ( ) ;
1094
+ let sg = this . significand . toString ( ) ;
1118
1095
let exp = this . exponent ;
1119
1096
let isZ = this . isZero ( ) ;
1120
1097
@@ -1129,13 +1106,6 @@ export class Decimal128 {
1129
1106
1130
1107
let numFractionalDigits = options . numDecimalDigits ;
1131
1108
1132
- if (
1133
- "number" === typeof numFractionalDigits &&
1134
- numFractionalDigits < 0
1135
- ) {
1136
- numFractionalDigits = undefined ;
1137
- }
1138
-
1139
1109
let renderedRat = this . rat . toDecimalPlaces (
1140
1110
numFractionalDigits ?? MAX_SIGNIFICANT_DIGITS
1141
1111
) ;
0 commit comments