ソースを参照

[fix] 修复-0导致error
[chore] 增加注释

Steven Yan 2 年 前
コミット
03eb5a9076
4 ファイル変更13 行追加4 行削除
  1. 1 2
      src/app.js
  2. 1 2
      src/app.test.js
  3. 7 0
      src/jison/calculator.jison
  4. 4 0
      src/test_cases.js

+ 1 - 2
src/app.js

@@ -27,8 +27,7 @@ function calc(exp, isDeg = false) {
             if (res.length === 1 || !isNaN(resNum)) {
                 stack.push(resNum);
             } else {
-                console.log(resNum, +parser.parse(resNum));
-                stack.push(parser.parse(resNum));
+                stack.push(parser.parse(resNum) + '');
             }
             res = [];
         }

+ 1 - 2
src/app.test.js

@@ -27,8 +27,7 @@ function calc(exp, isDeg = false) {
             if (res.length === 1 || !isNaN(resNum)) {
                 stack.push(resNum);
             } else {
-                // console.log(resNum, +parser.parse(resNum));
-                stack.push(parser.parse(resNum));
+                stack.push(parser.parse(resNum) + '');
             }
             res = [];
         }

+ 7 - 0
src/jison/calculator.jison

@@ -1,3 +1,10 @@
+/**
+ * jison 编译计算器库
+ * 参考:https://github.com/GerHobbelt/jison
+ * 安装编译库:npm install jison-gho -g
+ * 编译:jison calculator.jison 生成calculator.js
+ * 按需修改为module export
+*/
 
 /* description: Parses and executes mathematical expressions. */
 %{

+ 4 - 0
src/test_cases.js

@@ -104,5 +104,9 @@ module.exports = [
     {
         value: '0√(4) / 3',
         result: 'Infinity',
+    },
+    {
+        value: 'tan(tan(tan(tan(π))))',
+        result: 0,
     }
 ];