PDA

View Full Version : Usage of fmod?


azshall
11-08-2006, 08:23 PM
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?

Seth

smaragden
11-08-2006, 08:29 PM
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

Description

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.

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

grantimus
11-08-2006, 08:35 PM
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.

CGTalk Moderation
11-08-2006, 08:35 PM
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.