Permalink
Browse files

Remove isArray. min, max and sum: no arrays. Update bignumber.d.ts

  • Loading branch information...
MikeMcl committed Nov 1, 2018
1 parent 7614b58 commit 0280915d3c04859358455b41b78315ec682e5a73
Showing with 80 additions and 82 deletions.
  1. +22 −20 bignumber.d.ts
  2. +26 −32 bignumber.js
  3. +22 −15 bignumber.mjs
  4. +6 −11 doc/API.html
  5. +2 −2 test/methods/minmax.js
  6. +2 −2 test/methods/sum.js
@@ -1596,8 +1596,7 @@ export declare class BigNumber {
static isBigNumber(value: any): value is BigNumber;
/**
* Returns a BigNumber whose value is the maximum of the arguments, or of the array elements if
* an array is passed.
* Returns a BigNumber whose value is the maximum of the arguments.
*
* The return value is always exact and unrounded.
*
@@ -1606,16 +1605,15 @@ export declare class BigNumber {
* BigNumber.maximum(4e9, x, '123456789.9') // '4000000000'
*
* arr = [12, '13', new BigNumber(14)]
* BigNumber.maximum(arr) // '14'
* BigNumber.maximum.apply(null, arr) // '14'
* ```
*
* @param n A numeric value.
*/
static maximum(...n: BigNumber.Value[]): BigNumber;
static maximum(...n: BigNumber.Value): BigNumber;
/**
* Returns a BigNumber whose value is the maximum of the arguments, or of the array elements if
* an array is passed.
* Returns a BigNumber whose value is the maximum of the arguments.
*
* The return value is always exact and unrounded.
*
@@ -1624,16 +1622,15 @@ export declare class BigNumber {
* BigNumber.max(4e9, x, '123456789.9') // '4000000000'
*
* arr = [12, '13', new BigNumber(14)]
* BigNumber.max(arr) // '14'
* BigNumber.max.apply(null, arr) // '14'
* ```
*
* @param n A numeric value.
*/
static max(...n: BigNumber.Value[]): BigNumber;
static max(...n: BigNumber.Value): BigNumber;
/**
* Returns a BigNumber whose value is the minimum of the arguments, or of the array elements if
* an array is passed.
* Returns a BigNumber whose value is the minimum of the arguments.
*
* The return value is always exact and unrounded.
*
@@ -1642,16 +1639,15 @@ export declare class BigNumber {
* BigNumber.minimum(4e9, x, '123456789.9') // '123456789.9'
*
* arr = [2, new BigNumber(-14), '-15.9999', -12]
* BigNumber.minimum(arr) // '-15.9999'
* BigNumber.minimum.apply(null, arr) // '-15.9999'
* ```
*
* @param n A numeric value.
*/
static minimum(...n: BigNumber.Value[]): BigNumber;
static minimum(...n: BigNumber.Value): BigNumber;
/**
* Returns a BigNumber whose value is the minimum of the arguments, or of the array elements if
* an array is passed.
* Returns a BigNumber whose value is the minimum of the arguments.
*
* The return value is always exact and unrounded.
*
@@ -1660,12 +1656,12 @@ export declare class BigNumber {
* BigNumber.min(4e9, x, '123456789.9') // '123456789.9'
*
* arr = [2, new BigNumber(-14), '-15.9999', -12]
* BigNumber.min(arr) // '-15.9999'
* BigNumber.min.apply(null, arr) // '-15.9999'
* ```
*
* @param n A numeric value.
*/
static min(...n: BigNumber.Value[]): BigNumber;
static min(...n: BigNumber.Value): BigNumber;
/**
* Returns a new BigNumber with a pseudo-random value equal to or greater than 0 and less than 1.
@@ -1678,6 +1674,13 @@ export declare class BigNumber {
* either `Math.random` (fastest), `crypto.getRandomValues` (Web Cryptography API in recent
* browsers) or `crypto.randomBytes` (Node.js).
*
* To be able to set `CRYPTO` to true when using Node.js, the `crypto` object must be available
* globally:
*
* ```ts
* global.crypto = require('crypto')
* ```
*
* If `CRYPTO` is true, i.e. one of the `crypto` methods is to be used, the value of a returned
* BigNumber should be cryptographically secure and statistically indistinguishable from a random
* value.
@@ -1695,8 +1698,7 @@ export declare class BigNumber {
static random(decimalPlaces?: number): BigNumber;
/**
* Returns a BigNumber whose value is the sum of the arguments, or of the array elements if an
* array is passed.
* Returns a BigNumber whose value is the sum of the arguments.
*
* The return value is always exact and unrounded.
*
@@ -1705,12 +1707,12 @@ export declare class BigNumber {
* BigNumber.sum(4e9, x, '123456789.9') // '7381326134.9378653'
*
* arr = [2, new BigNumber(14), '15.9999', 12]
* BigNumber.sum(arr) // '43.9999'
* BigNumber.sum.apply(null, arr) // '43.9999'
* ```
*
* @param n A numeric value.
*/
static sum(...n: BigNumber.Value[]): BigNumber;
static sum(...n: BigNumber.Value): BigNumber;
/**
* Configures the settings that apply to this BigNumber constructor.
@@ -22,10 +22,10 @@
* isGreaterThan gt | FORMAT
* isGreaterThanOrEqualTo gte | ALPHABET
* isInteger | isBigNumber
* isLessThan lt | sum
* isLessThanOrEqualTo lte | maximum max
* isNaN | minimum min
* isNegative | random
* isLessThan lt | maximum max
* isLessThanOrEqualTo lte | minimum min
* isNaN | random
* isNegative | sum
* isPositive |
* isZero |
* minus |
@@ -457,7 +457,7 @@
// '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
v = obj[p];
if (isArray(v)) {
if (v && v.pop) {
intCheck(v[0], -MAX, 0, p);
intCheck(v[1], 0, MAX, p);
TO_EXP_NEG = v[0];
@@ -473,7 +473,7 @@
// '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
if (obj.hasOwnProperty(p = 'RANGE')) {
v = obj[p];
if (isArray(v)) {
if (v && v.pop) {
intCheck(v[0], -MAX, -1, p);
intCheck(v[1], 1, MAX, p);
MIN_EXP = v[0];
@@ -583,20 +583,6 @@
BigNumber.isBigNumber = function (v) {
return v instanceof BigNumber || v && v._isBigNumber === true || false;
};
/*
* Return a new BigNumber whose value is the sum of the arguments.
*
* arguments {number|string|BigNumber}
*/
BigNumber.sum = function () {
var sum = new BigNumber(0);
var args = Array.prototype.slice.call(arguments);
for (var i = 0; i < args.length; i++) {
sum = sum.plus(args[i]);
}
return sum;
}
/*
@@ -763,6 +749,20 @@
})();
/*
* Return a BigNumber whose value is the sum of the arguments.
*
* arguments {number|string|BigNumber}
*/
BigNumber.sum = function () {
var i = 1,
args = arguments,
sum = new BigNumber(args[0]);
for (; i < args.length;) sum = sum.plus(args[i++]);
return sum;
};
// PRIVATE FUNCTIONS
@@ -1246,13 +1246,11 @@
// Handle BigNumber.max and BigNumber.min.
function maxOrMin(args, method) {
var m, n,
i = 0;
var n,
i = 1,
m = new BigNumber(args[0]);
if (isArray(args[0])) args = args[0];
m = new BigNumber(args[0]);
for (; ++i < args.length;) {
for (; i < args.length; i++) {
n = new BigNumber(args[i]);
// If any number is NaN, return NaN.
@@ -2664,7 +2662,6 @@
// Infinity or NaN?
if (e === null) {
if (s) {
str = 'Infinity';
if (s < 0) str = '-' + str;
@@ -2703,6 +2700,7 @@
if (typeof Symbol == 'function' && typeof Symbol.iterator == 'symbol') {
P[Symbol.toStringTag] = 'BigNumber';
// Node.js v10.12.0+
P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;
}
@@ -2737,6 +2735,7 @@
// Determine trailing zeros.
for (j = r.length; r.charCodeAt(--j) === 48;);
return r.slice(0, j + 1 || 1);
}
@@ -2795,11 +2794,6 @@
}
function isArray(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
}
// Assumes finite n.
function isOdd(n) {
var k = n.c.length - 1;
@@ -22,7 +22,7 @@
* isLessThan lt | maximum max
* isLessThanOrEqualTo lte | minimum min
* isNaN | random
* isNegative |
* isNegative | sum
* isPositive |
* isZero |
* minus |
@@ -453,7 +453,7 @@ function clone(configObject) {
// '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
v = obj[p];
if (isArray(v)) {
if (v && v.pop) {
intCheck(v[0], -MAX, 0, p);
intCheck(v[1], 0, MAX, p);
TO_EXP_NEG = v[0];
@@ -469,7 +469,7 @@ function clone(configObject) {
// '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
if (obj.hasOwnProperty(p = 'RANGE')) {
v = obj[p];
if (isArray(v)) {
if (v && v.pop) {
intCheck(v[0], -MAX, -1, p);
intCheck(v[1], 1, MAX, p);
MIN_EXP = v[0];
@@ -745,6 +745,20 @@ function clone(configObject) {
})();
/*
* Return a BigNumber whose value is the sum of the arguments.
*
* arguments {number|string|BigNumber}
*/
BigNumber.sum = function () {
var i = 1,
args = arguments,
sum = new BigNumber(args[0]);
for (; i < args.length;) sum = sum.plus(args[i++]);
return sum;
};
// PRIVATE FUNCTIONS
@@ -1228,13 +1242,11 @@ function clone(configObject) {
// Handle BigNumber.max and BigNumber.min.
function maxOrMin(args, method) {
var m, n,
i = 0;
if (isArray(args[0])) args = args[0];
m = new BigNumber(args[0]);
var n,
i = 1,
m = new BigNumber(args[0]);
for (; ++i < args.length;) {
for (; i < args.length; i++) {
n = new BigNumber(args[i]);
// If any number is NaN, return NaN.
@@ -2646,7 +2658,6 @@ function clone(configObject) {
// Infinity or NaN?
if (e === null) {
if (s) {
str = 'Infinity';
if (s < 0) str = '-' + str;
@@ -2713,6 +2724,7 @@ function coeffToString(a) {
// Determine trailing zeros.
for (j = r.length; r.charCodeAt(--j) === 48;);
return r.slice(0, j + 1 || 1);
}
@@ -2771,11 +2783,6 @@ function intCheck(n, min, max, name) {
}
function isArray(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
}
// Assumes finite n.
function isOdd(n) {
var k = n.c.length - 1;
Oops, something went wrong.

0 comments on commit 0280915

Please sign in to comment.