MSVC brace initialization with doubles appears to violate the standard?

前端 未结 2 1625
生来不讨喜
生来不讨喜 2021-01-17 17:37

Check out this simple program:

int main() {
    float f2 = 7.2; // OK, with warning
    float f3 = 7.199999809265137; // OK, no warning
    float f4{ 7.2 };          


        
2条回答
  •  深忆病人
    2021-01-17 18:29

    It looks like a bug, indeed. For a workaround, the following appears to silence both errors and warnings in MSVC 2015.

    #pragma float_control(precise, off, push)
    
    float f2 = 7.2; // OK, with warning
    //...
    
    #pragma float_control(precise, pop)
    

    The same works globally if using the /fp:fast compiler switch, though that one is incompatible with /Za which disables MS language extensions.

提交回复
热议问题