Operations and Expressions

Operations and Expressions

FORTRAN provide five basic arithmetic operations:
Subtraction -
Multiplication *
Division /
Exponentiation **

FORTRAN expressions
Mathematical NotationCorrect ExpressionIncorrect Expression
a.bA*BAB (no operation)
a.(-b)A * (-B) or -A*BA*-B (two operations side by side)
a+2A+2.0A=2 (mixed integer and real)
-(a+b)-(A+B) or -A-B-A+B or -+A+B
{a+[b.(c-d)-c]+b}A+(B*(C-D)-C)+B){A+[B*(C-D)-C]+B}
A / (B+C)A / B + C
A ** (B+C)A ** B + C
(A ** B) + CA ** (B + C)

Lists some examples of correct and incorrect ways of forming FORTRAN expressions.
Mathematical Functions

Fortran provides for the use of certain common mathematical functions.

Mathematical Functions
Mathematical FunctionFORTRAN Name
ExponentialEXP
Natural LogarithmALOG
Common logarithmALOG10
Sine of an angle in radiansSIN
Cosine of an angle in radiansCOS
Hyperbolic tangentTANH
Square rootSQRT
Absolute valueABS

Arithmetic Assignment Statements

The most important is computing a new value of a variable, which is done with an arithmetic assignment statement. Its general form is a = b, in which "a" is a variable name, written without a sign, and "b" is any expression.

Examples:
I=10
ABC=12.34
D=2.0
Y=D/5.0
TAN=SIN(D)/COS(D)
ABSVAL=ABS(TAN)