e$B$1$$$8$e!w$$$7$D$+$G$9e(B.
In the message: "[ruby-dev:35869] Re: Complex & Rational ", on Aug/19
00:22(JST) Tadayoshi F. writes:
ruby-dev e$B$K%a!<%k$,FO$+$J$$$N$G!“D>@$G$9$_$^$;$s$,!”$$$/$D$+3NG’$5$;$Fe(B
e$B$/$@$5$$!#e(B
e$B$U$J$P$5$s$N%F%9%H%a%$%k$OFO$$$F$$$?$_$?$$$G$9$,e(B…
e$B$H$j$"$($:e(B, ruby-dev e$B$K$be(BCce$B$rF~$l$F$"$j$^$9e(B.
e$B$G$9$N$Ge(B, e$B$3$N9M$($,0];}$5$l$k$J$ie(B, e$BB>$N$b$N$K$J$C$F$b$+$^$$$^$;$se(B.
e$BNc$($Pe(B, e$B8e$G$G=P$F$/$ke(B, scalar?(e$B$H$+e(Breal?) e$B$G$b<B8=2DG=$G$9$Me(B.
e$B0l1~8x3+$5$l$F$$$k$N$G!#$=$l$G!"<B:]$K$O!"e(Bgeneric? e$B$O!“e(BCMath (Math) e$B$Ne(B
e$B$”$?$j$G$7$+$D$+$o$l$*$i$:!"8@$o$l$k$h$&$K!"e(Bscalar? e$B$GCV$-49$($k$3$H$Ge(B
e$B$h$$$H;W$$$^$9!#e(B
e$B$3$N7o$K$7$F$Oe(B, e$B%O%$$J$s$G$9$,e(B…
generic?e$B$,;H$o$l$F$$$J$$$H$N$3$H$J$N$Ge(B…
e$B%=!<%9$r8+$k$He(B, e$B0J2<$N$h$&$K$J$C$F$$$^$9$,e(B,
static VALUE
nucomp_add(VALUE self, VALUE other)
{
switch (TYPE(other)) {
case T_FIXNUM:
case T_BIGNUM:
case T_FLOAT:
case T_RATIONAL:
{
get_dat1(self);
return f_complex_new2(CLASS_OF(self),
f_add(dat->real, other), dat->image);
}
case T_COMPLEX:
{
VALUE real, image;
get_dat2(self, other);
real = f_add(adat->real, bdat->real);
image = f_add(adat->image, bdat->image);
return f_complex_new2(CLASS_OF(self), real, image);
}
default:
return rb_num_coerce_bin(self, other, ‘+’);
}
e$B$3$&$G$J$/$Fe(B, T_FIXNUM, T_BIGNUM, T_FLOAT, T_RATIONAL
e$B$@$1$K$+$.$i$:e(B,
other e$B$,e(B real?(scalar?) e$B$@$C$?$ie(B,
return f_complex_new2(CLASS_OF(self),
f_add(dat->real, other), dat->image);
e$B$G$-$k$H8@$$$?$$$o$1$J$s$G$9$he(B.
{Complex,Rational}#inspect e$B$N=q<0$rJQ99$7$?$$!#e(B
e$BA0<T$H$$$&$3$H$O!"e(Bto_s e$B$HF1$8$G$h$$$H$$$&$3$H$G$9$+!#3NG’$7$?$$$N$G$9e(B
e$B$,!"e(B
e$B$$$(e(B, e$B3g8L$D$-$G$C$F$3$H$G$9e(B.
to_se$B$O:F5"E*$K8F$P$l$k$3$H$O$"$^$j$J$$$Ge(B
e$B$9$7e(B, e$B$"$C$F$be(B, e$B8F$S=P$9B&$,9M$($l$P$h$$$3$H$G$9$,e(B,
inspect e$B$O:F5"E*$Ke(B
e$B8F$P$l$k$N$,A0Ds$J$N$Ge(B,
e$B%*%V%8%’%/%H$N6-3&$OL@3N$K$J$C$FM_$7$$$G$9e(B.
Complex(3,1).to_s #=> “3+i”
e$B$N$h$&$J$3$H$b$"$jF@$k$G$7$g$&!#e(B
e$B$=$&$+e(B, e$B0l4S@-$,$J$+$C$?$s$G$9$Me(B…
e$B0l8+$7$F6hJL$9$k$?$a$K$O!“e(Bto_se$B!“e(Binspect e$B$H$b$K@55,2=$7$J$$$+!”$”$k$$$O!"e(B
e$B>/$J$/$H$be(B inspect e$B$G$O@55,2=$7$J$$$h$&$K$;$M$P$J$i$J$$$h$&$K;W$$$^$9!#e(B
e$B$I$A$i$,K>$^$7$$$G$7$g$&$+!#e(B
e$BN><T$H$b@55,2=$7$J$$J}$,$h$$5$$,$7$F$-$^$7$?e(B. to_se$B$Ge(B “1”
e$B$,JV$k$H@0?te(B
e$B$Ne(B1e$B$H4*0c$$$7$=$&$G$9$b$N$Me(B.
e$B$D$.$K!"e(B
Complex(Rational(1,3),Rational(1,3)).to_s #=> “1/3+(1/3)i”
e$B$H$J$C$F$$$k$N$G$9$,!"$?$H$($P!“e(BMIT Scheme e$B$J$I$$$/$D$+$Ne(B Scheme e$B=hM}7Oe(B
e$B$J$I$N7k2L$HHf$Y$F;W$&$N$O!“5uIt$,M-M}?t$N>l9g$N3g8L$OI,MW$J$N$+!”$H$$e(B
e$B$&$3$H$G$9!#e(Binspect e$B$N;v$r9M$($F$$$?$i!”$+$J$jHyL/$J46$8$K;W$($F$-$^$7e(B
e$B$?!#e(B
e$B$o$6$o$6$3$&$d$C$F$$$k$s$G$9$h$Me(B. 1/3i e$B$@$He(B 1/(3i)
e$B$K8+$($k$J$H;W$C$?e(B
e$B$s$G$9e(B. e$B$=$l$Ke(B,
(1/3)i e$B!be(B 1/(3i) e$B!ae(B -(1/3)i
e$B$G$9$7e(B… e$B$^$"e(B, e$B$?$@e(B, e$B$=$l$O?t<0$H$7$F$NOC$Ge(B,
Rubye$B>e$NI=5-$H$7$F$3$&$J$Ce(B
e$B$F$$$k$H$9$l$PLdBj$J$$5$$b$7$^$9e(B.
e$BB>$N=hM}7O$G0lHLE*$J$i$=$l$[$I$3$@$oe(B
e$B$j$^$;$se(B. – (A)
Complex(Rational(1,3),Rational(1,3)).to_s #=> “1/3+1/3i”
Complex(Rational(1,3),Rational(1,3)).inspect #=> “((1/3)+(1/3)i)”
e$B$H$$$&$o$1$K$O$$$+$J$$$G$7$g$&$+!#e(B
e$BI=8=E*$K$O0l4S@-$,$"$j$^$9$h$Me(B. e$B$"$H$Oe(B,
e$B>e5-e(B(A)e$B$NOC$@$1$G$9$,e(B, scheme
e$B0J30$C$F$I$&$J$C$F$$$k$s$G$7$g$&$+$Me(B…
scheme e$B$Oe(B 1/3+1/3i e$B$C$Fe(B atom
e$B$G85!93F8D$D$1$i$l$J$$$G$9$7e(B… e$B$3$&$G$"e(B
e$B$k$Y$-$H9M$($?$N$+e(B,
e$B$3$l$7$+I=8=$N$7$h$&$,$J$+$C$?$N$+H=CG$G$-$J$$$G$9e(B
e$B$7e(B…
mathematica e$B$Oe(B
1i
3
e$B8+$?$$$J46$8$G$9$Me(B. e$B$3$l$O$3$l$G$9$4!<$/G<F@$G$9$,e(B,
e$B$+$J$jFCJL07$$$7$Je(B
e$B$$$H$$$1$J$$$G$9$7$M$'e(B.
__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—