• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Integer division
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Integer division


  • Subject: Integer division
  • From: Jonny Taylor <email@hidden>
  • Date: Tue, 20 Nov 2007 11:20:18 +0000
  • Authenticated-sender:

Hi everyone,

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
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Integer division
      • From: David Rowland <email@hidden>
  • Prev by Date: Re: Xcode 3 incorrect 'Incompatible Service' in dist. builds?
  • Next by Date: IB 3.0 plugin & error "NSMapRemove(): attempt to remove notAKeyMarker" when saving NIB
  • Previous by thread: Re: Xcode 3 incorrect 'Incompatible Service' in dist. builds?
  • Next by thread: Re: Integer division
  • Index(es):
    • Date
    • Thread