Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on August 28, 2009

Title: Float Mod Function
Post 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.
Title: Re: Float Mod Function
Post by: hellfire on August 28, 2009
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:
Code: [Select]
float modulo(float v, float max)
{
   float p= fmod(v, max);
   if (p<0.0)
      p+=max;
   return p;
}
Title: Re: Float Mod Function
Post by: Clyde on August 29, 2009
Cheers hellfire :)
Title: Re: Float Mod Function
Post by: ferris on September 07, 2009
http://www.cplusplus.com/reference/clibrary/cmath/modf/