Sqrt精度?! [英] Sqrt precision ?!

查看:234
本文介绍了Sqrt精度?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


如何使用20位精度制作SQRT(2)(在浮点之后)?

Hello!

How I can make SQRT(2) with 20 digits precision (after float point)?

推荐答案

Marcin写道:
你好!

如何使SQRT(2)具有20位精度(浮点后)?
Hello!

How I can make SQRT(2) with 20 digits precision (after float point)?




您可能意味着sqrt(2.0)或sqrtl(2.0L);如果DBL_DIG或LDBL_DIG是
小于21(1. [20Digits使得21位数]),你可以看看

用于大型浮点实现,自己写一个或者

将值存储在字符串中。

#include< math.h>

#include< float.h>

#include< stdio.h>


int main(无效)

{

long double r ;


r = sqrtl(2.0L);

printf("精度:%d位数;%。* Lg \ n,LDBL_DIG,LDBL_DIG ,r);


返回0;

}


我不确定C89标准库是否提供sqrtl ()

(在这种情况下,你必须选择双r,sqrt(2.0),%。* g和

DBL_DIG)。


干杯

Michael

-

电子邮件:我的是一个gmx点地址。



You probably mean sqrt(2.0) or sqrtl(2.0L); if DBL_DIG or LDBL_DIG is
smaller than 21 (1.[20Digits] makes 21 digits), you can either look
for a large floating point implementation, write one yourself or
store the value in a string.
#include <math.h>
#include <float.h>
#include <stdio.h>

int main (void)
{
long double r;

r = sqrtl(2.0L);
printf("Precision: %d digits; %.*Lg\n",LDBL_DIG,LDBL_DIG,r);

return 0;
}

I am not sure whether C89 standard libraries provide sqrtl()
(in this case, you would have to go for double r, sqrt(2.0), %.*g and
DBL_DIG).

Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.


Marcin写道:
Marcin wrote:
你好!

如何制作SQRT(2) 20数字精度(在浮点之后)?
Hello!

How I can make SQRT(2) with 20 digits precision (after float point)?




牛顿算法具有双精度浮点数,如果内置的一个

不足。


gtoomey



Newtons algorithm with double precision floating point, if the inbuilt one
is insufficient.

gtoomey


Gregory Toomey写道:
Gregory Toomey wrote:
Marcin写道:
Marcin wrote:
您好!

如何使SQRT(2)具有20位精度(浮点后)?
Hello!

How I can make SQRT(2) with 20 digits precision (after float point)?



具有双精度浮点的牛顿算法,如果内置的
不够。


Newtons algorithm with double precision floating point, if the inbuilt one
is insufficient.




问题是OP需要21(十进制)数字精度

意味着我们需要70位二进制数字精确度。

这反过来意味着你平均系统的双倍是不够的。

如果你运气好,那么长期双倍就可以了。否则,你将不得不使用非标准的东西或制作你自己的浮点数据类型。

干杯

Michael

-

电子邮件:我的是一个gmx点地址。



The problem is that the OP wants 21 (decimal) digits precision which
implies that we need 70 binary digits precision.
This in turn means that you average system''s double will not suffice.
If you are lucky, long double will do. Otherwise, you will have to
use either non-standard stuff or make your own floating point data type.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.


这篇关于Sqrt精度?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆