@lit-protocol/bigfx
v1.0.3
Published
`BigFX` is a JavaScript decimal fixed-point number library with unlimited size, built on the native BigInt.
Downloads
5
Keywords
Readme
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 bigfx
On 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()); // -1
API
constructor()
- Creates aBigFX
object equal to 0constructor(number)
- Creates aBigFX
object from a number (precision may be lost)constructor(bigint)
- Creates aBigFX
object from aBigInt
constructor(bigfx)
- Creates aBigFX
object from anotherBigFX
objectclone()
- Returns a clone of aBigFX
objectneg()
- Returns negation of aBigFX
objectadd(other)
- Returns addition of twoBigFX
objects (convertsother
if needed)sub(other)
- Returns subtraction of twoBigFX
objects (convertsother
if needed)mul(other)
- Returns multiplication of twoBigFX
objects (convertsother
if needed)div(other)
- Returns division of twoBigFX
objects (convertsother
if needed)mod(other)
- Returns modulo of twoBigFX
objects (convertsother
if needed)and(other)
- Returns bitwise AND of twoBigFX
objects (convertsother
if needed, only works if both arguments are integers)or(other)
- Returns bitwise OR of twoBigFX
objects (convertsother
if needed, only works if both arguments are integers)xor(other)
- Returns bitwise XOR of twoBigFX
objects (convertsother
if needed, only works if both arguments are integers)shl(other)
- Returns left-shift of twoBigFX
objects (convertsother
if needed, only works ifother
is an integer)shr(other)
- Returns right-shift of twoBigFX
objects (convertsother
if needed, only works ifother
is an integer)exp()
- Returns e raised to the power of aBigFX
objectlog()
- Returns natural logarithm of aBigFX
objectpow(other)
- Returns exponentiation of twoBigFX
objects (convertsother
if needed)sqrt()
- Returns the square root of aBigFX
objectsin()
- Returns the sine of aBigFX
objectcos()
- Returns the cosine of aBigFX
objecttan()
- Returns the tangent of aBigFX
objectlt(other)
- Checks if aBigFX
object is less than anotherBigFX
objectle(other)
- Checks if aBigFX
object is less than or equal to anotherBigFX
objectgt(other)
- Checks if aBigFX
object is greater than anotherBigFX
objectge(other)
- Checks if aBigFX
object is greater than or equal to anotherBigFX
objecteq(other)
- Checks if aBigFX
object is equal to anotherBigFX
objectne(other)
- Checks if aBigFX
object is not equal to anotherBigFX
objecttoNumber()
- Converts aBigFX
object to a numbertoBigInt()
- Converts aBigFX
object to aBigInt
toScaledBigInt()
- Converts aBigFX
object to aBigInt
scaled up by a factor of1e+15
(the internal representation)toString(radix = 10)
- Converts aBigFX
object to a string in the specified radixtoFixed(fractionDigits = 0)
- Converts aBigFX
object to a string with the specified number of fraction digitstoExponential()
- Converts aBigFX
object to a string in scientific notation formatstatic ZERO
- ABigFX
object with a value of 0static ONE
- ABigFX
object with a value of 1static PI
- ABigFX
object with a value of πstatic E
- ABigFX
object with a value of estatic random()
- Creates aBigFX
object with a pseudo-random value between 0 and 1