Permalink
Browse files

Document BigNumber.sum method. Update bignumber.d.ts

  • Loading branch information...
MikeMcl committed Oct 31, 2018
1 parent 73591e8 commit 7614b5844807cccaf3ccfe88ee0947aa8eaf2c8d
Showing with 97 additions and 52 deletions.
  1. +64 −32 bignumber.d.ts
  2. +1 −1 bignumber.js
  3. +1 −1 bignumber.mjs
  4. +29 −16 doc/API.html
  5. +1 −1 perf/bignumber-vs-bigdecimal.html
  6. +1 −1 perf/bigtime.js
@@ -281,6 +281,11 @@ export namespace BigNumber {
*/
export interface Format {

/**
* The string to prepend.
*/
prefix?: string;

/**
* The decimal separator.
*/
@@ -310,6 +315,11 @@ export namespace BigNumber {
* The grouping size of the fraction part.
*/
fractionGroupSize?: number;

/**
* The string to append.
*/
suffix?: string;
}

export type Instance = BigNumber;
@@ -644,6 +654,7 @@ export declare class BigNumber {
* @param n The exponent, an integer.
* @param [m] The modulus.
*/
exponentiatedBy(n: BigNumber.Value, m?: BigNumber.Value): BigNumber;
exponentiatedBy(n: number, m?: BigNumber.Value): BigNumber;

/**
@@ -677,6 +688,7 @@ export declare class BigNumber {
* @param n The exponent, an integer.
* @param [m] The modulus.
*/
pow(n: BigNumber.Value, m?: BigNumber.Value): BigNumber;
pow(n: number, m?: BigNumber.Value): BigNumber;

/**
@@ -1259,7 +1271,8 @@ export declare class BigNumber {
* @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
* @param [roundingMode] Rounding mode, integer, 0 to 8.
*/
toExponential(decimalPlaces?: number, roundingMode?: BigNumber.RoundingMode): string;
toExponential(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
toExponential(): string;

/**
* Returns a string representing the value of this BigNumber in normal (fixed-point) notation
@@ -1296,7 +1309,8 @@ export declare class BigNumber {
* @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
* @param [roundingMode] Rounding mode, integer, 0 to 8.
*/
toFixed(decimalPlaces?: number, roundingMode?: BigNumber.RoundingMode): string;
toFixed(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
toFixed(): string;

/**
* Returns a string representing the value of this BigNumber in normal (fixed-point) notation
@@ -1323,29 +1337,29 @@ export declare class BigNumber {
* fractionGroupSeparator: ' ',
* fractionGroupSize: 0
* }
*
*
* x = new BigNumber('123456789.123456789')
*
* // Set the format object globally
*
* // Set the global formatting options
* BigNumber.config({ FORMAT: fmt })
*
*
* x.toFormat() // '123,456,789.123456789'
* x.toFormat(3) // '123,456,789.123'
*
*
* // If a reference to the object assigned to FORMAT has been retained,
* // the format properties can be changed directly
* fmt.groupSeparator = ' '
* fmt.fractionGroupSize = 5
* x.toFormat() // '123 456 789.12345 6789'
*
* // Alternatively, pass a format object as an argument
*
* // Alternatively, pass the formatting options as an argument
* fmt = {
* decimalSeparator: ',',
* groupSeparator: '.',
* groupSize: 3,
* secondaryGroupSize: 2
* }
*
*
* x.toFormat() // '123 456 789.12345 6789'
* x.toFormat(fmt) // '12.34.56.789,123456789'
* x.toFormat(2, fmt) // '12.34.56.789,12'
@@ -1354,9 +1368,13 @@ export declare class BigNumber {
*
* @param [decimalPlaces] Decimal places, integer, 0 to 1e+9.
* @param [roundingMode] Rounding mode, integer, 0 to 8.
* @param [format] Format object. See `BigNumber.Format`.
* @param [format] Formatting options object. See `BigNumber.Format`.
*/
toFormat(decimalPlaces?: number, roundingMode?: BigNumber.RoundingMode, format?: BigNumber.Format): string;
toFormat(decimalPlaces: number, roundingMode: BigNumber.RoundingMode, format?: BigNumber.Format): string;
toFormat(decimalPlaces: number, roundingMode?: BigNumber.RoundingMode): string;
toFormat(decimalPlaces?: number): string;
toFormat(decimalPlaces: number, format: BigNumber.Format): string;
toFormat(format: BigNumber.Format): string;

/**
* Returns an array of two BigNumbers representing the value of this BigNumber as a simple
@@ -1382,7 +1400,7 @@ export declare class BigNumber {
*
* @param [max_denominator] The maximum denominator, integer > 0, or Infinity.
*/
toFraction(max_denominator?: BigNumber.Value): string[];
toFraction(max_denominator?: BigNumber.Value): [BigNumber, BigNumber];

/**
* As `valueOf`.
@@ -1439,7 +1457,8 @@ export declare class BigNumber {
* @param [significantDigits] Significant digits, integer, 1 to 1e+9.
* @param [roundingMode] Rounding mode, integer 0 to 8.
*/
toPrecision(significantDigits?: number, roundingMode?: BigNumber.RoundingMode): string;
toPrecision(significantDigits: number, roundingMode?: BigNumber.RoundingMode): string;
toPrecision(): string;

/**
* Returns a string representing the value of this BigNumber in base `base`, or base 10 if `base`
@@ -1577,10 +1596,8 @@ export declare class BigNumber {
static isBigNumber(value: any): value is BigNumber;

/**
*
* Returns a BigNumber whose value is the maximum of the arguments.
*
* Accepts either an argument list or an array of values.
* Returns a BigNumber whose value is the maximum of the arguments, or of the array elements if
* an array is passed.
*
* The return value is always exact and unrounded.
*
@@ -1597,9 +1614,8 @@ export declare class BigNumber {
static maximum(...n: BigNumber.Value[]): BigNumber;

/**
* Returns a BigNumber whose value is the maximum of the arguments.
*
* Accepts either an argument list or an array of values.
* Returns a BigNumber whose value is the maximum of the arguments, or of the array elements if
* an array is passed.
*
* The return value is always exact and unrounded.
*
@@ -1616,9 +1632,8 @@ export declare class BigNumber {
static max(...n: BigNumber.Value[]): BigNumber;

/**
* Returns a BigNumber whose value is the minimum of the arguments.
*
* Accepts either an argument list or an array of values.
* Returns a BigNumber whose value is the minimum of the arguments, or of the array elements if
* an array is passed.
*
* The return value is always exact and unrounded.
*
@@ -1635,9 +1650,8 @@ export declare class BigNumber {
static minimum(...n: BigNumber.Value[]): BigNumber;

/**
* Returns a BigNumber whose value is the minimum of the arguments.
*
* Accepts either an argument list or an array of values.
* Returns a BigNumber whose value is the minimum of the arguments, or of the array elements if
* an array is passed.
*
* The return value is always exact and unrounded.
*
@@ -1680,6 +1694,24 @@ 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.
*
* The return value is always exact and unrounded.
*
* ```ts
* x = new BigNumber('3257869345.0378653')
* BigNumber.sum(4e9, x, '123456789.9') // '7381326134.9378653'
*
* arr = [2, new BigNumber(14), '15.9999', 12]
* BigNumber.sum(arr) // '43.9999'
* ```
*
* @param n A numeric value.
*/
static sum(...n: BigNumber.Value[]): BigNumber;

/**
* Configures the settings that apply to this BigNumber constructor.
*
@@ -1778,7 +1810,7 @@ export declare class BigNumber {
/**
* To aid in debugging, if a `BigNumber.DEBUG` property is `true` then an error will be thrown
* on an invalid `BigNumber.Value`.
*
*
* ```ts
* // No error, and BigNumber NaN is returned.
* new BigNumber('blurgh') // 'NaN'
@@ -1787,20 +1819,20 @@ export declare class BigNumber {
* new BigNumber('blurgh') // '[BigNumber Error] Not a number'
* new BigNumber(9, 2) // '[BigNumber Error] Not a base 2 number'
* ```
*
*
* An error will also be thrown if a `BigNumber.Value` is of type number with more than 15
* significant digits, as calling `toString` or `valueOf` on such numbers may not result
* in the intended value.
*
*
* ```ts
* console.log(823456789123456.3) // 823456789123456.2
* // No error, and the returned BigNumber does not have the same value as the number literal.
* new BigNumber(823456789123456.3) // '823456789123456.2'
* BigNumber.DEBUG = true
* new BigNumber(823456789123456.3)
* new BigNumber(823456789123456.3)
* // '[BigNumber Error] Number primitive has more than 15 significant digits'
* ```
*
*
*/
static DEBUG?: boolean;
}
@@ -2485,7 +2485,7 @@
*
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
* [format] {object} See FORMAT object above.
* [format] {object} Formatting options. See FORMAT pbject above.
*
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
* '[BigNumber Error] Argument not an object: {format}'
@@ -2467,7 +2467,7 @@ function clone(configObject) {
*
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
* [format] {object} See FORMAT object above.
* [format] {object} Formatting options. See FORMAT pbject above.
*
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
* '[BigNumber Error] Argument not an object: {format}'
@@ -86,6 +86,7 @@
<li><a href="#max" >maximum</a><span>max</span></li>
<li><a href="#min" >minimum</a><span>min</span></li>
<li><a href="#random" >random</a></li>
<li><a href="#sum" >sum</a></li>
</ul>

<a href="#constructor-properties">Properties</a>
@@ -684,18 +685,15 @@ <h5 id="isBigNumber">



<h5 id="max">
maximum<code class='inset'>.max([arg1 [, arg2, ...]]) <i>&rArr; BigNumber</i></code>
</h5>
<h5 id="max">maximum<code class='inset'>.max(n...) <i>&rArr; BigNumber</i></code></h5>
<p>
<code>arg1</code>, <code>arg2</code>, ...: <i>number|string|BigNumber</i><br />
<code>n</code>: <i>number|string|BigNumber</i><br />
<i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
</p>
<p>
Returns a BigNumber whose value is the maximum of <code>arg1</code>,
<code>arg2</code>,... .
Returns a BigNumber whose value is the maximum of the arguments, or of the array elements if
an array is passed.
</p>
<p>The argument to this method can also be an array of values.</p>
<p>The return value is always exact and unrounded.</p>
<pre>x = new BigNumber('3257869345.0378653')
BigNumber.maximum(4e9, x, '123456789.9') // '4000000000'
@@ -705,18 +703,15 @@ <h5 id="max">



<h5 id="min">
minimum<code class='inset'>.min([arg1 [, arg2, ...]]) <i>&rArr; BigNumber</i></code>
</h5>
<h5 id="min">minimum<code class='inset'>.min(n...) <i>&rArr; BigNumber</i></code></h5>
<p>
<code>arg1</code>, <code>arg2</code>, ...: <i>number|string|BigNumber</i><br />
<code>n</code>: <i>number|string|BigNumber</i><br />
<i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
</p>
<p>
Returns a BigNumber whose value is the minimum of <code>arg1</code>,
<code>arg2</code>,... .
Returns a BigNumber whose value is the minimum of the arguments, or of the array elements if
an array is passed.
</p>
<p>The argument to this method can also be an array of values.</p>
<p>The return value is always exact and unrounded.</p>
<pre>x = new BigNumber('3257869345.0378653')
BigNumber.minimum(4e9, x, '123456789.9') // '123456789.9'
@@ -766,6 +761,24 @@ <h5 id="random">



<h5 id="sum">sum<code class='inset'>.sum(n...) <i>&rArr; BigNumber</i></code></h5>
<p>
<code>n</code>: <i>number|string|BigNumber</i><br />
<i>See <code><a href="#bignumber">BigNumber</a></code> for further parameter details.</i>
</p>
<p>
Returns a BigNumber whose value is the sum of the arguments, or of the array elements if an
array is passed.
</p>
<p>The return value is always exact and unrounded.</p>
<pre>x = new BigNumber('3257869345.0378653')
BigNumber.sum(4e9, x, '123456789.9') // '7381326134.9378653'

arr = [2, new BigNumber(14), '15.9999', 12]
BigNumber.sum(arr) // '43.9999'</pre>



<h4 id="constructor-properties">Properties</h4>
<p>
The library's enumerated rounding modes are stored as properties of the constructor.<br />
@@ -1594,7 +1607,7 @@ <h5 id="toFor">

x = new BigNumber('123456789.123456789')

// Set the format object globally
// Set the global formatting options
BigNumber.config({ FORMAT: fmt })

x.toFormat() // '123,456,789.123456789'
@@ -1606,7 +1619,7 @@ <h5 id="toFor">
fmt.fractionGroupSize = 5
x.toFormat() // '123 456 789.12345 6789'

// Alternatively, pass a format object as an argument
// Alternatively, pass the formatting options as an argument
fmt = {
prefix: '=> ',
decimalSeparator: ',',
@@ -288,7 +288,7 @@ <h1>Testing BigNumber against BigDecimal</h1>
timingVisible = true;
}
counterTimeout = setTimeout(updateCounter, 50);
return
return;
}
$COUNTER.innerHTML = completedReps;
@@ -9,7 +9,7 @@ var arg, i, j, max, method, methodIndex, decimalPlaces, rounding, reps, start,
bdMs = ['add', 'subtract', 'multiply', 'divide', 'remainder',
'compareTo', 'pow', 'negate', 'abs'],
bnMs1 = ['plus', 'minus', 'multipliedBy', 'dividedBy', 'modulo',
'comparedTo', 'exponentiatedBy', 'negated', 'absoluteValue']
'comparedTo', 'exponentiatedBy', 'negated', 'absoluteValue'],
bnMs2 = ['', '', '', 'div', 'mod', '', '', '', ''],
Ms = [bdMs, bnMs1, bnMs2],
allMs = [].concat.apply([], Ms),

0 comments on commit 7614b58

Please sign in to comment.