nuteron nuteron - 4 months ago 48
Objective-C Question

Mod operator in ios

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;
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.


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

#import <math.h>

rotationAngle = fmodf(rotationAngle, 360.0f);