So I've got 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 it's basically -1 % 10, which should be 9, but the result is 5 instead.
Google says it's 9.
And if I do NSInteger articleIndex = -1 % 10;
it gives me -1
I've tried casting the NSUInteger from count to NSInteger and that doesn't work. I've tried inserting brackets all over the place but that didn't work either.
I've since switched to using ((-1 % 10) + 10) % 10
.
But I'm still wondering what the deal is here. Any ideas?
Edit:
featuredArticlesCounter is a signed int
self.featuredArticles.count is an unsigned int