更好的精度来解决几何级数 [英] Better precision to solve a geometric progression

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

问题描述

a1 是第一项, r 是每个项乘以以得到下一项的常数term和 n 是术语的数量,几何级数是: ai = a1 * r **(i-1) pn n 的乘积和 sn n 的总和。



我有计算公式,但Fortran 95(Plato2)不承认我需要的精度。 (例如:我无法得到-1.234E + 00567890结果)。



我怎样才能充分地使用这个巨大的数字来处理双精度?

解决方案

如此高的数字(您的示例-1.234E + 00567890)对于Fortran标准提供的任何固有数值类型。它们也大于物理和工程应用中使用的数量。例如,我的gfortran支持这些类型:

  huge(1.0_real32)3.40282347E + 38 
huge(1.0_real64 )1.7976931348623157E + 308
huge(1.0_real128)1.18973149535723176508575932662800702E + 4932

至于我知道Fortran编译器没有更大的固有浮点类型可用。



出于专门目的,与您的一样,需要专门的库。本网站不适用于软件推荐,所以我不会推荐任何特定的软件。在 http://crd-legacy.lbl查看其中一些列表。 .gov /〜dhbailey / mpdist / ,当然还有更多(GNU科学图书馆将会有我确信的东西)。


Letting a1 be the first term, r be the constant that each term is multiplied by to get the next term and n be the number of terms, the geometric progression is: ai = a1*r**(i-1), pn the product of the n terms and sn the sum of the n terms.

I have the formulas to calculate this, but Fortran 95 (Plato2) doesn't admit the precision I need. (For example: I can't get -1.234E+00567890 as result).

How can I "amply" the double precision to work with this "huge" numbers?

解决方案

Such high numbers (your example -1.234E+00567890) are too large for any intrinsic numerical type supplied by Fortran standard. They are also larger than numbers used in physical and engineering applications. For example, my gfortran supports these types:

huge(1.0_real32)    3.40282347E+38
huge(1.0_real64)    1.7976931348623157E+308
huge(1.0_real128)   1.18973149535723176508575932662800702E+4932

As far as I know there is no Fortran compiler available with much larger intrinsic floating point types.

For specialized purposes, as yours, specialized libraries are needed. This site is not for software recommendations so I will not recommend any particular one. Have a look at a list of some of them at http://crd-legacy.lbl.gov/~dhbailey/mpdist/ and of course there are more around (the GNU Scientific Library will have something I am sure).

这篇关于更好的精度来解决几何级数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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