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

Annotation of OpenXM/src/k097/debug/complex0.kk, Revision 1.1

1.1     ! maekawa     1: /* complex0.kk , 1997, 4/17 */
        !             2: /*  complex の第0版 */
        !             3:
        !             4: class Complex extends Object {
        !             5:   local re, /* 実部 */
        !             6:         im; /* 虚部 */
        !             7:   def new2(a,b) {
        !             8:     this = new(super.new0());
        !             9:     re = a;
        !            10:     im = b;
        !            11:     return(this);
        !            12:   }
        !            13:   def real() { return(re); }
        !            14:   def imaginary() { return(im); }
        !            15:   def operator add(b) {
        !            16:     return( new2(re+b.real(), im+b.imaginary()) );
        !            17:     /* return( new0(re+b.real(), im+b.imaginary()) );
        !            18:        このようなエラーをしても, エラーがおきない.  これは問題. */
        !            19:     /* 片方が, プリミティブオブジェクトでも大丈夫なように書き換える.
        !            20:        実は operator override の方法は数学の記述にはいまひとつなのでは?
        !            21:        Mathematica は, 引数のデータ型を記述できるようになっている.
        !            22:        でも, ! IsObject() で分類していけばいい.
        !            23:        引数を二つみて, つまり this, b の順に context を決めていくのは,
        !            24:        私の idea.
        !            25:     */
        !            26:   }
        !            27:   def operator sub(b) {
        !            28:     return( new2(re-b.real(), im-b.imaginary()) );
        !            29:   }
        !            30:   def operator mul(b) {
        !            31:     return(new2( re*b.real()-im*b.imaginary(), re*b.imaginary()+im*b.real()));
        !            32:   }
        !            33:   def operator div(b) {
        !            34:     local den,num1,num2;
        !            35:     den = (b.real())^2 + (b.imaginary())^2 ;
        !            36:     num1 = re*b.real() + im*b.imaginary();
        !            37:     num2 = -re*b.imaginary()+im*b.real();
        !            38:     return(new2(num1/den, num2/den));
        !            39:     /* den == 0 なら, isInvalidRational() がエラーをだすはず.
        !            40:        このような, こと知らないと, プログラムを書けないのは良くない?
        !            41:     */
        !            42:   }
        !            43:
        !            44:   def void show() {
        !            45:     Print(re); Print(" +I["); Print(im); Print("]");
        !            46:   }
        !            47:   def void showln() {
        !            48:     this.show(); Ln();
        !            49:   }
        !            50: }
        !            51:
        !            52:

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