+ -
当前位置:首页 → 问答吧 → 我写的一个复数的类,大家看对不对?

我写的一个复数的类,大家看对不对?

时间: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)
<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