array precision

Hugo Martires hugomartires at hotmail.com
Fri Feb 8 08:16:49 EST 2002


"Emile van Sebille" <emile at fenx.com> wrote in message news:<a3retd$19cgik$1 at ID-11957.news.dfncis.de>...
> "Hugo Martires" <hmartires at cultalg.pt> wrote in message
> news:st888.7971$oI4.33917985 at newsserver.ip.pt...
> > but i don´t need all the numbers, i only need 0.6
> 
> See 4.98 in the FAQ at http://python.org/doc/FAQ.html

I have read it but still confused.
Se my point:
--> n=0

myArray = array.array('f', [0.5, 0.5, 0.5, 0.5]

myArray[i] = myArray[i] + (1.0/n)

myArray[0] = 0.600000023 ("something like this")

for i in range ( len(myArray) ):
	if (myArray[i] > 0.0) and (myArray[i]<1.0):
		exit(0)

The problem is that he it never exit, unless i do like this:
for i in range ( len(myArray) ):
	if (myArray[i] > 0.0001) and (myArray[i]<0.9999):
		exit(0)

that is not the better way :(

------------------------------------------------------------------
I have tried with:
    myArray=array.array('f')
    myArray=array.array('d')
and even with a list:  myArray=[]

I know that the problem is in the internal storage of the numbers, but
i canot understand how to solve that.
I just want to make a simple calculation and an if statement.

Tanks for help



More information about the Python-list mailing list