Christoph Zwerschke wrote:
> Anyway, in Python, you would first define:
> 
> def wrap(x, at=1<<31):
>     if x < -at:
>         x += at*2
>     elif x >= at:
>         x -= at*2
>     return x
> 
> Then, the Python program would be as simple:
> 
> Distance = lambda t1,t0: wrap(t1-t0)

In Python 2.4 and later, you could write

def Distance(t1, t0, maxint=(1<<32)-1):
  return (t1-t0) & maxint

Like your code, this also extends to 24-bit integers or 64-bit
integers.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to