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 CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2005   #1
Arrow Interpret This Line of code

Hello,

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?


Confused
Fess
 
Old 10 October 2005   #2
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.
-Ash

<.|.. My comments are not those of my employer(s)
 
Old 10 October 2005   #3
... 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.
 
Old 10 October 2005   #4
twidup, EigenPuff...

Thanks for the explaination.

Fess
 
Old 10 October 2005   #5
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.
 
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 09:07 AM.


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