Fortran 中指数函数的 DEXP 或 EXP?

发布于 2024-08-18 02:24:33 字数 195 浏览 2 评论 0原文

我有两个非常简短的问题:

1 - 我刚刚读到 DEXP()EXP()古老形式。这是否意味着不应再使用它?我一直认为 DEXP() 是相当于 EXP() 的双精度。

2 - 指数函数的范围是多少?它依赖于编译器吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怀里藏娇 2024-08-25 02:24:33

问题 1:

在现代 Fortran 中,最好使用通用函数(例如 EXP()),而不是过时的特定于类型的等效函数(例如 DEXP())。

在旧的(非常旧的)Fortran 版本(FORTRAN 77 之前)中,每种数据类型都需要不同的函数。因此,如果您想要指数函数,则需要:用于单精度数的 EXP()、用于双精度数的 DEXP() 或用于复数的 CEXP()。 Fortran 现在具有函数重载功能,因此单个函数适用于任何标准类型。

问题 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

实际上,如果您正在编写一个需要给定精度的程序,并且可能在异国情调或旧系统上运行,以这种方式定义类型是一个非常好的主意。这里显示了一些常见的定义:真实精度

Question number 1:

In modern Fortran 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. Fortran 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, 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

乖乖 2024-08-25 02:24:33

“exp”是一个通用函数,它返回与其参数相同的类型——实数或复数的精度。它应该优先于旧形式“dexp”使用,因为使用“exp”编译器将自动返回正确的类型。 Fortran 77 中添加了通用名称。

"exp" is a generic function, that returns the same type as its argument -- precision of real or complex. It should be used in preference to the older form "dexp" because with "exp" the compiler will automatically return the correct type. The generic names were added in Fortran 77.

春花秋月 2024-08-25 02:24:33

你问题第二部分的答案是指数函数的范围是所有正实数的集合。在 Fortran 术语中,这意味着所有大于 0 的实数的集合。是的,根据 Fortran 标准,它是依赖于编译器的,但在实践中,如果你将它视为所有正 IEEE 的集合,你不会错得太远。浮点数,单精度或双精度,如您所愿。但严格来说,您需要熟悉编译器支持的实数种类,其中几乎肯定会包括 IEEE fp 数字,但也可能包括其他数字。

The answer to part 2 of your question is that the range of the exponential function is the set of all positive real numbers. In Fortran terms that means the set of all REAL numbers greater than 0. Yes it is, according to the Fortran standards, compiler dependent, but in practice you won't go far wrong if you take it to be the set of all positive IEEE floating-point numbers, single or double precision as you wish. But to be strict you need to be familiar with the KINDs of real numbers that your compiler supports which will almost certainly include the IEEE f-p numbers, but may include others too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文