Operations and Expressions

Home Computational Physics FORTRAN Operations and Expressions

Operations and Expressions

FORTRAN provide five basic arithmetic operations:
Addition +
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
Mathematical NotationA / (B+C)A / B + C
Mathematical NotationA ** (B+C)A ** B + C
Mathematical Notation(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
Natural LogarithmALOG
Common logarithmALOG10
Sine of an angle in radiansSIN
Cosine of an angle in radiansCOS
Hyperbolic tangentTANH
Square rootSQRT
Arctangent: Angle computed in radiansATAN
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.