-
-
Notifications
You must be signed in to change notification settings - Fork 0
N6LBigFloatCalculatorJapanese
NAS6mixfoolv edited this page Sep 14, 2026
·
4 revisions
N6LBigFloatCalculator は JavaScript の Number 型では扱えない
任意精度の実数演算を提供する BigFloat クラスです。
主な特徴:
- 任意精度の加算・減算・乗算・除算
- digits(桁配列)+scale(小数部桁数)+符号の内部構造
- compareTo / epsCmp による高精度比較
- 科学用表記(AAA.BBBe±CCC)
- 分数化(toFraction)
- 整数除算(divInteger)
- Gamma 関数など特殊関数の基盤として利用可能
new N6LBigFloatCalculator("123.45")
new N6LBigFloatCalculator(123.45)
new N6LBigFloatCalculator("123e-1")
new N6LBigFloatCalculator(123e-1)
new N6LBigFloatCalculator(otherBigFloat)
new N6LBigFloatCalculator() // 0- digits: 下位→上位の桁配列
- scale: 小数部の桁数
- isNegative: 符号
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)divの戻り値の{ quot, mod }あるいはmod()のことですが
c言語のfmodと振る舞いが近く
trunc(X)はXの整数部を取得
となっておりこれはπなどを用いた時の周期表現に特化したものです
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ここをクリックすると関数一覧が開きます
//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