Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: Clyde on August 28, 2009
-
Has anyone made an mod or % ( modulous ) function that returns a float or int like in Blitz and FREEBasic and that copes with negatives too, I dont think fmod is the answer. Or could you help me in creating one please?
example:
If ( float_variable mod 1.0>=0.5 ) then
{
....;
....;
}
end if
another example:
if ( a mod 360 ) then .....
Cheers,
Clyde.
-
What exactly do you expect modulo (http://en.wikipedia.org/wiki/Modulo_operation) to return on negative input?
You're probably looking for something like this:
float modulo(float v, float max)
{
float p= fmod(v, max);
if (p<0.0)
p+=max;
return p;
}
-
Cheers hellfire :)
-
http://www.cplusplus.com/reference/clibrary/cmath/modf/