Every now and then I catch a mistake in my code where I've been caught out by integer division. For example I was transcribing straight from an equation I'd worked out on paper, and wrote:
psi[l] * sqrt((l-m) * (l-m-1) / ((2*l+1) * (2*l-1)))
This will not do what I intended. In the extreme case, for large l ~= m the integer calculation for the sqrt ends up as zero. I should of course have forced the values to floating point to ensure it did what I wanted.
This is of course a very basic mistake, but one I admit to making every now and then - and it can prove hard to track down.
Is there a warning that I can enable in Xcode/gcc that would pick up on this? A warn-on-integer-division warning would generate some false positives, but I'd be happy to live with that if it caught the genuine errors. An smart warning that spotted when an integer result generated by division was cast to floating point would be even better, but I'd be impressed if that existed (it's a pretty complicated condition!).
Anyway, if anyone can suggest any relevant warnings I could enable, that would be great.
Cheers
Jonny