b[v]?1:-1;break}
if(!(w<0))break;
for(p=P==l?o:d;P;){
if(b[--P]y&&a(D,y,n.RM,b[0]!==h),D},
u.eq=function(r){return 0===this.cmp(r)},
u.gt=function(r){return this.cmp(r)>0},
u.gte=function(r){return this.cmp(r)>-1},
u.lt=function(r){return this.cmp(r)<0},
u.lte=function(r){return this.cmp(r)<1},
u.minus=u.sub=function(r){var e,t,n,i,o=this,s=o.constructor,c=o.s,f=(r=new s(r)).s;
if(c!=f)return r.s=-f,o.plus(r);
var u=o.c.slice(),h=o.e,l=r.c,a=r.e;
if(!u[0]||!l[0])return l[0]?r.s=-f:u[0]?r=new s(o):r.s=1,r;
if(c=h-a){for((i=c<0)?(c=-c,n=u):(a=h,n=l),n.reverse(),f=c;f--;)n.push(0);n.reverse()}
else for(t=((i=u.length0)for(;f--;)u[e++]=0;
for(f=e;t>c;){if(u[--t] other.
div(other: number | string | Big): Big
Returns this Big number divided by another.
eq(other: number | string | Big): boolean
Returns true if this Big number is equal to another.
gt(other: number | string | Big): boolean
Returns true if this Big number is greater than another.
gte(other: number | string | Big): boolean
Returns true if this Big number is greater than or equal to another.
lt(other: number | string | Big): boolean
Returns true if this Big number is less than another.
lte(other: number | string | Big): boolean
Returns true if this Big number is less than or equal to another.
minus(other: number | string | Big): Big
Returns this Big number minus another.
mod(other: number | string | Big): Big
Returns the remainder of this Big number divided by another.
neg(): Big
Returns the negation of this Big number.
plus(other: number | string | Big): Big
Returns this Big number plus another.
pow(other: number | string | Big): Big
Returns this Big number raised to the power of another.
prec(value: number): Big
Sets the precision of this Big number.
Parameters:
value: The new precision value.
round(dp?: number, rm?: number): Big
Returns this Big number rounded to a specified number of decimal places and rounding mode.
Parameters:
dp: The number of decimal places to round to (optional).
rm: The rounding mode (optional).
sqrt(): Big
Returns the square root of this Big number.
times(other: number | string | Big): Big
Returns this Big number multiplied by another.
toExponential(dp?: number): string
Returns a string of this Big number in exponential notation.
Parameters:
dp: The number of digits after the decimal point (optional).
toFixed(dp?: number): string
Returns a string of this Big number in fixed-point notation.
Parameters:
dp: The number of digits after the decimal point (optional).
toJSON(): string
Returns a string representation of this Big number.
toNumber(): number
Returns a primitive value of this Big number.
toPrecision(prec?: number): string
Returns a string of this Big number in fixed-point notation or exponential notation depending on its value.
Parameters:
prec: The number of significant digits (optional).
toString(): string
Returns a string representation of this Big number.
valueOf(): Big
Returns a primitive value of this Big number.
INSTANCE Properties
c: Array
The coefficient of this Big number.
e: number
The exponent of this Big number.
s: number
The sign of this Big number (-1 for negative, 1 for positive).
```
--------------------------------
### Configuring Decimal Places and Rounding Mode
Source: https://github.com/mikemcl/big.js/blob/main/docs/index.html
Explains how to configure the global decimal places (`Big.DP`) and rounding mode (`Big.RM`) for operations. It also shows how to create separate Big.js constructors with custom configurations or redefine prototype methods to pass these settings per operation.
```javascript
// Global configuration
Big.DP = 10;
y = x.sqrt();
Big.DP = 0;
Big.RM = 1;
z = x.div(3);
// Redefining prototype method for per-operation settings
Big.prototype.div = (function () {
const div = Big.prototype.div;
return function (n, dp, rm) {
const Big = this.constructor;
const DP = Big.DP;
const RM = Big.RM;
if (dp != undefined) Big.DP = dp;
if (rm != undefined) Big.RM = rm;
let result = div.call(this, n);
Big.DP = DP;
Big.RM = RM;
return result;
}
})();
var dp = 10;
var round_up = 2;
x = x.div(y, dp, round_up);
```
--------------------------------
### Creating and Using Multiple Big.js Constructors
Source: https://github.com/mikemcl/big.js/blob/main/docs/index.html
Demonstrates how to create distinct Big.js constructors with custom DP and RM settings. It shows how numbers created from these constructors behave differently in division operations due to their unique configurations. It also highlights that Big numbers from different constructors can be used together, with the operation's settings determined by the Big number the method is called on.
```javascript
let Big = require('big.js');
// Create a default Big constructor
let bigDefault = Big;
// Create a new constructor with default DP and RM
let Big10 = Big();
// Set DP for the default constructor
Big.DP = 3;
// Set DP for the Big10 constructor
Big10.DP = 10;
// Create numbers using different constructors
let x = Big(5);
let y = Big10(5);
// Perform division operations
console.log(x.div(3).toString()); // Output: 1.667
console.log(y.div(3).toString()); // Output: 1.6666666667
// Using numbers from different constructors together
console.log(x.plus(y).toString()); // Uses Big.DP (3) for the result
```
--------------------------------
### Big.js Default Configuration and Initialization
Source: https://github.com/mikemcl/big.js/blob/main/perf/big-vs-bigdecimal.html
Sets default values for Big.js, including decimal places, rounding mode, and other configuration options. It also handles the loading of the ICU4J BigDecimal script.
```javascript
Big.DP = 20;
Big.RM = 1; // Set defaults
$MAX.checked = $INPUTS[0].checked = $GWT.checked = true;
$SHOW.checked = $INT.checked = false;
$REPS.value = DEFAULT_REPS;
$DIGITS.value = DEFAULT_DIGITS;
$DP.value = DEFAULT_DECIMAL_PLACES;
$R.option = DEFAULT_ROUNDING;
BigDecimal_GWT = BigDecimal;
BigDecimal = undefined; // Load ICU4J BigDecimal script = document.createElement("script"); script.src = ICU4J_URL;
script.onload = script.onreadystatechange = function () {
if (!script.readyState || /loaded|complete/.test(script.readyState)) {
script = null;
BigDecimal_ICU4J = BigDecimal;
$START.onmousedown = begin;
}
};
document.getElementsByTagName("head")[0].appendChild(script);
```
--------------------------------
### Big.js Constructor and Configuration
Source: https://github.com/mikemcl/big.js/blob/main/docs/index.html
Defines the Big.js constructor and its static properties for configuration. This includes setting the default precision (`DP`), rounding mode (`RM`), and exponential notation limits (`NE`, `PE`). The `strict` property controls behavior for imprecise conversions.
```javascript
e=function r(){
function e(t){
var n=this;
if(!(n instanceof e))return t===h&&0===arguments.length?r():new e(t);
if(t instanceof e)n.s=t.s,n.e=t.e,n.c=t.c.slice();
else{
if("string"!=typeof t){if(!0===e.strict&&"bigint"!=typeof t)throw TypeError(o+"value");t=0===t&&1/t<0?"-0":String(t)}
!function(r,e){
var t,n,i;
if(!l.test(e))throw Error(o+"number");
r.s="-"==e.charAt(0)?(e=e.slice(1),-1):1;
(t=e.indexOf("."))>-1&&(e=e.replace(".",""));
(n=e.search(/e/i))>0?(t<0&&(t=n),t+=+e.slice(n+1),e=e.substring(0,n)):t<0&&(t=e.length);
for(i=e.length,n=0;n0&&"0"==e.charAt(--i););
for(r.e=t-n-1,r.c=[],t=0;n<=i;)r.c[t++]=+e.charAt(n++)
}}
(n,t)
}
n.constructor=e
}
return e.prototype=u,e.DP=20,e.RM=1,e.NE=-7,e.PE=21,e.strict=false,e.roundDown=0,e.roundHalfUp=1,e.roundHalfEven=2,e.roundUp=3,e}(),
e.default=e.Big=e,"function"==typeof define&&define.amd?define((function(){return e})):"undefined"!=typeof module&&module.exports?module.exports=e:r.Big=e}(this)
```
--------------------------------
### Number Formatting Methods
Source: https://github.com/mikemcl/big.js/blob/main/README.md
Shows how to use the `toExponential`, `toFixed`, and `toPrecision` methods of Big.js to format numbers according to specific requirements.
```javascript
x = new Big(255.5)
x.toExponential(5) // "2.55500e+2"
x.toFixed(5) // "255.50000"
x.toPrecision(5) // "255.50"
```
--------------------------------
### Chaining Big.js Methods
Source: https://github.com/mikemcl/big.js/blob/main/README.md
Illustrates the ability to chain multiple Big.js arithmetic methods together for concise and readable code.
```javascript
x.div(y).plus(z).times(9).minus('1.234567801234567e+8').plus(976.54321).div('2598.11772')
x.sqrt().div(y).pow(3).gt(y.mod(z)) // true
```