我写的一个复数的类,大家看对不对?
时间:2010-05-11
来源:互联网
我写的一个复数的类,大家帮我看看,我在类里面调用了自身,这样对不对?
var images = function (x,y)
{
this.x=x;
this.y=y;
this.angle= function(){ return Math.atan(y/x);} //幅角
this.modes= function(){ return Math.sqrt(x*x+y*y); } //模
this.max= function() { return (x>y)?x:y;} //最大值
this.min= function() { return (x<y)?x:y;} //最小值
this.quad= function() //所在象限
{
if(x>=0&&y>=0){ return 1;}
if(x>=0&&y<0){ return 4;}
if(x<0&&y>=0){ return 2;}
if(x<=0&&y<=0){ return 3;}
}
this.add= function(z) {alert(222); return new images( this.x+z.x, this.y+z.y); } //加
this.reduce= function(z) { return new images( this.x-z.x, this.y-z.y); }//减
this.flipy= function(){ return new images( this.x, -this.y); } //x翻转
this.flipx= function(){ return new images( - this.x, this.y); }//y翻转
this.inv= function() { return new images( - this.x, - this.y); } //中心对称
this.multi= function(z) //乘法
{
return new images( this.x*z.x- this.y*z.y, this.x*z.y+ this.y*z.x);
}
this.recip= function() //倒数
{
return new images( this.x/( this.x* this.x+ this.y* this.y), - this.y/( this.x* this.x+ this.y* this.y));
}
this.div = function(t) //除以实数
{
return new images( this.x/t, this.y/t);
}
this.divide= function(z) //除法
{
return new images( this.multi(z).div(z.x*z.x+z.y*z.y));
}
}
var z1= new images(1,2);
var z2= new images(3,4);
var z=z1.add(z2);
var x=z.x;
var y=z.y;;
alert(x+","+y)
var images = function (x,y)
{
this.x=x;
this.y=y;
this.angle= function(){ return Math.atan(y/x);} //幅角
this.modes= function(){ return Math.sqrt(x*x+y*y); } //模
this.max= function() { return (x>y)?x:y;} //最大值
this.min= function() { return (x<y)?x:y;} //最小值
this.quad= function() //所在象限
{
if(x>=0&&y>=0){ return 1;}
if(x>=0&&y<0){ return 4;}
if(x<0&&y>=0){ return 2;}
if(x<=0&&y<=0){ return 3;}
}
this.add= function(z) {alert(222); return new images( this.x+z.x, this.y+z.y); } //加
this.reduce= function(z) { return new images( this.x-z.x, this.y-z.y); }//减
this.flipy= function(){ return new images( this.x, -this.y); } //x翻转
this.flipx= function(){ return new images( - this.x, this.y); }//y翻转
this.inv= function() { return new images( - this.x, - this.y); } //中心对称
this.multi= function(z) //乘法
{
return new images( this.x*z.x- this.y*z.y, this.x*z.y+ this.y*z.x);
}
this.recip= function() //倒数
{
return new images( this.x/( this.x* this.x+ this.y* this.y), - this.y/( this.x* this.x+ this.y* this.y));
}
this.div = function(t) //除以实数
{
return new images( this.x/t, this.y/t);
}
this.divide= function(z) //除法
{
return new images( this.multi(z).div(z.x*z.x+z.y*z.y));
}
}
var z1= new images(1,2);
var z2= new images(3,4);
var z=z1.add(z2);
var x=z.x;
var y=z.y;;
alert(x+","+y)
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title>无标题</title> <meta name="generator" content="Namo WebEditor"> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <script> var images = function (x,y) { this.x=x; this.y=y; this.angle= function(){ return Math.atan(y/x);} //幅角 this.modes= function(){ return Math.sqrt(x*x+y*y); } //模 this.max= function() { return (x>y)?x:y;} //最大值 this.min= function() { return (x<y)?x:y;} //最小值 this.quad= function() //所在象限 { if(x>=0&&y>=0){ return 1;} if(x>=0&&y<0){ return 4;} if(x<0&&y>=0){ return 2;} if(x<=0&&y<=0){ return 3;} } this.add= function(z) {alert(222); return new images( this.x+z.x, this.y+z.y); } //加 this.reduce= function(z) { return new images( this.x-z.x, this.y-z.y); }//减 this.flipy= function(){ return new images( this.x, -this.y); } //x翻转 this.flipx= function(){ return new images( - this.x, this.y); }//y翻转 this.inv= function() { return new images( - this.x, - this.y); } //中心对称 this.multi= function(z) //乘法 { return new images( this.x*z.x- this.y*z.y, this.x*z.y+ this.y*z.x); } this.recip= function() //倒数 { return new images( this.x/( this.x* this.x+ this.y* this.y), - this.y/( this.x* this.x+ this.y* this.y)); } this.div = function(t) //除以实数 { return new images( this.x/t, this.y/t); } this.divide= function(z) //除法 { return new images( this.multi(z).div(z.x*z.x+z.y*z.y)); } } var z1= new images(1,2); var z2= new images(3,4); var z=z1.add(z2); var x=z.x; var y=z.y;; alert(x+","+y) </script> </body> </html>
提示:您可以先修改部分代码再运行
[ 本帖最后由 Einsy 于 2010-5-11 17:54 编辑 ] 提示:您可以先修改部分代码再运行
作者: Einsy 发布时间: 2010-05-11
你的最大值最小值什么意思。
作者: su1216 发布时间: 2010-05-12
这个是可能用到的x,y中最大的一个值
作者: Einsy 发布时间: 2010-05-12
那和复数有什么关系
作者: su1216 发布时间: 2010-05-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28