@@ -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 ) ;
0 commit comments