dynamic class Counter {
//输出的文字,是格式化了的,例如分组,科学记数法...
var output:String = "0";
//计算的文字,纯数字
var value:String = "0";
//是否分组
var grouping:Boolean = false;
//监听器用
var _listeners:Array = [];
//统计用
var data:Array = undefined;
var datas:Object = {Ave:undefined, Ave2:undefined, Sum:undefined, Sum2:undefined, S:undefined, S2:undefined};
//算式储存
private var count:Array = [];
//是否重新输入数字
private var isnew:Boolean = false;
//储存数字
private var remember:Number = undefined;
//暂时数字储存
private var nrem:String;
//暂时运算符储存
private var nsign:String = undefined;
//数制
private var systems:Number = 10;
//单位
private var units:Number = 0;
//括号中的
private var inbracket:Array = [];
//构造函数
function Counter(key:Boolean) {
if (key == undefined) {
key = true;
}
if (key) {
Key.addListener(this);
}
}
//清除键
function C() {
//清除所有
数据 value = "0";
count = [];
isnew = true;
nsign = undefined;
CounterMessage("C");
}
//清空键
function CE() {
value = "0";
isnew = true;
CounterMessage("CE");
}
//BackSpace
function BackSpace() {
value = value.slice(0, -1);
if (value.length == 0) {
value = "0";
}
CounterMessage("BackSpace");
}
//输入数字
function numbers(n) {
n = n.toString().toUpperCase();
if (isnew) {
value = "0";
}
isnew = false;
//判断输入的数字是否在数制范围内
if (systems<=10) {
if (n.charCodeAt(0)<=47+systems) {
if (value != "0") {
value += n;
} else {
value = n;
}
CounterMessage(n);
}
} else if (systems>10 && systems<=36) {
if (n.charCodeAt(0)<=54+systems) {
if (value != "0") {
value += n;
} else {
value = n;
}
CounterMessage(n);
}
}
}
//小数点
function dot() {
if (systems == 10) {
if (isnew) {
value = output="0";
}
isnew = false;
if (value.indexOf(".") == -1) {
value += ".";
}
CounterMessage(".");
}
}
//正负号
function minuss() {
if (systems == 10) {
if (isnew) {
value = "0";
}
isnew = false;
if (value != "0") {
if (value.indexOf("-") == -1) {
value = "-"+value;
} else {
value = value.substr(1);
}
}
CounterMessage("+/-");
}
}
//+
function plus() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
//if(count[count.length-1].substr(-1,1)=="*"||count[count.length-1].substr(-1,1)=="/"){
//count[count.length-1]=count[count.length-1].slice(0,-1)
//}
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += parseInt(value, systems).toString();
}
}
count.push("+");
nsign = "+";
value = calculate();
isnew = true;
CounterMessage("+");
}
//-
function minus() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
//if(count[count.length-1].substr(-1,1)=="*"||count[count.length-1].substr(-1,1)=="/"){
//count[count.length-1]=count[count.length-1].slice(0,-1)
//}
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += parseInt(value, systems).toString();
}
}
count.push("-");
nsign = "-";
value = calculate();
isnew = true;
CounterMessage("-");
}
//*
function multiply() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
//if(count[count.length-1].substr(-1,1)=="*"||count[count.length-1].substr(-1,1)=="/"){
//count[count.length-1]=count[count.length-1].slice(0,-1)
//}
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += (parseInt(value, systems).toString());
}
}
count[count.length-1] += "*";
nsign = "*";
value = calculate();
isnew = true;
CounterMessage("*");
}
// /
function except() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
//if(count[count.length-1].substr(-1,1)=="*"||count[count.length-1].substr(-1,1)=="/"){
//count[count.length-1]=count[count.length-1].slice(0,-1)
//}
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += (parseInt(value, systems).toString());
}
}
count[count.length-1] += "/";
nsign = "/";
value = calculate();
isnew = true;
CounterMessage("/");
}
// =
function equal() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
nrem = value;
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
nrem = value;
} else {
if (count[count.length-1].substr(-1, 1) == "*" || count[count.length-1].substr(-1, 1) == "/" || count[count.length-1].substr(-1, 1) == "^") {
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += parseInt(value, systems).toString();
}
nrem = value;
} else {
//if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "*" || count[count.length-1] == "/" || count[count.length-1] == "^") {
//count.pop();
//}
if (nsign == "+") {
count.push("+");
count.push(parseInt2(nrem, systems, 10));
} else if (nsign == "-") {
count.push("-");
count.push(parseInt2(nrem, systems, 10));
} else if (nsign == "%") {
count.push("%");
count.push(parseInt2(nrem, systems, 10));
} else if (nsign == "*") {
count[count.length-1] += ("*"+parseInt2(nrem, systems, 10));
} else if (nsign == "+") {
count[count.length-1] += ("/"+parseInt2(nrem, systems, 10));
} else if (nsign == "^") {
count[count.length-1] += ("^"+parseInt2(nrem, systems, 10));
}
}
}
value = calculate();
isnew = true;
CounterMessage("=");
}
//sqrt
function sqrt() {
duseless();
if (systems == 10) {
value = Math.sqrt(Number(value)).toString();
} else {
value = Math.sqrt(parseInt(value, systems)).toString(systems).toUpperCase();
}
isnew = true;
CounterMessage("sqrt");
}
//取模
function Mod() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
//if(count[count.length-1].substr(-1,1)=="*"||count[count.length-1].substr(-1,1)=="/"){
//count[count.length-1]=count[count.length-1].slice(0,-1)
//}
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += parseInt(value, systems).toString();
}
}
count.push("%");
nsign = "%";
value = calculate();
isnew = true;
CounterMessage("Mod");
}
//x^y
function pow() {
duseless();
if (count[count.length-1] == "+" || count[count.length-1] == "-" || count[count.length-1] == "%") {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else if (count.length == 0) {
if (systems == 10) {
count.push(value);
} else {
count.push(parseInt(value, systems).toString());
}
} else {
if (systems == 10) {
count[count.length-1] += value;
} else {
count[count.length-1] += (parseInt(value, systems).toString());
}
}
count[count.length-1] += "^";
nsign = "^";
value = calculate();
isnew = true;
CounterMessage("x^y");
}
//x^3
function pow3() {
duseless();
if (systems == 10) {
value =
[1] [2] [3] [4] 下一页