Bizarre floating-point behavior with vs. without extra variables, why?

后端 未结 4 388
终归单人心
终归单人心 2021-01-18 01:27

When I run the following code in VC++ 2013 (32-bit, no optimizations):

#include 
#include 
#include 

double mulpow         


        
4条回答
  •  时光说笑
    2021-01-18 02:10

    You have casted y1 as a double before casting it again to a long. the value of x isn't the "floor" value but a rounded value for floor.

    Same logic would apply with casting integers and floats. float x = (float)((int) 1.5) will give a different value to float x = 1.5

提交回复
热议问题