[BACK]Return to complex01.kk CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097 / debug

Annotation of OpenXM/src/k097/debug/complex01.kk, Revision 1.1.1.1

1.1       maekawa     1: class Complex extends Object {
                      2:   local re, /* real part */
                      3:         im; /* imaginary part*/
                      4:   def new2(a,b) {
                      5:     this = new(super.new0());
                      6:     re = a;
                      7:     im = b;
                      8:     return(this);
                      9:   }
                     10:   def real() { return(re); }
                     11:   def imaginary() { return(im); }
                     12:   def operator add(b) {
                     13:     return( new2(re+b.real(), im+b.imaginary()) );
                     14:   }
                     15:   def operator sub(b) {
                     16:     return( new2(re-b.real(), im-b.imaginary()) );
                     17:   }
                     18:   def operator mul(b) {
                     19:     return(new2( re*b.real()-im*b.imaginary(), re*b.imaginary()+im*b.real()));
                     20:   }
                     21:   def operator div(b) {
                     22:     local den,num1,num2;
                     23:     den = (b.real())^2 + (b.imaginary())^2 ;
                     24:     num1 = re*b.real() + im*b.imaginary();
                     25:     num2 = -re*b.imaginary()+im*b.real();
                     26:     return(new2(num1/den, num2/den));
                     27:   }
                     28:
                     29:   def void show() {
                     30:     Print(re); Print(" +I["); Print(im); Print("]");
                     31:   }
                     32:   def void showln() {
                     33:     this.show(); Ln();
                     34:   }
                     35: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>