Skip to content

Commit 021ff7e

Browse files
committed
feat: add rm support to strigify and uglify-js as package dependencies
1 parent b4f32ae commit 021ff7e

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

big.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@
251251
* 4 valueOf
252252
* n? {number|undefined} Caller's argument.
253253
* k? {number|undefined}
254+
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
254255
*/
255-
function stringify(x, id, n, k) {
256+
function stringify(x, id, n, k, rm) {
256257
var e, s,
257258
Big = x.constructor,
258259
z = !x.c[0];
@@ -268,7 +269,7 @@
268269
n = k - x.e;
269270

270271
// Round?
271-
if (x.c.length > ++k) round(x, n, Big.RM);
272+
if (x.c.length > ++k) round(x, n, rm || Big.RM);
272273

273274
// toFixed: recalculate k as x.e may have changed if value rounded up.
274275
if (id == 2) k = x.e + n + 1;
@@ -865,9 +866,10 @@
865866
* places and rounded using Big.RM.
866867
*
867868
* dp? {number} Integer, 0 to MAX_DP inclusive.
869+
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
868870
*/
869-
P.toExponential = function (dp) {
870-
return stringify(this, 1, dp, dp);
871+
P.toExponential = function (dp, rm) {
872+
return stringify(this, 1, dp, dp, rm);
871873
};
872874

873875

@@ -876,12 +878,13 @@
876878
* places and rounded using Big.RM.
877879
*
878880
* dp? {number} Integer, 0 to MAX_DP inclusive.
879-
*
881+
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
882+
*
880883
* (-0).toFixed(0) is '0', but (-0.1).toFixed(0) is '-0'.
881884
* (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
882885
*/
883-
P.toFixed = function (dp) {
884-
return stringify(this, 2, dp, this.e + dp);
886+
P.toFixed = function (dp, rm) {
887+
return stringify(this, 2, dp, this.e + dp, rm);
885888
};
886889

887890

@@ -891,9 +894,10 @@
891894
* the integer part of the value in normal notation.
892895
*
893896
* sd {number} Integer, 1 to MAX_DP inclusive.
897+
* rm? 0, 1, 2 or 3 (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_UP)
894898
*/
895-
P.toPrecision = function (sd) {
896-
return stringify(this, 3, sd, sd - 1);
899+
P.toPrecision = function (sd, rm) {
900+
return stringify(this, 3, sd, sd - 1, rm);
897901
};
898902

899903

big.min.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)