iOS中的Mod运算子

编程入门 行业动态 更新时间:2024-10-22 07:38:19
本文介绍了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运算子

本文发布于:2023-10-14 22:21:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   Mod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!