Re: [q-lang-users] improvement to Q
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-06-27 23:41:47
|
ed...@ri... wrote: > I hope other Q users don't boo me but, I would like to see x^n return > integer results when x is an integer and n is a natural number. Maybe > even return a rational when n is a negative integer. The pow function already does this: ==> whos pow pow external function symbol defined in /usr/share/q/lib/clib.q pow X1 X2 ==> pow 2 64 18446744073709551616 ==> pow 2 (-2) 1%4 ==> pow (2%3) (-2) 9%4 So if you prefer to have this as an operator, simply define: public (^^) X Y @ (^); X:Num^^Y:Num = Z where Z:Num = pow X Y; If you want to have the operator work with floats as well, just add: X:Num^^Y:Num = Z where Z:Num = X^Y; A while ago there was a heated discussion over whether (^) should provide that functionality but, as John already pointed out, it's really better to have two different operations here, for various reasons. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |