How to make a modulo operation in objective-c / cocoa touch?

后端 未结 2 1077
慢半拍i
慢半拍i 2020-11-28 06:10

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.

相关标签:
2条回答
  • 2020-11-28 06:28

    If I remember correctly modulo requires 2 ints as its input so you'd need something like:

    CGFloat moduloResult = (float)((int)valueB % (int)valueA);
    

    Assuming that valueB and valueA are both floats

    0 讨论(0)
  • 2020-11-28 06:44

    % is for int or long, not float or double.

    You can use fmod() or fmodf() from <math.h> instead.

    Better is <tgmath.h> as suggested by the inventor of CGFloat.

    0 讨论(0)
提交回复
热议问题