retitle 299847 [fixed in 2.4] shift operator doesn't extend to longs
tags 299847 + fixed-upstream
thanks

Did you see the warning?

tai64nlocal.py:16: FutureWarning: x<<y losing bits or changing sign will return 
a long in Python 2.4 and up secs <<= 4

that's "fixed" in python2.4.


Toni Mueller writes:
> 
> 
> 
> Package: python2.3
> Version: 2.3.5-1
> Severity: normal
> 
> *** Please type your report below this line ***
> 
> Hello,
> 
> I've tried to convert DJB's "tai64nlocal" program from C to Python. This
> looks easy since the code can more or less be used 1:1 in both
> languages, but requires proper handling of very long integers.
> 
> This is not the case: underway, the variables were turned negative after
> shifts, and not extended. Exchanging the shifts ("<<=") with
> multiplications ("*=") fixed the results. The code:
> 
> ----------- cut
> import sys, string
> from time import mktime, localtime
> 
> digits = { '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6,
>            '7': 7, '8': 8, '9': 9, 'a': 10, 'b': 11, 'c': 12,
>           'd': 13, 'e': 14, 'f': 15 }
> 
> def readTai64 (stamp):
>     secs = 0
>     nanosecs = 0
>     for i in stamp:
>       if i == '@': continue
>       if i > 'f': break
>       print "readTai64(%s): i= %s" % (stamp, i)
>       u = digits[i]
>       secs *= 16
>       secs += nanosecs >> 28
>       nanosecs &= 0x0fffffff
>       nanosecs *= 16
>       nanosecs += u
>       print "readTai64(%s): u= %s secs= %s nanosecs= %s" % (stamp, u,
> secs, nanosecs)
>     secs -= 4611686018427387914
>     t = localtime(secs)
>     return [ t, secs, nanosecs ]
> 
> if __name__ == '__main__':
>     """simulate tai64nlocal"""
>     for f in sys.argv[1:]:
>       for l in file(f):
>           print "l: %s\n" % l
>           stamp, body = string.split (l, ' ', 1)
>           print readTai64(stamp), body
> ----------- cut
> 
> 
> Test case data:
> 
> @400000004238b09c2cc80704 something
> 
> should result in printing a time stamp of 2005-03-16 23:17:54.751306500,
> but won't if you put back in the shift operators.
> 
> 
> 
> Best,
> --Toni++
> 
> 
> 
> -- System Information:
> Debian Release: 3.1
>   APT prefers unstable
>   APT policy: (500, 'unstable'), (1, 'experimental')
> Architecture: i386 (i686)
> Kernel: Linux 2.4.27-2-686-smp
> Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15)
> 
> Versions of packages python2.3 depends on:
> ii  libbz2-1.0                  1.0.2-5      high-quality block-sorting file 
> co
> ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries 
> an
> ii  libdb4.2                    4.2.52-18    Berkeley v4.2 Database Libraries 
> [
> ii  libncurses5                 5.4-4        Shared libraries for terminal 
> hand
> ii  libreadline4                4.3-15       GNU readline and history 
> libraries
> ii  libssl0.9.7                 0.9.7e-3     SSL shared libraries
> ii  zlib1g                      1:1.2.2-4    compression library - runtime
> 
> -- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to