Skip to content

Commit 20f76b1

Browse files
committed
🐛 BigFloatのpowのバグ修正とtestのKaTeX対応
1 parent c142f5a commit 20f76b1

File tree

12 files changed

+1215
-32
lines changed

12 files changed

+1215
-32
lines changed

dist/JavaLibraryScript.js

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/JavaLibraryScript.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/JavaLibraryScript.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/JavaLibraryScript.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/math/BigFloat.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,10 @@ class BigFloat extends JavaLibraryScriptCore {
11211121
if (exponent === 0n) return scale;
11221122
if (base === 0n) return 0n;
11231123
if (exponent < 0n) {
1124-
// 負の指数は逆数計算を根幹でやるため div を使う
1125-
const one = this._makeResult(scale, precision);
1126-
return one.div(this._pow(base, -exponent, precision)).value;
1124+
const positivePow = this._pow(base, -exponent, precision);
1125+
if (positivePow === 0n) throw new Error("Division by zero in power function");
1126+
// (scale * scale) は、スケールされた値の除算で精度を維持するためのおまじない
1127+
return (scale * scale) / positivePow;
11271128
}
11281129
if (exponent % scale === 0n) {
11291130
// 整数が指数の場合
@@ -2474,8 +2475,8 @@ class BigFloat extends JavaLibraryScriptCore {
24742475
* @static
24752476
*/
24762477
static _bernoulliNumbers(n, precision) {
2477-
const A = new Array(n + 1).fill(null).map(() => 0n);
2478-
const B = new Array(n + 1).fill(null);
2478+
const A = new Array(n + 1).fill(0n);
2479+
const B = new Array(n + 1).fill(0n);
24792480

24802481
const scale = 10n ** precision;
24812482

@@ -2558,7 +2559,7 @@ class BigFloat extends JavaLibraryScriptCore {
25582559
}
25592560

25602561
/**
2561-
* Lanczos-Spouge近似
2562+
* gamma関数[Lanczos-Spouge近似]
25622563
* @param {BigInt} z - スケール済
25632564
* @param {BigInt} precision - 精度
25642565
* @returns {BigInt}
@@ -2609,7 +2610,7 @@ class BigFloat extends JavaLibraryScriptCore {
26092610
}
26102611

26112612
/**
2612-
* ガンマ関数[台形積分]
2613+
* ガンマ関数[Lanczos-Spouge近似]
26132614
* @returns {BigFloat}
26142615
*/
26152616
gamma() {

0 commit comments

Comments
 (0)