如何在objective-c / cocoa touch中进行模运算? [英] How to make a modulo operation in objective-c / cocoa touch?
本文介绍了如何在objective-c / cocoa touch中进行模运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个CGFloat值,想要计算模数结果。换句话说:我想知道如果将valueA尽可能多地放入valueB,剩下的是什么。
I have two CGFloat values, and want to calculate the modulo result. Or in other words: I want to know what's left if valueA is placed as much as possible into valueB.
所以我只是尝试了:
CGFloat moduloResult = valueB % valueA;
编译器抱怨%并告诉我:二进制%的操作数无效。有什么想法吗?
the compiler complains about the % and tells me: "invalid operands to binary %". Any idea?
推荐答案
%适用于 int
或长
,而不是 float
或 double
。
% is for int
or long
, not float
or double
.
你可以从使用
代替。 fmod()
或 fmodf()
< math.h>
You can use fmod()
or fmodf()
from <math.h>
instead.
更好是 < tgmath.h>
由CGFloat的发明者建议。
这篇关于如何在objective-c / cocoa touch中进行模运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文