Problem with real-accurate module num != num

jepler epler jepler.lnk at lnk.ispi.net
Sun Jul 9 13:21:26 EDT 2000


On Sun, 09 Jul 2000 23:06:19 +1000, cmfinlay at SPAMmagnet.com.au
 <cmfinlay at SPAMmagnet.com.au> wrote:
>I am having problems with the code below
>
>QUOTE
>from real import *
>num = r(0)
>num_real = r(0)
>if num == num_real:
>   print "ok"
>else:
>   print "Bad" # the code goes here.
>UN QUOTE
>
>Also
>
>if num_real == 0
>
>Goes to the wrong place as well.

you need to implement real.r.__cmp__().

real.r.__cmp__(a, b) should return:
	0 if a and b are equal
	-1 if a is less than b
	+1 if a is greater than b
just as the builtin cmp() function returns.

A common error is for __cmp__() to be written so that it returns
	0 if a and b are unequal
	+1 if a and b are equal
but of course, there's no way for python to diagnose this programming error.

Jeff



More information about the Python-list mailing list