Interpret This Line of code

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  10 October 2005
Arrow 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.

Quote: 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
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
... 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.
  10 October 2005
twidup, EigenPuff...

Thanks for the explaination.

  10 October 2005
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 10:13 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.