|10 October 2005||#1|
tapping his potentialportfolio
Join Date: Feb 2004
Interpret This Line of code
I need some help on how to read this code. I'm learn MEL but have not come across this syntax as yet.
This is taken from the avalanche.mb fluid file's expression that came with Maya.
$i & $zres are both integer variables.
float $v = $vscale * (float)$i/(float)($zres);
Set float variable $v to the value of $vscale multiplied by..............??????
Why is "float" in parentheses? What does this mean?
Some form of automatic variable type conversion?
|10 October 2005||#2|
zombie slaying rugby plyrportfolio
Sr Creature TD
Cardinal Pier, United Kingdom
Join Date: May 2002
from someone else :
The (float) are casting an otherwise-non-float value into a float. In the instance above, if both of the variables $i, and $zres are integers, then the result of $i/$zres would be an integer, even if the true result would be a float. By casting at leaast one of the arguments, it is forcing the compiler to do this math in full floating point mode, rather than in integer mode.
Good . . . Bad . . . I'm the guy with the gun.
<.|.. My comments are not those of my employer(s)
|10 October 2005||#3|
Art Tools Programmer
San Francisco, USA
... The reason why casting to a (float) would be useful is that if you divide by an integer, you can't get fractional values - 0.5, 0.75, etc. In integer math, 1/2 = 3/4 = 99/100 = 0, which can be really annoying. In this case, $v would have been probably always be 0 or $vscale - no gradiation between the two - if the writer hadn't cast the expression to floating point math.
|Thread Closed share thread|