# Interpret This Line of code

 10 October 2005 Fess tapping his potential   portfolio Jason Mohan Animation/VFX/Lighting Digital Domain 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. 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? Confused Fess share quote
 10 October 2005 twidup zombie slaying rugby plyr   portfolio Todd Widup Sr Creature TD movielocation Cardinal Pier, United Kingdom 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) share quote
 10 October 2005 EigenPuff Artist's Tool   Mike Gonzales Art Tools Programmer Crystal Dynamics 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. share quote
 10 October 2005 Fess tapping his potential   portfolio Jason Mohan Animation/VFX/Lighting Digital Domain twidup, EigenPuff... Thanks for the explaination. Fess share quote
 10 October 2005 CGTalk Moderation Expert 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. share quote

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.