• Welcome to Dark Bit Factory & Gravity.
 

Float Mod Function

Started by Clyde, August 28, 2009

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Clyde

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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

#1
What exactly do you expect modulo 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;
}
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: