1.0.3 • Published 3 years ago
bigfx v1.0.3
bigfx
BigFX is a JavaScript decimal fixed-point number library with unlimited size, based on the native BigInt. It supports up to 15 digits of fractional precision, and is internally stored as a BigInt scaled by a factor of 1e+15. BigFX can work on both Node.js and the browser.
Installation
Using NPM:
npm install bigfxOn the browser:
<script src="https://raw.githubusercontent.com/nirvanasupermind/bigfx/main/bigfx.min.js" type="text/javascript"></script>Example
var BigFX = require("bigfx");
console.log(new BigFX(36.9).add(45).mul(94).toFixed(6)); // 7698.600000
console.log(new BigFX(9007199254740991n).add(2).toString()); // 9007199254740993
console.log(BigFX.PI.neg().cos().toString()); // -1API
constructor()- Creates aBigFXobject equal to 0constructor(number)- Creates aBigFXobject from a number (precision may be lost)constructor(bigint)- Creates aBigFXobject from aBigIntconstructor(bigfx)- Creates aBigFXobject from anotherBigFXobjectclone()- Returns a clone of aBigFXobjectneg()- Returns negation of aBigFXobjectadd(other)- Returns addition of twoBigFXobjects (convertsotherif needed)sub(other)- Returns subtraction of twoBigFXobjects (convertsotherif needed)mul(other)- Returns multiplication of twoBigFXobjects (convertsotherif needed)div(other)- Returns division of twoBigFXobjects (convertsotherif needed)mod(other)- Returns modulo of twoBigFXobjects (convertsotherif needed)and(other)- Returns bitwise AND of twoBigFXobjects (convertsotherif needed, only works if both arguments are integers)or(other)- Returns bitwise OR of twoBigFXobjects (convertsotherif needed, only works if both arguments are integers)xor(other)- Returns bitwise XOR of twoBigFXobjects (convertsotherif needed, only works if both arguments are integers)shl(other)- Returns left-shift of twoBigFXobjects (convertsotherif needed, only works ifotheris an integer)shr(other)- Returns right-shift of twoBigFXobjects (convertsotherif needed, only works ifotheris an integer)exp()- Returns e raised to the power of aBigFXobjectlog()- Returns natural logarithm of aBigFXobjectpow(other)- Returns exponentiation of twoBigFXobjects (convertsotherif needed)sqrt()- Returns the square root of aBigFXobjectsin()- Returns the sine of aBigFXobjectcos()- Returns the cosine of aBigFXobjecttan()- Returns the tangent of aBigFXobjectlt(other)- Checks if aBigFXobject is less than anotherBigFXobjectle(other)- Checks if aBigFXobject is less than or equal to anotherBigFXobjectgt(other)- Checks if aBigFXobject is greater than anotherBigFXobjectge(other)- Checks if aBigFXobject is greater than or equal to anotherBigFXobjecteq(other)- Checks if aBigFXobject is equal to anotherBigFXobjectne(other)- Checks if aBigFXobject is not equal to anotherBigFXobjecttoNumber()- Converts aBigFXobject to a numbertoBigInt()- Converts aBigFXobject to aBigInttoScaledBigInt()- Converts aBigFXobject to aBigIntscaled up by a factor of1e+15(the internal representation)toString(radix = 10)- Converts aBigFXobject to a string in the specified radixtoFixed(fractionDigits = 0)- Converts aBigFXobject to a string with the specified number of fraction digitstoExponential()- Converts aBigFXobject to a string in scientific notation formatstatic ZERO- ABigFXobject with a value of 0static ONE- ABigFXobject with a value of 1static PI- ABigFXobject with a value of πstatic E- ABigFXobject with a value of estatic random()- Creates aBigFXobject with a pseudo-random value between 0 and 1