[Numpy-discussion] Re: numpy, overflow, inf, ieee, and rich comparison

Huaiyu Zhu hzhu at users.sourceforge.net
Thu Oct 26 13:57:43 EDT 2000


On Thu, 26 Oct 2000 02:05:29 GMT, Huaiyu Zhu <hzhu at users.sourceforge.net>
wrote: 
>
>So let's ask the question in another way: Is there a technical reason
>(performance, implementation details, etc) not to have a rational type,
>given the existence of a complex type?

Answering my own question: I think rational type is too costly to be useful
by default.  Without eliminating common factors, fraction operations will
accumulate them.  Then they will be using longs that are very long and
costly.  But adding factorization to arithmetics would be costly, too.

Given that 2-7==-5 and sqrt(2)==1.4142135..., maybe 2/3==0.666... is the
most consistent, which could be charactorized as "reasonably effecient and
reasonably accurate approximation to the correct value". 

Additional functions like possub(2,7)==0, intsqrt(2)==1 and intdiv(2,3)==0
would satisfy the situation where representational types are more important
than accuracy.  That could make an unsigned int type useful, too. :-)
Want to utilize machine efficiency of integer operations as opposed to
floating point operations?  intadd(3.5, 8) could be doing
int(3.5)+8.

Huaiyu



More information about the Python-list mailing list