浮点精度问题 [英] floating point precision problem

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

问题描述



i需要获得高位数浮点数。


说,我需要pi = 22 / 7.0 = 3.142857 ....(upto 80位数)


有可能吗?


gcc / g ++编译器可以提供这种类型的高精度吗?


plz给出一个小代码我怎样才能实现这个目标?哪种方式,我要

写代码?

问题2:AT最多可以用gcc / g ++和VC ++给出多少精度?

我可以写



双倍双倍双倍x = 22 / 7.0? ...这样它可以保持

非常精确的结果。


i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(upto 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.

推荐答案



" ;语法" < SA ***** @ yahoo.com.hk>在留言中写道

news:5c ************************** @ posting.google.c om ...

"syntax" <sa*****@yahoo.com.hk> wrote in message
news:5c**************************@posting.google.c om...

我需要得到高位数浮点数。

说,我需要pi = 22 / 7.0 = 3.142857 ....(高达80位数) )

有可能吗?

gcc / g ++编译器可以提供这种类型的高精度吗?

PLZ给出一个小代码如何可以我实现了吗?哪种方式,我必须编写代码??

问题2:AT最多可以用gcc / g ++和VC ++给出多少精度?

我可以写吗<双/双双x = 22 / 7.0? ...这样它可以保持高度精确的结果。

i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(upto 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.




使用lcc-win32。

例如:

#include< qfloat.h>

int main(无效)

{

qfloat p = 2;

printf("%1.80qf \ n",sqrt(p));

返回0;

}

将产生:

1.414213562373095048801688724209698078569671875376 94807317667973799073

247846210704

Qfloats的精度为350位,大约100位。

http://www.cs.virginia.edu/~lcc -win32


语法写道:


我需要得到高位数浮点数。

说,我需要pi = 22 / 7.0 = 3.142857 ......(最多80位数)

是否有可能?

gcc / g ++编译器可以给出这种类型的高精度吗?

PLZ给一个小C ODE我怎样才能实现?哪种方式,我要编写代码?

问题2:AT最多可以用gcc / g ++和VC ++给出多少精度?

我可以写吗<双/双双x = 22 / 7.0? ...这样它可以保持高度精确的结果。


i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(upto 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??

Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.




如前所述,在这一组中,有几个高精度库在

标准C已经编写并可供下载。


Google搜索C中的高精度算术收益

http:// crd。 lbl.gov/~dhbailey/mpdist/mpdist.html


约126,000次点击。


-

Julian V. Noble

物理荣誉教授
jv*@lessspamformother.virginia.edu

^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/


上帝我不愿意做任何事情,从而带走我们的免费财富和b $ b以及那些合法属于我们自己的荣耀。

- N. Machiavelli, ;王子。



As noted previously in this group, several high-precision libraries in
standard C have been written and are available for download.

A Google search of "high precision arithmetic in C" yields

http://crd.lbl.gov/~dhbailey/mpdist/mpdist.html

among about 126,000 hits.

--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"God is not willing to do everything, and thereby take away our free wiil
and that share of glory that rightfully belongs to ourselves."
-- N. Machiavelli, "The Prince".


" syntax" < SA ***** @ yahoo.com.hk>在消息中写道
"syntax" <sa*****@yahoo.com.hk> wrote in message

我需要获得高位数浮点数。

i need to get high presion float numbers.



通常C编译器会将自己限制为
中支持的类型
硬件,通常是32,64,有时是80位。

如果硬件具有高精度双精度,例如128位,编译器是

可能会提供诸如long long double之类的扩展。然而,这种

硬件并不常用。


双精度几乎适用于所有用途。如果你需要更高的精度

,你需要在软件中模拟浮点数(图书馆可用于b
)。

如果你想要为了计算PI到精确度,有更好的算法

可用,不依赖于任意精度浮点运算。


Generally C compilers will restrict themselves to types supported in
hardware, which are usually 32, 64 and sometimes 80 bits.
If the hardware has high-precison doubles, such as 128 bits, the compiler is
likely to provide an extension such as long long double. However such
hardware is not in common use.

A double is enough precision for almost all uses. If you need more precision
you need to emulate floating point in software (libraries are available to
do just that).
If you want to calculate PI to great precison, there are better algorithms
available that don''t rely on arbitrary-precison floating point arithmetic.


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

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