sin, cos, tan and rounding error

前端 未结 9 655
执念已碎
执念已碎 2020-12-06 14:09

I\'m doing some trigonometry calculations in C/C++ and am running into problems with rounding errors. For example, on my Linux system:

#include 

        
9条回答
  •  我在风中等你
    2020-12-06 14:29

    I get the exact same result on my system - I'd say it is close enough

    I would solve the problem by changing the format string to "%f\n" :)

    However, this gives you a "better" result, or at least on my system it does give -3.661369e-245

    #include 
    #include 
    
    int main(int argc, char *argv[]) {
        printf("%e\n", (long double)sin(M_PI));
        return 0;
    }
    

提交回复
热议问题