GMPY compare warning

From: Mensanator (mensanator_at_aol.compost)
Date: 11/29/03


Date: 29 Nov 2003 05:17:40 GMT

In the program that follows, I get the following warning message:

collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1
  while b>1:

In this case, b is a gmpy.mpz number. The program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?

import sys
import time
import gmpy

i = long(sys.argv[1])

n = 2**(i) - 1

r1 = 0
r2 = 0
t0 = time.time()

a = n

while a>1:
        z = divmod(a,2)
        if z[1]==0:
                a = z[0]
                r1 += 1
        else:
                a = a*3 + 1
                r2 += 1

t1 = time.time()

print "r1",r1,"r2",r2,"in",t1-t0,"seconds\n"

b = gmpy.mpz(n)

r1 = 0
r2 = 0
t0 = time.time()

while b>1:
        z = gmpy.scan1(b)
        if z==0:
                b = b*3 + 1
                r2 += 1
        else:
                b = b/(2**z)
                r1 += z

t1 = time.time()

print "r1",r1,"r2",r2,"in",t1-t0,"seconds\n"

"""
C:\Python23\user>python collatz_.py 1000
r1 7841 r2 4316 in 0.109000086784 seconds
r1 7841 r2 4316 in 0.375 seconds

C:\Python23\user>python collatz_.py 10000
r1 86278 r2 48126 in 6.42199993134 seconds
r1 86278 r2 48126 in 4.85900008678 seconds

C:\Python23\user>python collatz_.py 100000
r1 863323 r2 481603 in 604.766000032 seconds
r1 863323 r2 481603 in 121.859999895 seconds
"""

--
Mensanator
Ace of Clubs


Relevant Pages

  • Re: gmpy 1.01 rc near... anybody wanna test>
    ... It looks like the warning about "tp_compare" has been fixed. ... Thanks for the updates to gmpy! ... Prev by Date: ...
    (comp.lang.python)
  • RE: Receiving notification on exchange storage limits
    ... Click to select one or all of the following check boxes under Storage ... Issue warning at: Select this check box to warn the user that their ... in the Warning message interval box or click Customize. ... Use System Policies to Configure Mailbox Storage Limits in Exchange ...
    (microsoft.public.windows.server.sbs)
  • Re: while (1) vs. for ( ;; )
    ... >>>errant warning message. ... >>>out of the compiler, ... The original phrase was "errant warning message". ... believe that infinite loops usually should be recast ...
    (comp.lang.c)
  • Re: Should compilers elide errors when possible?
    ... in general the compiler isn't going to see all the code. ... "Infinite loop executed") and emits a warning while ... other than printing the warning message. ...
    (comp.lang.lisp)
  • Re: open file security warning "unknown publisher"
    ... Your Terminal Services Security Website ... The warning message does say "unknown publisher", ... executes flawlessly, whilst the other app throws up a warning ...
    (microsoft.public.windows.terminal_services)