Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Why do I get exception

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

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
";
  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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...