📅  最后修改于: 2020-11-04 06:14:02             🧑  作者: Mango
运算符是一个符号,告诉编译器执行特定的数学或逻辑操作。 Fortran提供以下类型的运算符-
让我们一一看一下所有这些类型的运算符。
下表显示了Fortran支持的所有算术运算运算符。假设变量A持有5,变量B持有3,则-
Operator | Description | Example |
---|---|---|
+ | Addition Operator, adds two operands. | A + B will give 8 |
– | Subtraction Operator, subtracts second operand from the first. | A – B will give 2 |
* | Multiplication Operator, multiplies both operands. | A * B will give 15 |
/ | Division Operator, divides numerator by de-numerator. | A / B will give 1 |
** | Exponentiation Operator, raises one operand to the power of the other. | A ** B will give 125 |
下表显示了Fortran支持的所有关系运算符。假设变量A持有10,变量B持有20,则-
Operator | Equivalent | Description | Example |
---|---|---|---|
== | .eq. | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (A == B) is not true. |
/= | .ne. | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (A != B) is true. |
> | .gt. | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (A > B) is not true. |
< | .lt. | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (A < B) is true. |
>= | .ge. | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (A >= B) is not true. |
<= | .le. | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (A <= B) is true. |
Fortran中的逻辑运算符仅对逻辑值.true起作用。和.false。
下表显示了Fortran支持的所有逻辑运算符。假设变量A保持.true。变量B保留.false。 ,然后-
Operator | Description | Example |
---|---|---|
.and. | Called Logical AND operator. If both the operands are non-zero, then condition becomes true. | (A .and. B) is false. |
.or. | Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. | (A .or. B) is true. |
.not. | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A .and. B) is true. |
.eqv. | Called Logical EQUIVALENT Operator. Used to check equivalence of two logical values. | (A .eqv. B) is false. |
.neqv. | Called Logical NON-EQUIVALENT Operator. Used to check non-equivalence of two logical values. | (A .neqv. B) is true. |
运算符优先级确定表达式中术语的分组。这会影响表达式的求值方式。某些运算符具有更高的优先级;例如,乘法运算符的优先级高于加法运算符。
例如,x = 7 + 3 * 2;在这里,x被赋值为13,而不是20,因为运算符*的优先级比+高,因此它首先与3 * 2相乘,然后加到7。
在此,优先级最高的运算符出现在表格的顶部,优先级最低的运算符出现在表格的底部。在表达式中,优先级较高的运算符将首先被评估。
Category | Operator | Associativity |
---|---|---|
Logical NOT and negative sign | .not. (-) | Left to right |
Exponentiation | ** | Left to right |
Multiplicative | * / | Left to right |
Additive | + – | Left to right |
Relational | < <= > >= | Left to right |
Equality | == /= | Left to right |
Logical AND | .and. | Left to right |
Logical OR | .or. | Left to right |
Assignment | = | Right to left |