为了表达平等和不平等,什么被认为是惯用的Fortran? [英] To represent equalities and inequalities, what is considered idiomatic Fortran?

查看:155
本文介绍了为了表达平等和不平等,什么被认为是惯用的Fortran?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用通常的

  a< p> b 
x == y

等等或者是

  a .lt。 b 
x .eq。 y

用得更频繁吗?

有时候我不确定什么是习惯用法,什么是使用Fortran时打卡时代的遗留问题,这可能是我没有找到答案的一种情况

解决方案

据我所知,选择只是风格,我不认为社区已经同意那个更好。 Fortran 90标准中引入了'现代'运算符(< / code>, == ...)已经出现了一段时间。



值得注意的是逻辑运算符( .NOT。 .OR。 ...)的格式与传统关系运算符( .NE。 .LT 。 ...)。因此,人们可以选择混搭:

 ((a <1.0).AND。(a> 0.0 ))

或保持一致:

<$ p
$ ((a .LT。1.0).AND。(a .GT。0.0))

我个人更喜欢现代形式,特别是在这些情况下,因为它有助于区分逻辑运算符和关系运算符。



在我看来,那么(dif (dif .LT。tol)更容易理解,特别是对于休闲或快速阅读。

我也很好奇 - 其他人会有不同的偏好吗?也许有人可以参考一个有意见的fortran风格指南。

有趣的是,对我来说一个常见的Fortran引用( PGI Fortran ,第11页)列出了表中的所有现代操作符,使用一个单一遗留操作符的示例,并没有提及任何的其他传统运营商。

Is it more idiomatic to use the usual

a < b
x == y

and so on or is

a .lt. b
x .eq. y

used more frequently?

Sometimes I'm not sure what is idiomatic and what is just legacy from the punchcard era when using Fortran, and this is probably the one case I have not found an answer for yet.

解决方案

As far as I know, the choice is stylistic only, and I don't think the community has agreed that one is better. The 'modern' operators (<, == ...) were introduced in the fortran 90 standard so both have been around for a while.

It's worth noting that logical operators (.NOT., .OR. ...) are formatted similarly to the legacy relational operators (.NE., .LT. ...). So one can choose to mix-and-match:

 ((a < 1.0) .AND. (a > 0.0))

or be consistent:

 ((a .LT. 1.0) .AND. (a .GT. 0.0))

I personally prefer the modern form, particularly in these cases, because it helps to distinguish between logical and relational operators.

It also seems to me that (dif < tol) is easier to quickly understand than (dif .LT. tol), particularly for the casual or fast reader.

I'm curious too, though - will other people have different preferences? Perhaps somebody can reference a fortran style guide that has an opinion.

Interestingly, a common fortran reference for me (PGI Fortran, page 11) lists all the modern operators in a table, uses an example with a single legacy operator, and doesn't make mention of any of the other legacy operators.

这篇关于为了表达平等和不平等,什么被认为是惯用的Fortran?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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