Problem with real-accurate module num != num

david_ullrich at my-deja.com david_ullrich at my-deja.com
Sun Jul 9 14:58:19 EDT 2000


In article <nndoOWltXGEw7f=5YdyL54JFUe+J at 4ax.com>,
  cmfinlay at magnet.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.

    All you have to do is add a __cmp__ method to a subclass.
With no __cmp__ method real instances get compared by object
identity (address?), which is not what you want.

    There are other problems with real.py - you may want to
try Tim's fixed-point class (you can find hints on how
__cmp__ should work there in any case). I think it's
fp.py, available everywhere (except I don't appear to
have a copy on the machine in the office or I could tell
you for sure what it's called...)

DU

> Any help would be very much appreciated
>
> Col. Finlay
> cmfinlaySPAM at magnet.com.au
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list