tuple(int, int) --> FixedPoint; is there a better way?

Greg Ewing see_reply_address at something.invalid
Mon Dec 2 21:58:05 EST 2002


>>>>>>Henrik.Weber at sys.aok.de (Henrik Weber) (HW) writes:
> 
> HW>             self.n = value[0] * 2**32 + long("%u" % value[1])
> 
> if value[1] < 0 then add 2**32 to it.


Also, shifting left 32 bits is probably faster
than multiplying by 2**32.

So how about:

   def funny_tuple_to_long((hi, lo)):
     if lo < 0:
       hi += 1
     return (hi << 32L) + lo

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list