From f87445077bf246a5a72a64fbb9749fefe1e576c2 Mon Sep 17 00:00:00 2001 From: Yoyo Zhou Date: Wed, 4 Apr 2018 06:58:01 -0700 Subject: [PATCH] big.js: add aliases .add, .mul, .sub (#24708) --- types/big.js/index.d.ts | 18 ++++++++++++++++++ types/big.js/test/big.js-global-tests.ts | 3 +++ types/big.js/test/big.js-module-tests.ts | 3 +++ 3 files changed, 24 insertions(+) diff --git a/types/big.js/index.d.ts b/types/big.js/index.d.ts index 405622f7ee..8b61c73d37 100644 --- a/types/big.js/index.d.ts +++ b/types/big.js/index.d.ts @@ -102,6 +102,12 @@ export interface BigConstructor { export interface Big { /** Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number. */ abs(): Big; + /** + * Returns a Big number whose value is the value of this Big number plus n - alias for .plus(). + * + * @throws `NaN` if n is invalid. + */ + add(n: BigSource): Big; /** * Compare the values. * @@ -162,6 +168,12 @@ export interface Big { * @throws `NaN` if n is negative or otherwise invalid. */ mod(n: BigSource): Big; + /** + * Returns a Big number whose value is the value of this Big number times n - alias for .times(). + * + * @throws `NaN` if n is invalid. + */ + mul(n: BigSource): Big; /** * Returns a Big number whose value is the value of this Big number plus n. * @@ -196,6 +208,12 @@ export interface Big { * @throws `NaN` if this Big number is negative. */ sqrt(): Big; + /** + * Returns a Big number whose value is the value of this Big number minus n - alias for .minus(). + * + * @throws `NaN` if n is invalid. + */ + sub(n: BigSource): Big; /** * Returns a Big number whose value is the value of this Big number times n. * diff --git a/types/big.js/test/big.js-global-tests.ts b/types/big.js/test/big.js-global-tests.ts index 578391de7b..a57e748fbf 100644 --- a/types/big.js/test/big.js-global-tests.ts +++ b/types/big.js/test/big.js-global-tests.ts @@ -86,6 +86,7 @@ function minusTests() { 0.3 - 0.1; // 0.19999999999999998 const x = new Big(0.3); x.minus(0.1); // '0.2' + x.sub(0.1); // '0.2' } function modTests() { @@ -99,6 +100,7 @@ function plusTests() { const x = new Big(0.1); const y = x.plus(0.2); // '0.3' Big(0.7).plus(x).plus(y); // '1' + Big(0.7).add(x).add(y); // '1' } function powTests() { @@ -138,6 +140,7 @@ function timesTests() { const x = new Big(0.6); const y = x.times(3); // '1.8' Big('7e+500').times(y); // '1.26e+501' + Big('7e+500').mul(y); // '1.26e+501' } function toExponentialTests() { diff --git a/types/big.js/test/big.js-module-tests.ts b/types/big.js/test/big.js-module-tests.ts index 056d41727b..62e5ba491e 100644 --- a/types/big.js/test/big.js-module-tests.ts +++ b/types/big.js/test/big.js-module-tests.ts @@ -88,6 +88,7 @@ function minusTests() { 0.3 - 0.1; // 0.19999999999999998 const x = new Big(0.3); x.minus(0.1); // '0.2' + x.sub(0.1); // '0.2' } function modTests() { @@ -101,6 +102,7 @@ function plusTests() { const x = new Big(0.1); const y = x.plus(0.2); // '0.3' Big(0.7).plus(x).plus(y); // '1' + Big(0.7).add(x).add(y); // '1' } function powTests() { @@ -140,6 +142,7 @@ function timesTests() { const x = new Big(0.6); const y = x.times(3); // '1.8' Big('7e+500').times(y); // '1.26e+501' + Big('7e+500').mul(y); // '1.26e+501' } function toExponentialTests() {