Multiplication of three numbers in c give a wrong results?

前端 未结 2 1431
小蘑菇
小蘑菇 2020-12-22 14:02

I can\'t belive what\'s happen in my program

double den = 180*3600*10000 ;

in debugging a got this value -2109934592.0000000

any he

2条回答
  •  伪装坚强ぢ
    2020-12-22 15:06

    test.c: In function ‘main’:
    test.c:6:37: warning: integer overflow in expression [-Woverflow]
          double denominator =  10000*180*3600 ;
                                         ^
    

    Is the error when I compile. Your overflowing ints and casting to a double.

       double denominator =  10000.0*180.0*3600.0 ;
    

    Fixes the issue

提交回复
热议问题