Usage of fmod?

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
  11 November 2006
Usage of fmod?

The docs give little info on this MEL command, anyone have the time to explain what exactly this does and the proper way to use it OR use the data it returns?

  11 November 2006
This is in PHP, and i'm pretty sure it's the same.

fmod -- Returns the floating point remainder (modulo) of the division of the arguments


float fmod ( float x, float y )
Returns the floating point remainder of dividing the dividend (x) by the divisor (y). The reminder (r) is defined as: x = i * y + r, for some integer i. If y is non-zero, r has the same sign as x and a magnitude less than the magnitude of y.

PHP Code:
 $x 5.7;
$y 1.3;
$r fmod($x$y);
// $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7 

Fredrik Brännbacka | Technical Director

Last edited by smaragden : 11 November 2006 at 09:31 PM.
  11 November 2006
Fmod is used for finding the remainder in division problems. 5 / 3 could be thought of as 1.6666666666 or it could be thought of as 1 with a remainder of 2. Fmod is used for finding that remainder. So `fmod 5 3` would return 2.

About the only time I use fmod is to figure out if a number is even or not. If `fmod $someNumber 2` returns a zero then I know that number is even. If it returns anything else I know the number is odd. I'm sure it has other uses though.
  11 November 2006
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 07:09 AM.

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