Maya isnt completing a simple loop??!!

Maya isnt completing a simple loop??!!

Anonymous
Not applicable
722 Views
5 Replies
Message 1 of 6

Maya isnt completing a simple loop??!!

Anonymous
Not applicable
hy guys and girl,

i hope this is the right place to post my problem.
i scripted a simple loop to put a certain range of numbers into an array. but maya is just not completing the whole loop. i dont get it why it behaves like that.
by the way im running "Autodesk® Maya®, Version 8.5 x64" .

here is the script :

global proc test()
{

float $variable_01 ;
float $myArray01[] ;

$variable_01 = 0.4 ;

float $x;
int $i = 0 ;

for($x = (-1.0) ; $x <= 1 ; $x+= 0.1)

{
$myArray01 = $variable_01 + $x ;
$i++ ;
}
;

print $myArray01;
print (size($myArray01)+"\n") ;
}
test();

if you c+p this to maya and run it, it'll give you the whole array plus the information about how many numbers are in the array (200). but there should be 201 values (200 values + "0"). the last value given is 1.39 . the first value in the array and all the other that follow are just as expected and correct, but somehow maya doesnt run the loop till the end.

If you strip away one zero from the iteration

for($x = (-1.0) ; $x <= 1 ; $x+= 0.01)
to
for($x = (-1.0) ; $x <= 1 ; $x+= 0.1)

and run the script again, you dont get that problem.
the loop runs correctly an gives you back 21 values and as the last value 1.4.
otherwise if you take the iteration to an even lower level e.g. "0.001" it produces the same problem.
why does this happen? maya-internal-rounding-bug?

i would be very gratefull if somebody could explain to me why that is happening.
is it a known problem?

greetz
stefan
0 Likes
723 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
hummm....I don't see the problem in your code, but this works.

{
float $x;
float $array[];
int $i = 0;
for($x = -1.0; $x <= 1.0; $x += 0.1){
$array = 0.4 + $x;
$i++;
print ($x + " ");
}
print "\n";
print $array;
}
0 Likes
Message 3 of 6

Anonymous
Not applicable
@paulalso : thnx, but as i said the loop runs smooth when keeping the "0.1" case. the problem only occurs when you take the iteration to "0.01" or further to "0.001", "0.0001", etc.
nevertheless, thnx for replying. cheers
0 Likes
Message 4 of 6

Anonymous
Not applicable
oh, I see what you are talking about......that is strange........have you posted your question elsewhere, like highend or cgtalk?......
If you test $x <= 1.0000001 the darn thing works fine for values of $x less then 0.1.......
0 Likes
Message 5 of 6

Anonymous
Not applicable
yes, i tested it with those "1.000.....1" and its true that in this manner it works fine...but its just not quite what i wanted to achieve.
i posted it on cgtalk and a asian guy answered my question, its kind of a problem how maya interprets float numbers....he said not to use >= or <= with floats if you need exact results. the link is
http://forums.cgsociety.org/showthread.php?f=7&t=566120
hope its usefull to you

still thanks for taking your time to figure out the problem.
cheers
0 Likes
Message 6 of 6

Anonymous
Not applicable
you mean it is the way all computers handle float numbers............I was wondering why no one uses floats as you were....now we know.
0 Likes