So, I have this thing where I got the following operation:
NSInteger articleIndex = self.featuredArticlesCounter % self.featuredArticles.count;
In this case, self.featuredArticlesCounter is -1 and self.featuredArticles.count is 10
So this is basically -1% 10, which should be 9, but the result is 5.
Google says it.
And if I do NSInteger articleIndex = -1 % 10; he gives me -1
I tried casting NSUInteger from count to NSInteger and it does not work. I tried to insert brackets everywhere, but that didn't work either.
Since then, I switched to using ((-1 % 10) + 10) % 10 .
But I'm still wondering what the deal is. Any ideas?
Edit
featuredArticlesCounter is a signed int
self.featuredArticles.count is an unsigned int
source share