Multiplication of three numbers in c give a wrong results? -


I can not give credit to whatever happened in my program

  double Den = 180 * 3600 * 1000;  

This value was found in debugging -2109934592.0000000

Any help please ???

You can try this simple code

  # include & lt; Stdio.h & gt; # Include & lt; Math.h> Int main (int argc, char * argv) {double divisor = 10000 * 180 * 3600; Printf ("% f \ n", divisor); Return 0; }  

With full code in question we can now see that this integer is overflow

  10000 * 180 * 3600 = 6,480,000,000  

This is greater than 2,147,483,648 which is the maximum value of 32-bit signed int. The results of multiplication are overflow to -2,0 9, 34, 592 and then it is repeated.

Repeat one of the numbers to get the correct number before multiplying:

  10000.0 * 180 * 3600  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -