您所在的位置:QQ首页 > 动画频道 > 高级应用> 正文

Calculator类 模拟科学计算器函数
http://flash.QQ.com   2006年 08月 29日 11:15   闪吧  
1 2 3 4
public function log() { //计算常用对数

if (this._system == 10) {

this._value = (Math.log(Number(this._value))/Math.LN10).toString();

} else {

this._value = (Math.log(parseInt(this._value, this._system))/Math.LN10).toString(this._system);

}

this.broadMessage("log");

}

public function PI() { //显示PI

if (_system == 10) {

this._value = String(Math.PI);

this.isnew = 1;

this.broadMessage("PI");

}

}

public function E() { //显示E

if (_system == 10) {

this._value = String(Math.E);

this.isnew = 1;

this.broadMessage("E");

}

}

public function dms() { //将数字化为度-分-秒

/*if (this._system == 10) {

var st = this._value.indexOf(".");

if (st != -1) {

var ss = (Number(this._value.substr(st+1))*60);

if (ss.length>2) {

ss = ss.substr(0, 2)+(Number(ss.substr(2))*60).toString();

}

this._value = this._value.slice(0, st)+"."+ss;

this.broadMessage("dms");

}

}*/

}

public function adms() { //将数字化为度

/*if (_system == 10) {

if ((st=_value.indexOf(".")) != -1) {

var s:Number = 0;

if (_value.length>=st+4) {

s = Number(_value.substr(st+3))/60;

while (s>10) {

s /= 10;

}

}

var f:Number = (Number(_value.substr(st+1, 2))+s)/60;

_value = (Math.floor(Number(_value))+f).toString();

//_value=Rtrim(_value,"0")

this.broadMessage("adms");

}

}*/

}

public function ChangetoE(s:String) {

return s; //化成科学记数法

/*if (n>=1) {

if (String(n).length<16) {

var nz = Math.floor(n);

var nx = String(n).slice(String(nz).length+1);

nx = Rtrim(nx, "0");

var ns = String(nz).split("");

var nsp = ns[0]+".";

for (var i = 1; i

if (nx == 0) {

if (ns[i] == 0) {

var del = true;

for (var j = i; j

if (!ns[i] == 0) {

del = false;

break;

}

}

if (del) {

break;

}

} else {

nsp += ns[i];

}

} else {

nsp += ns[i];

}

}

nsp = String(nsp);

nsp = Rtrim(nsp, "0");

if (nx == "") {

if (String(nsp).substr(-1, 1) == ".") {

nsp = String(nsp).slice(0, -1);

}

} else {

nx = String(nx);

nsp += Rtrim(nx, "0");

}

return String(nsp+"e+"+(ns.length-1));

} else {

return n;

}

} else {

if (n == 0) {

return "0e+0";

} else if (n>0.00001) {

var ns = String(n).split("");

var nt = 0;

for (var i = 2; i

if (Number(ns[i]) == 0) {

nt++;

} else {

break;

}

}

var nz = String(n).substr(nt+2, 1);

var nx = String(n).substr(nt+3);

if (nx != "") {

return String(nz+"."+nx+"e-"+(nt+1));

} else {

return String(nz+"e-"+(nt+1));

}

} else {

return n;

}

}*/

}

public function ChangetoF(s:String) {

return s; //化成普通数

/*var ns = String(n);

if (ns.indexOf("e") == -1) {

return n;

} else {

var nss = ns.split("e");

var nz = nss[0];

var nx = nss[1];

if (nz.indexOf(".") == -1) {

for (var i = 0; i

nz += "0";

}

} else {

var nzs = nz.split(".");

var nzz = nzs[0];

if (nzs[1].length<=Number(nx)) {

for (var i = 0; i<(Number(nx)-Number(nzs[1])); i++) {

nzz += "0";

}

nz = nzz;

}

return String(nz);

}

}*/

}

private function Rtrim(n:String, d:String) {

//ChangetoF和ChangetoE函数支持,删除字符串右边的指定字符

/*if (d == undefined) {

d = " ";

}

if (n.indexOf(d) != -1) {

var ss = n.split("");

var ssl = ss.length;

for (var i = ssl; i>=0; i--) {

if (ss[i] == d) {

if (i+1 == ss.length) {

ss.pop();

}

}

}

return ss.join("");

} else {

return n;

}*/

}

public function set group(b:Boolean) {

this.isgroup = b;

this.broadcastMessage("onChange", this, "GroupChange");

}

public function get group():Boolean {

return this.isgroup;

}

public function set FtoE(b:Boolean) {

this._isE = b;

this.broadcastMessage("onChange", this, "FtoEChange");

}

public function get FtoE():Boolean {

return this._isE;

}

public function get value():String {

return this._value;

}

public function get result():String { //数字输出

var re = this._value;

if (this._isE) {

if (this._system == 10) {

re = ChangetoE(re);

}

} else {

re = ChangetoF(re);

if (this.isgroup) {

if (_system == 10) {

var s = ",";

var n:Number = 3;

} else {

var s = " ";

var n:Number = 4;

}

if (re != "0") {

if (re.indexOf(".") != -1) {

var num = re.indexOf(".");

} else {

var num = re.length;

}

var i = num-n;

while (i>0) {

if (re.slice(0, i) != "-") {

re = re.slice(0, i).concat(s, re.slice(i));

}

i -= n;

}

}

}

}

return re;

} //数据暂存

public function MC(index:Number) { // 清除存储区的数字

if (index == undefined) {

this._memory = [];

} else {

this._memory.splice(index, 1);

}

this.isnew = 1;

this.broadMessage("MC");

}

public function MR(index:Number) { // 输出存储区的所有数字

if (_memory == undefined) {

_value = "0";

} else {

if (index == undefined) {

index = 0;

}

this._value = this._memory[index].toString(this._system);

}

isnew = 1;

this.broadMessage("MR");

}

public function MS(index:Number) { // 将数字储存在存储区

if (_value != "0") {

if (index == undefined) {

index = 0;

}

if (_system == 10) {

this._memory[index] = Number(this._value);

} else {

this._memory[index] = parseInt(this._value, this._system);

}

isnew = 1;

this.broadMessage("MS");

}

}

public function MP(index:Number) { // 将存储区的数字与以有数字相加

if (_value != "0") {

if (index == undefined) {

index = 0;

}

if (_system == 10) {

this._memory[index] += Number(this._value);

} else {

this._memory[index] += parseInt(this._value, this._system);

}

isnew = 1;

this.broadMessage("M+");

}

}

public function get memory():Array {

return this._memory;

}

public function get hasMemory():Boolean {

return (this._memory.length != 0);

}

public function set system(n:Number) {

if (n>=2 && n<=36) {

this._system = n;

this.broadcastMessage("onChange", this, "SystemChange");

}

}

public function get system():Number {

return this._system;

}

public function set unit(n:Number) {

if (n == 1) {

this.units = 1;

} else if (n == 0) {

this.units = 0;

} else if (n == 2) {

this.units = 2;

}

this.broadcastMessage("onChange", this, "UnitChange");

}

public function get unit():Number {

return this.units;

} //统计计算

public function Sta() { //进入,退出统计模式

if (data == undefined) {

this.data = [];

} else {

this.data = undefined;

}

this.datam = {Ave:undefined, Ave2:undefined, Sum:undefined, Sum2:undefined, S:undefined, S2:undefined};

this.isnew = 1;

this.broadMessage("Sta");

}

private function getSum() { //求数据和

//Sum=x1+x2+x3+...+xn

var num:Number = 0;

for (var i in this.data) {

num += this.data[i];

}

this.datam.Sum = num;

}

private function getSum2() { //求数据平方和

//Sum=x1*x1+x2*x2+x3*x3+...+xn*xn

var num:Number = 0;

for (var i in this.data) {

num += this.data[i]*this.data[i];

}

this.datam.Sum2 = num;

}

上一页 下一页
[1] [2] [3] [4]
免费订阅】【发表评论】【动画论坛】【  】【关闭
发表评论
 QQ号码:
 QQ密码:
 验证码: 匿名发表
* 请各位网友遵纪守法并注意语言文明。
*《互联网电子公告服务管理规定》
*《全国人大常委会关于维护互联网安全的规定》




关于腾讯 | About Tencent | 服务条款 | 广告服务 | 腾讯招聘 | 腾讯公益 | 客服中心 | 网站导航
Copyright © 1998 - 2008 Tencent Inc. All Rights Reserved
腾讯公司 版权所有