Minor bug fixed

Hello,

I'm not a great experienced developper but I make some modifications on your code:
- Use long when using NSInteger (correct warning in 64 bits environments)
- Prevent divide by 0 (reported by Analyse)

Best regards
(Please apologies my bad english)
seb