P3与P4的整数溢出处理 [英] Integer overflow handling on P3 vs. P4

查看:62
本文介绍了P3与P4的整数溢出处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例代码:


static void Main(string [] args)

{

double inf = 0.1 / 0.0 ;

int test2 =(int)(inf * 0.0F);

Console.WriteLine(test2.ToString());

}


在P3上,结果为0,在P4上给出-2147483648,这是

int.MinValue。


任何人都知道为什么会这样吗?是.Net在P4上错误地编译了吗,

还是错误的P4?


当然如果我用溢出检查编译它会抛出例外,

并且在分割之前检查值是一个好习惯。 (我

从我下载的图形组件中取出了这个例子,它在P4上失败了

。)


问候,

Mikael Svenson

解决方案

肯定要么两种结果都可以接受,因为结果不正确因为

答案是未定义的。


为什么处理器如何划分为零,因为它是什么东西?b
$ b应该永远不会发生?


以后! = o)

Dan。


" Mikael Svenson" < MI ***** @ powertech.no>写在消息

新闻:3F *************** @ powertech.no ...

示例代码:


static void Main(string [] args)

{

double inf = 0.1 / 0.0;

int test2 =(int)(inf * 0.0F);

Console.WriteLine(test2.ToString());

}


在P3上,这给出结果0,在P4上它给出-2147483648这是

int.MinValue。


任何人都知道为什么会这样?是.Net在P4上错误地编译了吗,

还是错误的P4?


当然如果我用溢出检查编译它会抛出例外,

并且在分割之前检查值是一个好习惯。 (我

从我下载的图形组件中取出了这个例子,它在P4上失败了

。)


问候,

Mikael Svenson


我不是很困扰:)但它仍然很有趣。并且在数学上

0应该是正确的答案。我们还看到了一个奇怪的舍入错误

在工作中,其中2.24变为2.2400000021。这也是在P4上。

但是还没有在P3上试过它。所以可能有P4错误;)


-m


Daniel Bass写道:


当然任何一个结果都是可以接受的,因为结果是不正确的,因为
答案是不确定的。

为什么要对处理器如何划分为零而烦恼呢?永远不会发生?

以后! = o)
Dan。

Mikael Svenson < MI ***** @ powertech.no>在消息中写道
新闻:3F *************** @ powertech.no ...
示例代码:

static void Main (string [] args)
{/ /> double inf = 0.1 / 0.0;
int test2 =(int)(inf * 0.0F);
Console.WriteLine(test2.ToString ());
}

在P3上,它给出结果0,在P4上给出-2147483648,这是
int.MinValue。

任何人都知道为什么会这样?是.Net在P4上错误编译,
还是错误的P4?

当然如果我使用溢出检查编译它会引发异常,
和在分割之前检查值是一种好习惯。 (我已经从我下载的图表组件中找到了这个例子,它在P4上失败了。)

问候,
Mikael Svenson


我不是很困扰:)但它仍然很有趣。并且在数学上

0应该是正确的答案。我们还看到了一个奇怪的舍入错误

在工作中,其中2.24变为2.2400000021。这也是在P4上。

但是还没有在P3上试过它。所以可能有P4错误;)


-m


Daniel Bass写道:


当然任何一个结果都是可以接受的,因为结果是不正确的,因为
答案是不确定的。

为什么要对处理器如何划分为零而烦恼呢?永远不会发生?

以后! = o)
Dan。

Mikael Svenson < MI ***** @ powertech.no>在消息中写道
新闻:3F *************** @ powertech.no ...
示例代码:

static void Main (string [] args)
{/ /> double inf = 0.1 / 0.0;
int test2 =(int)(inf * 0.0F);
Console.WriteLine(test2.ToString ());
}

在P3上,它给出结果0,在P4上给出-2147483648,这是
int.MinValue。

任何人都知道为什么会这样?是.Net在P4上错误编译,
还是错误的P4?

当然如果我使用溢出检查编译它会引发异常,
和在分割之前检查值是一种好习惯。 (我已经从我下载的图表组件中找到了这个例子,它在P4上失败了。)

问候,
Mikael Svenson


Sample code:

static void Main(string[] args)
{
double inf = 0.1 / 0.0;
int test2 = (int)(inf * 0.0F);
Console.WriteLine( test2.ToString() );
}

On a P3 this gives the result "0", on a P4 it gives -2147483648 which is
int.MinValue.

Anyone know why this happens? Is it .Net which compiled wrongly on a P4,
or is it the P4 which is erroneus?

Of course if I compile with overflow checking it throws an exception,
and it''s good practise to check the value before you divide with it. (I
made this example out from a graph component I downloaded which failed
on a P4.)

Regards,
Mikael Svenson

解决方案

surely either result is acceptable since either result is incorrect because
the answer is undefined.

why be too bothered about how processors divide zero when it''s something
that should never occur?

LATER! =o)
Dan.

"Mikael Svenson" <mi*****@powertech.no> wrote in message
news:3F***************@powertech.no...
Sample code:

static void Main(string[] args)
{
double inf = 0.1 / 0.0;
int test2 = (int)(inf * 0.0F);
Console.WriteLine( test2.ToString() );
}

On a P3 this gives the result "0", on a P4 it gives -2147483648 which is
int.MinValue.

Anyone know why this happens? Is it .Net which compiled wrongly on a P4,
or is it the P4 which is erroneus?

Of course if I compile with overflow checking it throws an exception,
and it''s good practise to check the value before you divide with it. (I
made this example out from a graph component I downloaded which failed
on a P4.)

Regards,
Mikael Svenson


I''m not that bothered :) but it is still interesting. And mathematically
0 should be the correct answer. We''ve also seen a strange rounding error
at work, where 2.24 becomes 2.2400000021. That''s on a P4 as well.
Haven''t tried it on a P3 yet. So could there possible be P4 bug ;)

-m

Daniel Bass wrote:


surely either result is acceptable since either result is incorrect because
the answer is undefined.

why be too bothered about how processors divide zero when it''s something
that should never occur?

LATER! =o)
Dan.

"Mikael Svenson" <mi*****@powertech.no> wrote in message
news:3F***************@powertech.no...
Sample code:

static void Main(string[] args)
{
double inf = 0.1 / 0.0;
int test2 = (int)(inf * 0.0F);
Console.WriteLine( test2.ToString() );
}

On a P3 this gives the result "0", on a P4 it gives -2147483648 which is
int.MinValue.

Anyone know why this happens? Is it .Net which compiled wrongly on a P4,
or is it the P4 which is erroneus?

Of course if I compile with overflow checking it throws an exception,
and it''s good practise to check the value before you divide with it. (I
made this example out from a graph component I downloaded which failed
on a P4.)

Regards,
Mikael Svenson



I''m not that bothered :) but it is still interesting. And mathematically
0 should be the correct answer. We''ve also seen a strange rounding error
at work, where 2.24 becomes 2.2400000021. That''s on a P4 as well.
Haven''t tried it on a P3 yet. So could there possible be P4 bug ;)

-m

Daniel Bass wrote:


surely either result is acceptable since either result is incorrect because
the answer is undefined.

why be too bothered about how processors divide zero when it''s something
that should never occur?

LATER! =o)
Dan.

"Mikael Svenson" <mi*****@powertech.no> wrote in message
news:3F***************@powertech.no...
Sample code:

static void Main(string[] args)
{
double inf = 0.1 / 0.0;
int test2 = (int)(inf * 0.0F);
Console.WriteLine( test2.ToString() );
}

On a P3 this gives the result "0", on a P4 it gives -2147483648 which is
int.MinValue.

Anyone know why this happens? Is it .Net which compiled wrongly on a P4,
or is it the P4 which is erroneus?

Of course if I compile with overflow checking it throws an exception,
and it''s good practise to check the value before you divide with it. (I
made this example out from a graph component I downloaded which failed
on a P4.)

Regards,
Mikael Svenson



这篇关于P3与P4的整数溢出处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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