Monday, 9 September 2013

Why this is undefined behavior?

Why this is undefined behavior?

I had a question and my answer was this function:
inline bool divisible15(unsigned int x)
{
//286331153 = (2^32 - 1) / 15
//4008636143 = (2^32) - 286331153
return x * 4008636143 <= 286331153;
}
It perfectly worked on my machine with VS2008 compiler, however here it
doesn't work at all.
Does anyone has an idea, why it is UB?

No comments:

Post a Comment