iOS中的Mod运算子 [英] Mod operator in ios

查看:90
本文介绍了iOS中的Mod运算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在ios中搜索mod运算符,就像c中的%一样,但是找不到运气.在此链接中尝试了答案,但给出了相同的错误. 我有一个浮点变量'rotationAngle',其角度根据用户的手指移动而不断增加或减少. 像这样的东西:

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);
}

我只需要确保rotationAngle不超过+/- 360的限制. 任何帮助任何身体. 谢谢

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

推荐答案

您可以使用math.h的fmod(对于double)和fmodf(对于float):

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

#import <math.h>

rotationAngle = fmodf(rotationAngle, 360.0f);

这篇关于iOS中的Mod运算子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆