Skip to content

Commit 989d6a5

Browse files
committed
🔨 デモの機能を強化&gh-page機能を仮作成
1 parent 2bc9fce commit 989d6a5

File tree

10 files changed

+190
-43
lines changed

10 files changed

+190
-43
lines changed

.github/workflows/deploy.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy test dir to gh-page
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: リポジトリをチェックアウト
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 1
16+
17+
- name: 仮フォルダのセットアップ
18+
run: |
19+
mkdir output
20+
cp -r test/* output/
21+
22+
- name: gh-page ブランチにデプロイ
23+
uses: peaceiris/actions-gh-pages@v4
24+
with:
25+
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
publish_dir: ./output
27+
publish_branch: gh-page
28+
force_orphan: true

JavaLibraryScript.code-workspace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"laguerre",
2121
"Maclaurin",
2222
"murmurhash",
23+
"peaceiris",
2324
"prec",
2425
"prereleased",
2526
"softprops",

dist/JavaLibraryScript.js

Lines changed: 34 additions & 2 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: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,8 +2625,8 @@ class BigFloat extends JavaLibraryScriptCore {
26252625
// 階乗・二項係数
26262626
// --------------------------------------------------
26272627
/**
2628-
* 階乗を計算する
2629-
* @param {BigInt} n
2628+
* 階乗を計算する (整数のみ)
2629+
* @param {BigInt} n - スケールなし
26302630
* @returns {BigInt}
26312631
* @static
26322632
*/
@@ -2635,6 +2635,38 @@ class BigFloat extends JavaLibraryScriptCore {
26352635
for (let i = 2n; i <= n; i++) f *= i;
26362636
return f;
26372637
}
2638+
/**
2639+
* 階乗を計算する (小数対応)
2640+
* @param {BigInt} n - スケールあり
2641+
* @param {BigInt} precision
2642+
* @returns {BigInt}
2643+
* @static
2644+
*/
2645+
static _factorialGamma(n, precision) {
2646+
const scale = 10n ** precision;
2647+
return this._gammaLanczos(n + scale, precision);
2648+
}
2649+
/**
2650+
* 階乗を計算する (小数計算の場合の精度に注意)
2651+
* @returns {BigFloat}
2652+
*/
2653+
factorial() {
2654+
/** @type {typeof BigFloat} */
2655+
const construct = this.constructor;
2656+
const exPrec = construct.config.extraPrecision;
2657+
const totalPr = this._precision + exPrec;
2658+
const val = this.value * 10n ** exPrec;
2659+
const scale = 10n ** totalPr;
2660+
let raw;
2661+
if (val % scale === 0n && val >= 0n) {
2662+
// 整数の場合
2663+
raw = construct._factorial(val / scale) * scale;
2664+
} else {
2665+
// 小数の場合
2666+
raw = construct._factorialGamma(val, totalPr);
2667+
}
2668+
return this._makeResult(raw, this._precision, totalPr);
2669+
}
26382670
/**
26392671
* 二項係数を計算する
26402672
* @param {BigInt} n

test/calculator.js

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NodeDict {
1111
if (!isNaN(Number(key))) {
1212
this._map.set(key, new Node({ disp: key, type: "num" }));
1313
} else {
14-
this._log.warn("not found", key);
14+
console.warn("not found", key);
1515
return new Node();
1616
}
1717
}
@@ -115,6 +115,7 @@ const nodeDataDict = {
115115
"(": node({ label: "()", key: "(", disp: "", argLength: 1, type: "bracket" }),
116116
mod: node({ label: "mod", key: "%", disp: "%", type: "op" }),
117117
pi: node({ label: "π", key: "P", disp: "π", type: "static" }),
118+
tau: node({ label: "τ", key: "T", disp: "τ", type: "static" }),
118119
e: node({ label: "e", key: "E", disp: "e", type: "static" }),
119120
rand: node({ label: "Rnd", key: "R", disp: "rand", argLength: 0, type: "struct-func" }),
120121
pow: node({ label: "xⁿ", key: "^", disp: "pow", argLength: 2, type: "func" }),
@@ -124,10 +125,21 @@ const nodeDataDict = {
124125
nthRoot: node({ label: "ⁿ√x", disp: "nthRoot", argLength: 2, type: "func" }),
125126
abs: node({ label: "|x|", disp: "abs", argLength: 1, type: "func" }),
126127
reciprocal: node({ label: "1/x", disp: "reciprocal", argLength: 1, type: "func" }),
127-
exp: node({ label: "exp", disp: "exp", argLength: 1, type: "func" }),
128+
exp: node({ label: "eˣ", disp: "exp", argLength: 1, type: "func" }),
129+
exp2: node({ label: "2ˣ", disp: "exp2", argLength: 1, type: "func" }),
130+
expm1: node({ label: "eˣ⁻¹", disp: "expm1", argLength: 1, type: "func" }),
128131
"!": node({ label: "n!", key: "!", disp: "factorial", argLength: 1, type: "struct-func" }),
129-
log: node({ label: "log", disp: "log", args: [null, ["1", "0"]], argLength: 2, type: "struct-func" }),
132+
log: node({ label: "log", disp: "log", argLength: 2, type: "func" }),
133+
log2: node({ label: "log₂", disp: "log2", argLength: 1, type: "func" }),
134+
log10: node({ label: "log₁₀", disp: "log10", argLength: 1, type: "func" }),
130135
ln: node({ label: "ln", disp: "ln", argLength: 1, type: "struct-func" }),
136+
sin: node({ label: "sin", disp: "sin", argLength: 1, type: "func" }),
137+
cos: node({ label: "cos", disp: "cos", argLength: 1, type: "func" }),
138+
tan: node({ label: "tan", disp: "tan", argLength: 1, type: "func" }),
139+
asin: node({ label: "asin", disp: "asin", argLength: 1, type: "func" }),
140+
acos: node({ label: "acos", disp: "acos", argLength: 1, type: "func" }),
141+
atan: node({ label: "atan", disp: "atan", argLength: 1, type: "func" }),
142+
atan2: node({ label: "atan2", disp: "atan2", argLength: 2, type: "func" }),
131143
gamma: node({ label: "Γx", disp: "gamma", argLength: 1, type: "func" }),
132144
};
133145

@@ -306,56 +318,71 @@ class Calculator {
306318
_BUTTONS = [
307319
[
308320
// 1行目
321+
nodeDataDict.gamma.clone(),
309322
nodeDataDict.rand.clone(),
310323
nodeDataDict.pi.clone(),
324+
nodeDataDict.tau.clone(),
311325
nodeDataDict.e.clone(),
312326
{ label: "AC", type: "clear", func: () => this._calcInit() },
313327
{ label: "BS", key: "Backspace", type: "clear", func: () => this._key_BS() },
314328
],
315329
[
316330
// 2行目
317-
nodeDataDict.gamma.clone(),
318-
nodeDataDict.reciprocal.clone(),
319-
nodeDataDict.abs.clone(),
320331
nodeDataDict.exp.clone(),
332+
nodeDataDict.exp2.clone(),
333+
nodeDataDict.expm1.clone(),
334+
nodeDataDict.sin.clone(),
335+
nodeDataDict.cos.clone(),
336+
nodeDataDict.tan.clone(),
321337
],
322338
[
323339
// 3行目
324340
nodeDataDict.nthRoot.clone(),
325341
nodeDataDict.sqrt.clone(),
342+
nodeDataDict.asin.clone(),
343+
nodeDataDict.acos.clone(),
344+
nodeDataDict.atan.clone(),
345+
nodeDataDict.atan2.clone(),
346+
],
347+
[
348+
// 4行目
326349
nodeDataDict.pow.clone(),
327350
nodeDataDict.pow2.clone(),
351+
nodeDataDict.ln.clone(),
352+
nodeDataDict.log.clone(),
353+
nodeDataDict.log10.clone(),
354+
nodeDataDict.log2.clone(),
328355
],
329356
[
330-
// 4行目
331-
nodeDataDict["!"].clone(),
357+
// 5行目
358+
nodeDataDict.pow10.clone(),
332359
nodeDataDict["7"].clone(),
333360
nodeDataDict["8"].clone(),
334361
nodeDataDict["9"].clone(),
335362
nodeDataDict["("].clone(),
336363
nodeDataDict.mod.clone(),
337364
],
338365
[
339-
// 5行目
340-
nodeDataDict.pow10.clone(),
366+
// 6行目
367+
nodeDataDict.abs.clone(),
341368
nodeDataDict["4"].clone(),
342369
nodeDataDict["5"].clone(),
343370
nodeDataDict["6"].clone(),
344371
nodeDataDict["*"].clone(),
345372
nodeDataDict["/"].clone(),
346373
],
347374
[
348-
// 6行目
349-
nodeDataDict.log.clone(),
375+
// 7行目
376+
nodeDataDict.reciprocal.clone(),
350377
nodeDataDict["1"].clone(),
351378
nodeDataDict["2"].clone(),
352379
nodeDataDict["3"].clone(),
353380
nodeDataDict["+"].clone(),
354381
nodeDataDict["-"].clone(),
355382
],
356383
[
357-
// 7行目
358-
nodeDataDict.ln.clone(),
384+
// 8行目
385+
nodeDataDict["!"].clone(),
359386
nodeDataDict["."].clone(),
360387
nodeDataDict["0"].clone(),
361388
{ label: "=", key: ["=", "Enter"], type: "equal", func: () => this._key_Enter() },
@@ -433,7 +460,7 @@ class Calculator {
433460
precDiv.appendChild(exPrecInput);
434461

435462
const roundModeLabel = document.createElement("label");
436-
roundModeLabel.textContent = "丸めモード:";
463+
roundModeLabel.textContent = "丸めモード:";
437464
precDiv.appendChild(roundModeLabel);
438465

439466
const roundModeSelect = document.createElement("select");
@@ -832,6 +859,8 @@ class Calculator {
832859
switch (node.key) {
833860
case "P": // π
834861
return BigFloat.pi(precision);
862+
case "T": // τ
863+
return BigFloat.tau(precision);
835864
case "E": // e
836865
return BigFloat.e(precision);
837866
default:
@@ -876,6 +905,10 @@ class Calculator {
876905
return args[0].reciprocal();
877906
case "exp":
878907
return args[0].exp();
908+
case "exp2":
909+
return args[0].exp2();
910+
case "expm1":
911+
return args[0].expm1();
879912
case "ln":
880913
return args[0].ln();
881914
case "gamma":
@@ -892,19 +925,18 @@ class Calculator {
892925
return args[0].acos();
893926
case "atan":
894927
return args[0].atan();
895-
case "factorial": {
896-
// n! = Γ(n + 1)
897-
const one = new BigFloat(1, precision);
898-
return args[0].add(one).gamma();
899-
}
928+
case "factorial":
929+
return args[0].factorial();
900930

901931
// 2引数以上の関数
902932
case "pow":
903933
// 通常の pow(x, y)
904934
return args[0].pow(args[1]);
935+
case "atan2":
936+
return args[0].atan2(args[1]);
905937

906938
case "nthRoot": // n√x -> x.nthRoot(n)
907-
return args[1].nthRoot(args[0].toNumber()); // BigFloat.nthRootはnをNumber/BigIntで受け取ります
939+
return args[1].nthRoot(args[0].toNumber() | 0); // BigFloat.nthRootはnをNumber/BigIntで受け取ります
908940

909941
case "log": // log_b(x) -> x.log(b)
910942
return args[1].log(args[0]);
@@ -913,10 +945,6 @@ class Calculator {
913945
case "rand":
914946
return BigFloat.random(precision);
915947

916-
// 括弧
917-
case "":
918-
return args[0];
919-
920948
default:
921949
throw new Error(`未定義の関数です: ${node.disp}`);
922950
}
@@ -1028,14 +1056,23 @@ class Calculator {
10281056
}
10291057
flushNumber();
10301058

1031-
if (node.key === "-") {
1032-
const prevNode = processedNodes[processedNodes.length - 1];
1033-
// 単項マイナスかを判定: 式の先頭、または直前が演算子か開き括弧/関数
1034-
if (!prevNode || ["op", "unary_op", "func", "struct-func", "bracket"].includes(prevNode.type)) {
1035-
const unaryMinusNode = new Node({ key: "neg", disp: "-", type: "unary_op", argLength: 1 });
1036-
processedNodes.push(unaryMinusNode);
1059+
if (node.key === "+" || node.key === "-") {
1060+
const prevProcessedNode = processedNodes.length > 0 ? processedNodes[processedNodes.length - 1] : null;
1061+
1062+
// 単項演算子かを判定: 式の先頭、または直前が二項/単項演算子の場合。
1063+
// 値(数値、関数、定数など)の直後に来る +/- は二項演算子とみなす。
1064+
const isUnary = !prevProcessedNode || prevProcessedNode.type === "op" || prevProcessedNode.type === "unary_op";
1065+
1066+
if (isUnary) {
1067+
if (node.key === "-") {
1068+
// 単項マイナスは 'neg' というキーを持つ単項演算子ノードとして追加
1069+
const unaryMinusNode = new Node({ key: "neg", disp: "-", type: "unary_op", argLength: 1 });
1070+
processedNodes.push(unaryMinusNode);
1071+
}
1072+
// 単項プラス(+)は、計算に影響しないため無視する
10371073
} else {
1038-
processedNodes.push(node); // 二項マイナス
1074+
// 二項演算子としてそのまま追加
1075+
processedNodes.push(node);
10391076
}
10401077
} else {
10411078
processedNodes.push(node);

test/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
html,
88
body {
99
box-sizing: border-box;
10-
font-family: "メイリオ", "Meiryo", "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "MS Pゴシック", sans-serif;
10+
font-family: "メイリオ", "Meiryo", "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "MS Pゴシック", sans-serif;
1111
font-size: 16px;
1212
height: 100%;
1313
margin: 0;
@@ -27,6 +27,10 @@ h2 {
2727
width: 100%;
2828
}
2929

30+
select {
31+
max-width: 100%;
32+
}
33+
3034
.JLS_display {
3135
align-items: center;
3236
background-color: #fafafa;

0 commit comments

Comments
 (0)