Author Topic: Float Mod Function  (Read 4911 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Float Mod Function
« 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Float Mod Function
« Reply #1 on: August 28, 2009 »
What exactly do you expect modulo 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;
}
« Last Edit: August 28, 2009 by hellfire »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Float Mod Function
« Reply #2 on: August 29, 2009 »
Cheers hellfire :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won: