-
-
Notifications
You must be signed in to change notification settings - Fork 0
N6LBigFloatCalculator
NAS6mixfoolv edited this page Sep 14, 2026
·
5 revisions
N6LBigFloatCalculator is a BigFloat class that provides arbitrary-precision real number arithmetic beyond the capabilities of the JavaScript Number type. Key Features:
- Arbitrary-precision addition, subtraction, multiplication, and division
- Internal structure: digits (digit array) + scale (number of decimal places) + sign
- High-precision comparison via
compareTo/epsCmp - Scientific notation (AAA.BBBe±CCC)
- Conversion to fraction (
toFraction) - Integer division (
divInteger) - Usable as a foundation for special functions such as the Gamma function
new N6LBigFloatCalculator("123.45")
new N6LBigFloatCalculator(123.45)
new N6LBigFloatCalculator("123e-1")
new N6LBigFloatCalculator(123e-1)
new N6LBigFloatCalculator(otherBigFloat)
new N6LBigFloatCalculator() // 0- digits: Array of digits (ordered from least significant to most significant)
- scale: Number of decimal places
- isNegative: Sign
add(other, fp = 30)sub(other, fp = 30)mul(other, fp = 30)div(other, fp = 30) // { quot, mod }mod(other, fp = 30)compareTo(other)
epsCmp(other, eps)toStringScientific()toString()N6LBigFloatCalculator.toFraction(value, true, fp)N6LBigFloatCalculator.divInteger(numDigits,
``` denDigits)Regarding the { quot, mod } return value of div (or the mod() function):
Its behavior is similar to that of fmod in C:
Here, trunc(X) extracts the integer part of X.
This formulation is specifically designed for periodic representations, such as those involving
const a = new N6LBigFloatCalculator("0.5");
const b = new N6LBigFloatCalculator("1.25");
const c = new N6LBigFloatCalculator("0.3");
console.log(a.add(b, 50).toString()); // 1.75
console.log(a.sub(b, 50).toString()); // -0.75
console.log(a.mul(b, 50).toString()); // 0.625
const ret = a.div(b, 50);
console.log(ret.quot.toString()); //0.4
console.log(ret.mod.toString()); //0.5:0.4→0→0.5-0*1.25=0.5
const ret = a.div(c, 50);
console.log(ret.quot.toString()); //1.666...
console.log(ret.mod.toString()); //0.2:1.666...→1→0.5-1*0.3=0.2
console.log(a.compareTo(b)); // -1
console.log(a.toStringScientific()); // 5.0e-1Click here to open the function list
//Programed by NAS6
//BigFloatCalculator.js
class N6LBigFloatCalculator {
constructor(value = "0")
clone()
parse(str)
toStringScientific()
toString()
epsCmp(other, eps = "1e-10")
static compareAbsoluteWithScale(A, B)
compareTo(other)
static compareAbsolute(aDigits, bDigits)
static addAbsolute(d1, d2)
static subAbsolute(d1, d2)
_padFraction(maxScale)
add(other, fp = 30)
sub(other, fp = 30)
mul(other, fp = 30)
div(other, fp = 30)
mod(other, fp = 30)
static divInteger(numDigits, denDigits)
static toFraction(other, f = true, fp = 30)
_toIntegerDigits()
_toIntegerLike()
static getInteger(other)
static getDecimal(other)
modInt(other)
static gcdInt(a, b)
static lcmInt(a, b, fp = 30)
static factorialInt(n, fp = 30)
static PI50()
static E50()
static Euler50()
static calcPI(fp = 30, mac = 100)
static calcE(fp = 30, mac = 50)
static abs(x)
static epsilon(fp)
static sqrt(x, fp = 30, iter = 20)
static pow(base, exp, fp = 30)
static _integerPower(base, exp, fp)
static nthroot(base, n, fp = 30)
static gammaBF(z, fp = 50)
static realFactorialBF(x, fp = 50)
static bernoulliSmall(k)
static nCrBF(n, r)
static bernoulliBF(n, fp = 30)
static isPrimeInt(n, fp = 30)
static factorInt(n, fp = 30)
static binomial(n, k, fp = 30)
static exp(x, fp = 30, mac = 30)
static log(x, fp = 30, mac = 40)
static logBase(x, y, fp = 30, mac = 30)
static sin(x, fp = 30, mac = 30, negf = false)
static cos(x, fp = 30, mac = 30)
static tan(x, fp = 30, mac = 30)
static atan(x, fp = 30, mac = 40)
static asin(x, fp = 30, mac = 40)
static acos(x, fp = 30, mac = 40)
static atan2(y, x, fp = 30, mac = 40)
static sinh(x, fp = 30, mac = 30)
static cosh(x, fp = 30, mac = 30)
static tanh(x, fp = 30, mac = 30)
static asinh(x, fp = 30, mac = 30)
static acosh(x, fp = 30, mac = 30)
static atanh(x, fp = 30, mac = 30)
GPL-3.0
Return to Table of Contents Return to NAS6LIB repository [External link]