SwipeView
SwipeView copied to clipboard
Is there a reason for using roundf instead of floorf when calculating currentPage?
@nicklockwood Any reason why you chose to use roundf instead of floorfwhen calculating the currentPage?
- (NSInteger)currentPage {
if (_itemsPerPage > 1 && _truncateFinalPage && !_wrapEnabled &&
_currentItemIndex > (_numberOfItems / _itemsPerPage - 1) * _itemsPerPage)
{
return self.numberOfPages - 1;
}
return roundf((float)_currentItemIndex / (float)_itemsPerPage);
}
After a bit of testing I noticed that roundf is not reliable enough when attempting to calculate the currentPage. The reason being that roundf rounds up any float with a decimal point of 0.5 or above. Rounding down is a better option though. This is where floorf is ideal.

The page numbers in pink highlight the errors when using roundf.
BTW great job on this component!