sin, cos, tan and rounding error

前端 未结 9 620
执念已碎
执念已碎 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:36

    An IEEE double stores 52 bits of mantissa, with the "implicit leading one" forming a 53 bit number. An error in the bottom bit of a result therefore makes up about 1/2^53 of the scale of the numbers. Your output is of the same order as 1.0, so that comes out to just about exactly one part in 10^16 (because 53*log(2)/log(10) == 15.9).

    So yes. This is about the limit of the precision you can expect. I'm not sure what the ULP technique you're using is, but I suspect you're applying it wrong.

提交回复
热议问题