Python less error-prone than Java
"Martin v. Löwis"
martin at v.loewis.de
Mon Jun 5 04:22:27 EDT 2006
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
More information about the Python-list
mailing list