为什么Int32.MaxValue * Int32.MaxValue == 1? [英] Why does Int32.MaxValue * Int32.MaxValue == 1?

查看:134
本文介绍了为什么Int32.MaxValue * Int32.MaxValue == 1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,我知道,Int32.MaxValue * Int32.MaxValue将产生数大于的Int32,但不应该这句话提高某种异常的?

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?

我做这样的事情IF(X * Y> Z)其中,所有的Int32当跨越这个跑去。在X和Y是足够足够大,你从X * Y虚假值

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

为什么会这样,以及如何解决这个问题?除了铸造一切INT64

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

推荐答案

您已经于您的项目中禁用溢出检查。随着检查方式上会抛出异常。

You have disabled the overflow checks in your project. With checked mode On it will throw an exception.

这篇关于为什么Int32.MaxValue * Int32.MaxValue == 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆