Why does Int32.MaxValue * Int32.MaxValue == 1 ???

Posted by Greg Balajewicz on Stack Overflow See other posts from Stack Overflow or by Greg Balajewicz
Published on 2010-06-08T20:32:36Z Indexed on 2010/06/08 20:42 UTC
Read the original article Hit count: 259

Filed under:

OK, I know, Int32.MaxValue * Int32.MaxValue will yield a number larger than Int32 BUT, shouldn't this statement raise some kind of an exception?

I ran across this when doing something like IF (X * Y > Z) where all are Int32. in X and Y are sufficiently large enough, you get a bogus value from X*Y

Why is this so and how to get around this? besides casting everything to int64

© Stack Overflow or respective owner

Related posts about c#