Fortran77编译器处理PI=4.D0*DATAN(1.D0)

发布于 2024-08-20 02:37:38 字数 109 浏览 3 评论 0 原文

当在 fortran77 中使用以下代码计算 PI 时,编译器会评估该值还是在运行时评估?

PI=4.D0*DATAN(1.D0)

When using the following to compute PI in fortran77, will the compiler evaluate this value or will it be evaluated at run time?

PI=4.D0*DATAN(1.D0)

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

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

发布评论

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

评论(2

心欲静而疯不止 2024-08-27 02:37:38

编辑:取决于编译器:请参阅下面的我的编辑。 编辑结束

我同意 Mick Sharpe 的建议,即它将在运行时进行评估。出于好奇,我用 PI=4.D0*DATAN(1.D0) rel="nofollow noreferrer">Silverfrost 的 ftn77 编译器 并查看生成的二进制文件。相关部分看起来像这样:

fld1                 ; push 1.D0 onto the FPU register stack
call    ATAN_X
fmul    dbl_404000   ; multiply by 4.D0

所以确实,这里没有编译器的聪明才智。

这当然可能与另一个编译器(例如 g77)不同。 编辑:显然,对于g77(gcc的fortran77前端),可以(默认情况下启用)使用gcc的内置 atan 函数自动将 PI=4.D0*DATAN(1.D0) 折叠为常量编辑结束

EDIT: depends on the compiler: see my EDIT below. EDIT END

i second Mick Sharpe's suggestion that it will be evaluated at runtime. just out of curiosity, i compiled PI=4.D0*DATAN(1.D0) with Silverfrost's ftn77 compiler and looked at the generated binary. the relevant part looks like so:

fld1                 ; push 1.D0 onto the FPU register stack
call    ATAN_X
fmul    dbl_404000   ; multiply by 4.D0

so indeed, no compiler cleverness here.

this of course might be different with another compiler (eg. g77). EDIT: apparently, with g77 (the fortran77 front-end for gcc) it is possible (and enabled by default) to use gcc's built-in atan function to auto-fold PI=4.D0*DATAN(1.D0) into a constant. EDIT END

萌逼全场 2024-08-27 02:37:38

对数学函数的调用通常在运行时进行评估。毕竟,没有什么可以阻止您编写自己的数学函数。如果在编译时评估它们,这是不可能的。

Calls to math functions are normally evaluated at run time. After all, there's nothing to stop you writing your own math functions. This would not be possible if they were evaluated at compile time.

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