Intrinsic functions present a set of the most fundamental functions which are built into the compiler and are directly accessible in your program. These include basic mathematical functions complemented with functions for conversions between different numerical data types. Look at the table below to learn about the most useful functions which you can directly use in your codes.
function | description |
SQRT(x) |
calculates the square root of x |
LOG(x) |
calculates the natural logarithm of x (base ) |
LOG10(x) |
calculates the common log of x (base 10) |
EXP(x) |
raises base to the x power () |
SIN(x) |
calculates the sine of x (x expressed in radians) |
COS(x) |
calculates the cosine of x (x expressed in radians) |
TAN(x) |
calculates the tangent of x (x expressed in radians) |
ASIN(x) |
calculates the inverse sine of x (x expressed in radians) |
ACOS(x) |
calculates the inverse cosine of x (x expressed in radians) |
ATAN(x) |
calculates the inverse tangent of x (x expressed in radians) |
REAL(x) |
converts the argument to a real value |
INT(x) |
converts the argument to an integer value |
NINT(x) |
rounds x to the nearest integer value |
ABS(x) |
calculates the absolute value of x |
MAX(x1,x2,...) |
returns the maximum value of x1 , x2 , ... |
Problem: The normal (Gaussian) distribution function is defined as
phi
. Display the results.
Solution:
real phi(50), x, pi parameter( pi=3.1415927 ) x = -3.0 do while (x .le. 3.0) phi(idx) = 1.0/SQRT(2*pi) * EXP(-x**2/2.0) write(*,'("For x = ",F4.1,", phi(x) = ",F6.4)') + x, phi(idx) x = x + 0.2 enddo
When dividing two integers or a real number and an integer, be careful to enter all integers as real
numbers. For example, the expression 1/4
is not 0.25, as expected, but zero. When dividing an
integer by another integer, F77 automatically rounds the result towards zero. To avoid this, you
have to always enter the values in their real expressions. Hence, 1.0/4.0
correctly returns
0.25.
A slightly different case is a division of two variables of type integer
or
byte
. Suppose that we calculate an average of n
integral numbers whose sum is stored
in variable sum
. The average should then be calculated as
aver = REAL(sum)/REAL(n)
. Remember that aver = sum/REAL(n)
would give the correct
average if sum
were of type real
.
Roman Gröger (2015-09-23)