To aid in debugging, if a BigNumber.DEBUG property is true then an error will be thrown
if the BigNumber constructor receives an invalid BigNumber.Value, or if BigNumber.isBigNumber
receives a BigNumber instance that is malformed.
// No error, and BigNumber NaN is returned. newBigNumber('blurgh') // 'NaN' newBigNumber(9, 2) // 'NaN' BigNumber.DEBUG = true newBigNumber('blurgh') // '[BigNumber Error] Not a number' newBigNumber(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.
console.log(823456789123456.3) // 823456789123456.2 // No error, and the returned BigNumber does not have the same value as the number literal. newBigNumber(823456789123456.3) // '823456789123456.2' BigNumber.DEBUG = true newBigNumber(823456789123456.3) // '[BigNumber Error] Number primitive has more than 15 significant digits'
Check that a BigNumber instance is well-formed:
x = newBigNumber(10)
BigNumber.DEBUG = false // Change x.c to an illegitimate value. x.c = NaN // No error, as BigNumber.DEBUG is false. BigNumber.isBigNumber(x) // true
To aid in debugging, if a
BigNumber.DEBUGproperty istruethen an error will be thrown if the BigNumber constructor receives an invalidBigNumber.Value, or ifBigNumber.isBigNumberreceives a BigNumber instance that is malformed.An error will also be thrown if a
BigNumber.Valueis of type number with more than 15 significant digits, as callingtoStringorvalueOfon such numbers may not result in the intended value.Check that a BigNumber instance is well-formed: