Re: [q-lang-users] improvement to Q
Brought to you by:
agraef
From: <ed...@ri...> - 2007-06-28 00:57:37
|
<html>=0D =0D <P><BR> Ok :) I promise I looked for this function. I guess I overlooked it many ti= mes. I wonder what other goodies I've overlooked many times?</P>=0D <P>Eddie<BR> <BR> <BR> <B>On Wed Jun 27 18:52 , Albert Graef <Dr....@t-...> sent:<BR> <BR> </P></B>=0D <BLOCKQUOTE style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5p= x; BORDER-LEFT: #f5f5f5 2px solid; MARGIN-RIGHT: 0px"><A href=3D"javascript= :top.opencompose('ed...@ri...','','','')">ed...@ri...= </A> wrote:<BR> <FONT color=3Dred>> I hope other Q users don't boo me but, I would like = to see x^n return</FONT><BR> <FONT color=3Dred>> integer results when x is an integer and n is a natu= ral number. Maybe</FONT><BR> <FONT color=3Dred>> even return a rational when n is a negative integer.= </FONT><BR> <BR> The pow function already does this:<BR> <BR> =3D=3D> whos pow<BR> <BR> pow external function symbol defined in /usr/share/q/lib/clib.q<BR> pow X1 X2<BR> <BR> =3D=3D> pow 2 64<BR> 18446744073709551616<BR> <BR> =3D=3D> pow 2 (-2)<BR> 1%4<BR> <BR> =3D=3D> pow (2%3) (-2)<BR> 9%4<BR> <BR> So if you prefer to have this as an operator, simply define:<BR> <BR> public (^^) X Y @ (^);<BR> <BR> X:Num^^Y:Num =3D Z where Z:Num =3D pow X Y;<BR> <BR> If you want to have the operator work with floats as well, just add:<BR> <BR> X:Num^^Y:Num =3D Z where Z:Num =3D X^Y;<BR> <BR> A while ago there was a heated discussion over whether (^) should<BR> provide that functionality but, as John already pointed out, it's really<BR> better to have two different operations here, for various reasons.<BR> <BR> Albert<BR> <BR> -- <BR> Dr. Albert Gr"af<BR> Dept. of Music-Informatics, University of Mainz, Germany<BR> Email: <A href=3D"javascript:top.opencompose('Dr....@t-...','','','= ')">Dr....@t-...</A>, <A href=3D"javascript:top.opencompose('ag@muw= iinfa.geschichte.uni-mainz.de','','','')">ag...@mu...schichte.uni-mainz.= de</A><BR> WWW: <A href=3D"parse.pl?redirect=3Dhttp%3A%2F%2Fwww.musikinformatik.uni-ma= inz.de%2Fag" target=3D_blank><FONT color=3Dred>http://www.musikinformatik.u= ni-mainz.de/ag</FONT></A><BR> </BLOCKQUOTE>=0D </html><BR>= |