开发者

Get precision of about 20-30 digits in C

开发者 https://www.devze.com 2023-01-24 02:17 出处:网络
So, I\'m trying to calculate a certain value to a rather large precision.The expression in C is: long double t = 2.0L+.2L*(sp)+s.missRate*50L;

So, I'm trying to calculate a certain value to a rather large precision. The expression in C is:

long double t = 2.0L+.2L*(sp)+s.missRate*50L;

my result is: 11.575345

But the 'real' result is: 11.575345222开发者_JAVA百科971968

I'm using long doubles, which are the largest primitive type AFAIK. I shouldn't have to use any precision libraries to do this. So, what C type has this kind of precision?


The result is probably precise enough, but you are printing it rounded to 6 digits after the decimal point. Increase your printing precision, like this:

long double var;
printf("%.20Lf\n", var); //20 digits after the radix


The double type doesn't support more than about 16 decimal digits (http://en.wikipedia.org/wiki/IEEE_754). So don't count on the additonal 4-14 you mention in the title.

To get more I suggest you turn to gmplib.org

0

精彩评论

暂无评论...
验证码 换一张
取 消