32位数C ++的异常 [英] Exception for 32 bit number C++

查看:275
本文介绍了32位数C ++的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会出现异常

在TestingCOA.exe中0x00000001处的未处理异常:0xC0000005:访问违例(参数:0x00000008) code>

Unhandled exception at 0x00000001 in TestingCOA.exe: 0xC0000005: Access violation (parameters: 0x00000008).

当我尝试使用4294967295或更高的数字。在我的机器 sizeof double是 8bytes 应该能够处理和使用 2 ^ 64 -1 数字,但是它为32位数生成异常,为什么?

when I try to work with a 4294967295 or higher number. On my machine sizeof double is 8bytes which should be able to handle and work with2^64 -1 number but it is generating exception for a 32 bit number, why is that?

int main()
{
  double n,remainderA;
  int AfterDecimal1[64],RemExponent1;

  cout<< "Enter number\n";
  cin>> n;

  remainderA=a-(int)a;

   HandleFractionNumber(remainderA,AfterDecimal1,RemExponent1);
}


int HandleFractionNumber(double remainder,int (&Goku)[64],int &RemExponent)
{
int x=0;
for(int i=0;;i++)
{
    remainder*=2;
    if(remainder>1)
    {
        remainder-=1;
        Goku[x]=1;
        x++;
    }
    else
        if(remainder<1)
        {
            Goku[x]=0;
            x++;
        }
        if(remainder==1)
        {
            Goku[x]=1;
            break;
        }
        RemExponent=x;
}


推荐答案

Double不起作用。它是一种具有字段和特定格式的结构(称为 IEEE双精度)。不是所有的64位都可用尾数。

Double does not work like that. It is a structure with fields and certain format (known as IEEE double precision). Not all 64 bits are available for the mantissa.

然而,它应该吃了你提到的数字(4294967295)在输入。你确定这是你放吗?您引用的程序 - 是否有?

Yet, it should have eaten the number you mentioned (4294967295) at input. Are you sure this is what you put? Is the program you quoted - all there is?

这篇关于32位数C ++的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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