On Mon, May 17, 2010 at 04:49:41PM +0530, Manish kumar Singh wrote: > is using this statement a good idea? > if (fmod(k + 1, pow(2, n)) == 0)... > It worked.
All of the values involved are exactly representable as 'double', so it should work as long as fmod and pow are accurate to the limits of the precision of their datatypes. And of course a well-implemented math function will have that accuracy and I would be disappointed in one that didn't. However, I've been unable to find any statement in the relevant standards or in my library documentation that actually guarantees that accuracy. Can we rely on it? As for it being a 'good idea' -- I would prefer bit manipulations when working with powers of two. I can't offer a proper rationale for that, though. It's just what I'm used to, and I understand the rules better. If pressed, I would justify it by saying that it's faster :) But I've never actually measured the difference. -- Richard Braakman -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to google-c...@googlegroups.com. To unsubscribe from this group, send email to google-code+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.