Mod operator in ios

nuteron picture nuteron · Apr 27, 2012 · Viewed 25.9k times · Source

have been searching for a mod operator in ios, just like the % in c, but no luck in finding it. Tried the answer in this link but it gives the same error. I have a float variable 'rotationAngle' whose angle keeps incrementing or decrementing based on the users finger movement. Some thing like this:

if (startPoint.x < pt.x) {
    if (pt.y<936/2) 
        rotationAngle += pt.x - startPoint.x;
    else
        rotationAngle += startPoint.x - pt.x;   
    }
    rotationAngle = (rotationAngle % 360);
}

I just need to make sure that the rotationAngle doesnot cross the +/- 360 limit. Any help any body. Thanks

Answer

Hailei picture Hailei · Apr 27, 2012

You can use fmod (for double) and fmodf (for float) of math.h:

#import <math.h>

rotationAngle = fmodf(rotationAngle, 360.0f);