DEXP或EXP用于fortran中的指数函数? [英] DEXP or EXP for exponential function in fortran?

查看:1373
本文介绍了DEXP或EXP用于fortran中的指数函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个很简短的问题:
$ b $ 1我刚才读到 DEXP()陈旧形式的 EXP()。这是否意味着它不应该被使用了?我一直认为 DEXP()是等于 EXP()的双精度。



<2> - 指数函数的范围是多少?

感谢您的帮助!



Best,
Remek

解决方案

问题1:



如前所述,最好使用EXP()等通用函数,而不要使用过时的类型特定的等价物,比如DEXP()。

在FORTRAN(FORTRAN 77之前)的旧版(旧版本)中,每种数据类型都需要一个不同的函数。因此,如果您希望指数函数需要:单精度数字的EXP(),双精度数字的DEXP()或复数的CEXP()。 FORTAN现在有函数重载,所以一个函数可以用于任何标准类型。



问题2。



原则上,指数的可能范围可以取决于处理器和编译器。但是,如前所述,大多数现代处理器和编译器都将使用IEEE标准。

如果需要,可以在声明变量时指定变量的所需范围。要使用的函数是 SELECTED_REAL_KIND([P,R])

例如,假设您要确保 x 是一个十进制精度至少为10位数的类型,十进制指数范围至少为100。

  INTEGER,PARAMETER :: mytype = SELECTED_REAL_KIND(10,100)
REAL(KIND = mytype):: x

更多信息: SELECTED_REAL_KIND 在实践中,如果你正在编写一个需要给定准确性的程序,并且这个程序可能运行在异常的或旧的系统上,那么定义你的程序是个好主意以这种方式类型。这里显示了一些常见的定义:实际精度


I have two very short questions:

1 - I just read that DEXP() is the archaic form of EXP(). Does it mean that it should not be used anymore? I always thought that DEXP() was the double precision equivalent to EXP().

2 - What is the range of the exponential function? Is it compiler dependent?

Thanks in advance for your help!

Best, Remek

解决方案

Question number 1:

As mentioned before, it is always better to use the generic functions, such as EXP(), in preference to the outdated type specific equivalents, such as DEXP().

In the old (really old) versions of FORTRAN (before FORTRAN 77), a different function was required for each data type. So if you wanted the exponential function would need: EXP() for single precision numbers, DEXP() for double precision numbers, or CEXP() for complex numbers. FORTAN now has function overloading, so a single function will work for any standard type.

Question number 2.

In principle the possible range of the exponent can be processor and compiler dependent. However, as mentioned before, most modern processors and compilers will use the IEEE standard.

If needed, it is possible to specify the required range of a variable when declaring it. The function to use is SELECTED_REAL_KIND([P,R]).

For example, suppose you to make sure that x is of a type with decimal precision of at least 10 digits and a decimal exponent range of at least 100.

INTEGER, PARAMETER :: mytype = SELECTED_REAL_KIND(10, 100)
REAL(KIND=mytype) :: x

For more information: SELECTED_REAL_KIND

In practice, if you are writing a program that requires a given accuracy, and which may be run on exotic or old systems, it is a very good idea to define your types in this way. Some common definitions are shown here: Real Precision

这篇关于DEXP或EXP用于fortran中的指数函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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