Different math rounding behaviour between Linux, Mac OS X and Windows

前端 未结 4 1280
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 07:25

HI,

I developed some mixed C/C++ code, with some intensive numerical calculations. When compiled in Linux and Mac OS X I get very similar results after the simulatio

4条回答
  •  旧巷少年郎
    2020-12-19 08:06

    I can't speak to the implementation in Windows, but Intel chips contain 80-bit floating point registers, and can give greater precision than that specified in the IEEE-754 floating point standard. You can try calling this routine in the main() of your application (on Intel chip platforms):

    inline void fpu_round_to_IEEE_double()
    {
       unsigned short cw = 0;
       _FPU_GETCW(cw);        // Get the FPU control word
       cw &= ~_FPU_EXTENDED;  // mask out '80-bit' register precision
       cw |= _FPU_DOUBLE;     // Mask in '64-bit' register precision
       _FPU_SETCW(cw);        // Set the FPU control word
    }
    

    I think this is distinct from the rounding modes discussed by @Alok.

提交回复
热议问题