# Fortran Intrinsic Functions Fortran provides many commonly used functions, called intrinsic functions. To use a Fortran function, one needs to understand the following items:
• the name and meaning of the function such as ABS() and SQRT()
• the number of arguments
• the range of the argument
• the types of the arguments
• the type of the return value or the function value
For example, function SQRT() accepts a REAL argument whose value must be non-negative and computes and returns the square root of the argument. Therefore, SQRT(25.0) returns the square root of 25.0 and SQRT(-1.0) would cause an error since the argument is negative.
• Mathematical functions:

 Function Meaning Arg. Type Return Type ABS(x) absolute value of x INTEGER INTEGER REAL REAL SQRT(x) square root of x REAL REAL SIN(x) sine of x radian REAL REAL COS(x) cosine of x radian REAL REAL TAN(x) tangent of x radian REAL REAL ASIN(x) arc sine of x REAL REAL ACOS(x) arc cosine of x REAL REAL ATAN(x) arc tangent of x REAL REAL EXP(x) exp(x) REAL REAL LOG(x) natural logarithm of x REAL REAL

Note that all trigonometric functions use radian rather than degree for measuring angles. For function ATAN(x), x must be in (-PI/2, PI/2). For ASIN(x) and ACOS(x), x must be in [-1,1].

• Conversion functions:

 Function Meaning Arg. Type Return Type INT(x) integer part x REAL INTEGER NINT(x) nearest integer to x REAL INTEGER FLOOR(x) greatest integer less than or equal to x REAL INTEGER FRACTION(x) the fractional part of x REAL REAL REAL(x) convert x to REAL INTEGER REAL
• Other functions:

 Function Meaning Arg. Type Return Type MAX(x1, x2, ..., xn) maximum of x1, x2, ... xn INTEGER INTEGER REAL REAL MIN(x1, x2, ..., xn) minimum of x1, x2, ... xn INTEGER INTEGER REAL REAL MOD(x,y) remainder x - INT(x/y)*y INTEGER INTEGER REAL REAL ### Functions in an Expression:

• Functions have higher priority than any arithmetic operators.
• All arguments of a function can be expressions. These expressions are evaluated first and passed to the function for computing the function value.
• The returned function value is treated as a value in the expression. ### An Example:

The example below has three initialized variables A, B and C. The result is computed and saved into uninitialized variable R.

```REAL     ::  A = 1.0, B = -5.0, C = 6.0
REAL     ::  R

R = (-B + SQRT(B*B - 4.0*A*C))/(2.0*A)
```
The following uses brackets to indicated the order of evaluation:
```(-B + SQRT(B*B - 4.0*A*C))/(2.0*A)
--> ([-B] + SQRT(B*B - 4.0*A*C))/(2.0*A)
--> (5.0 + SQRT(B*B - 4.0*A*C))/(2.0*A)
--> (5.0 + SQRT([B*B] - 4.0*A*C))/(2.0*A)
--> (5.0 + SQRT(25.0 - 4.0*A*C))/(2.0*A)
--> (5.0 + SQRT(25.0 - [4.0*A]*C))/(2.0*A)
--> (5.0 + SQRT(25.0 - 4.0*C))/(2.0*A)
--> (5.0 + SQRT(25.0 - [4.0*C))/(2.0*A)
--> (5.0 + SQRT(25.0 - 24.0))/(2.0*A)
--> (5.0 SQRT([25.0 - 24.0]))/(2.0*A)
--> (5.0 + SQRT(1.0))/(2.0*A)
--> (5.0 + 1.0)/(2.0*A)
--> ([5.0 + 1.0])/(2.0*A)
--> 6.0/(2.0*A)
--> 6.0/([2.0*A])
--> 6.0/2.0
--> 3.0
```
Therefore, R receives 3.0.