Skip to content

N6LBigFloatCalculator

NAS6mixfoolv edited this page Sep 14, 2026 · 5 revisions

N6LBigFloatCalculator Arbitrary-Precision Real Number Calculation Class

Return to Table of Contents

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

Constructor

new N6LBigFloatCalculator("123.45")
new N6LBigFloatCalculator(123.45)
new N6LBigFloatCalculator("123e-1")
new N6LBigFloatCalculator(123e-1)
new N6LBigFloatCalculator(otherBigFloat)
new N6LBigFloatCalculator() // 0

Internal Structure

  • digits: Array of digits (ordered from least significant to most significant)
  • scale: Number of decimal places
  • isNegative: Sign

Key Methods

Addition

add(other, fp = 30)

Subtraction

sub(other, fp = 30)

Multiplication

mul(other, fp = 30)

Division (Quotient and Remainder)

div(other, fp = 30) // { quot, mod }

Remainder

mod(other, fp = 30)

Comparison

compareTo(other)
epsCmp(other, eps)

Scientific Notation

toStringScientific()

Standard String Conversion

toString()

Conversion to Fraction

N6LBigFloatCalculator.toFraction(value, true, fp)

Integer Division

N6LBigFloatCalculator.divInteger(numDigits,
``` denDigits)

Definition of the Remainder

Regarding the { quot, mod } return value of div (or the mod() function):
Its behavior is similar to that of fmod in C:

$$ mod = A - ( \text{trunc}(\frac{A}{B}) \times B ) $$

Here, trunc(X) extracts the integer part of X.
This formulation is specifically designed for periodic representations, such as those involving $\pi$.


Usage Examples

Return to Table of Contents

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-1

List of Member Functions

Return to Table of Contents

Click 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)


License

GPL-3.0


Return to Table of Contents Return to NAS6LIB repository [External link]

Clone this wiki locally