Next: Numerical Intrinsic Functions
Up: Intrinsic Functions
Previous: Generic vs. Specific Functions
  Contents
In what follows we will use the short notation
I,R,D,C for INTEGER, REAL, DOUBLE PRECISION
and COMPLEX.
- INT(x); converts a R, D or
C argument (x) to the corresponding
INTEGER approximation using
``round towards '' (dumps the fractional part).
For a complex argument, INT(real part) is taken.
- CEILING(x); converts a R or D
argument (x) to the corresponding
INTEGER approximation using
``round up''.
- FLOOR(x); converts a R or D
argument (x) to the corresponding
INTEGER approximation using
``round down''.
- NINT(x); converts a R or D argument
(x) to the nearest
INTEGER (using ``round to nearest'').
For example,
- REAL(k); converts a I or D
argument (k) to the corresponding
REAL approximation. Selects the real part
of a C argument.
- AIMAG(z); selects the imaginary part
of a C argument.
- DBLE(x); converts an INTEGER or REAL
argument (x) to the corresponding
DOUBLE PRECISION approximation.
- CMPLX(x,y); returns the complex value
x + iy.
The arguments x,y are usually REAL, but can also be
INTEGER or DOUBLE PRECISION, in which case
the returned value is
REAL(x) + iREAL(y).
CMPLX(x) returns the
complex value REAL(x) + i.
For example,
{}
integer :: i=2
real :: t=1.7
double precision :: x=1.7d0,y=2.8d0
complex :: z=(1.7,2.8)
print*, x, real(x) ! output = 1.7, 1.70000005
print*, real(z), aimag(z) ! output = 1.70000005, 2.79999995
print*, dble(t) ! output = 1.7000000476837158
print*, cmplx(i), cmplx(z) ! output = (2.,0.e+0), (1.70000005,2.79999995)
Note the errors in double to real and real to double conversions,
as well as the representation errors.
Next: Numerical Intrinsic Functions
Up: Intrinsic Functions
Previous: Generic vs. Specific Functions
  Contents
Adrian Sandu
2001-08-26