number comparison problem
David Lees
debl2Nonosapmmyyy at bellatlantic.net
Tue Oct 15 23:35:31 EDT 2002
You are assuming that the default print is displaying all the digits in
your number. Try this:
>>> x=0.132945911028
>>> y=x+10**(-13)
>>> print x,y
0.132945911028 0.132945911028
>>> print y>x
1
You might want to go look at the
http://www.python.org/doc/current/tut/node14.html
david lees
Chris Fonnesbeck wrote:
>
> I am using python to code an optimization function that requires
> numbers to be compared to one another, as is common in many
> algorithms. However, the comparison operators (<,>,<=,>=,==) seem not
> to be working properly. Regard the following:
>
> >>> print fb,fc
>
> 0.132945911028 0.132945911028
>
> >>> print fb>fc
>
> 1
>
> These numbers look the same to me; what do I have to do to be able to
> test numbers accurately in python?
>
> TIA,
> cjf
More information about the Python-list
mailing list