计算器,按照运算法则运算
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-12
true; CounterMessage("load"); } } //清除数据 function clear(n:Number) { if (data != undefined) { data = data.slice(0, n).concat(data.slice(n+1)); isnew = true; CounterMessage("clear"); } } //清除全部数据 function clearAll() { if (data != undefined) { data = []; isnew = true; CounterMessage("clearAll"); } } // 显示Math.PI function PI() { if (systems == 10) { value = String(Math.PI); isnew = true; CounterMessage("PI"); } } //****************************************************************** //私有函数 //根据运算符号计算,与evals和evalPow构成了计算的核心 private function calculate():String { var c:Array = count; //trace(c) if (c.length == 1) { if (c[0].substr(-1, 1) == "^") { var st = Math.max(c[0].lastIndexOf("*"), c[0].lastIndexOf("/")); if (st != -1) { var n:Number = evals(c[0].slice(0, st)); c[0] = n.toString()+c[0].slice(st); return evals(c[0].slice(st+1, -1)).toString(systems); } else { var n:Number = evals(c[0].slice(0, -1)); c[0] = n.toString()+"^"; return n.toString(systems); } } else if (c[0].substr(-1, 1) == "*" || c[0].substr(-1, 1) == "/") { var n:Number = evals(c[0].slice(0, -1)); c[0] = n.toString()+c[0].substr(-1, 1); return n.toString(systems); } else { var n:Number = evals(c[0]); c[0] = n.toString(); return n.toString(systems); } } else if (c.length == 2) { var n:Number = evals(c[0]); c[0] = n.toString(); return n.toString(systems); } else if (c.length == 3) { if (c[2].substr(-1, 1) == "^") { var st = Math.max(c[2].lastIndexOf("*"), c[2].lastIndexOf("/")); if (st != -1) { var n:Number = evals(c[2].slice(0, st)); c[2] = n.toString()+c[2].slice(st); return evals(c[2].slice(st, -1)).toString(systems); } else { var n:Number = evals(c[2].slice(0, -1)); c[2] = n.toString()+"^"; return n.toString(systems); } } else if (c[2].substr(-1, 1,) == "*" || c[2].substr(-1, 1) == "/") { var n:Number = evals(c[2].slice(0, -1)); c[2] = n.toString()+c[2].substr(-1, 1); return n.toString(systems); } else { //trace(c[1]) if (c[1] == "+") { c[0] = (Number(c[0])+evals(c[2])).toString(); c[1] = c[3]; c.length = 1; return parseInt2(c[0], 10, systems); } else if (c[1] == "-") { c[0] = (Number(c[0])-evals(c[2])).toString(); c[1] = c[3]; c.length = 1; return parseInt2(c[0], 10, systems); } else if (c[1] == "%") { //trace(Number(c[0])%evals(c[2])) c[0] = (Number(c[0])%evals(c[2])).toString(); c[1] = c[3]; c.length = 1; return parseInt2(c[0], 10, systems); } } } else if (c.length == 4) { if (c[1] == "+") { c[0] = (Number(c[0])+evals(c[2])).toString(); c[1] = c[3]; c.length = 2; return parseInt2(c[0], 10, systems); } else if (c[1] == "-") { c[0] = (Number(c[0])-evals(c[2])).toString(); c[1] = c[3]; c.length = 2; retu |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于计算器,按照运算法则运算的所有评论