Manual Reference Pages  - int (3fortran)

NAME

INT(3) - [TYPE:NUMERIC] Truncate towards zero and convert to integer

SYNOPSIS

result = int(a [,kind])

         elemental integer(kind=KIND) function int(a, KIND )

TYPE(kind=**),intent(in) :: a integer,optional :: KIND

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o A shall be of type integer, real, or complex, or a boz-literal-constant.
o KIND shall be a scalar integer constant expression.

DESCRIPTION

INT(3) truncates towards zero and return an integer.

OPTIONS

o A : is the value to truncate towards zero
o KIND : indicates the kind parameter of the result. If not present the returned type is that of default integer type.

RESULT

returns an integer variable applying the following rules:

CASE:
1. If A is of type integer, INT(a) = a
2. If A is of type real and |A| < 1, INT(A) equals 0. If |A| >= 1, then INT(A) equals the integer whose magnitude does not exceed A and whose sign is the same as the sign of A.
3. If A is of type complex, rule 2 is applied to the real part of A.
4. If a is a boz-literal constant, it is treated as an integer with the kind specified.

The interpretation of a bit sequence whose most significant bit is 1 is processor dependent.

The result is undefined if it cannot be represented in the specified integer type.

EXAMPLES

Sample program:

    program demo_int
    use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
    implicit none
    integer :: i = 42
    complex :: z = (-3.7, 1.0)
    real :: x=-10.5, y=10.5

print *, int(x), int(y)

print *, int(i)

print *, int(z), int(z,8) ! elemental print *, int([-10.9,-10.5,-10.3,10.3,10.5,10.9]) ! note int(3) truncates towards zero

! CAUTION: ! a number bigger than a default integer can represent ! produces an incorrect result and is not required to ! be detected by the program. x=real(huge(0))+1000.0 print *, int(x),x ! using a larger kind print *, int(x,kind=int64),x

print *, int(& & B"111111111111111111111111111111111111111111111111111111111111111",& & kind=int64) print *, int(O"777777777777777777777",kind=int64) print *, int(Z"7FFFFFFFFFFFFFFF",kind=int64)

! elemental print * print *,int([ & & -2.7, -2.5, -2.2, -2.0, -1.5, -1.0, -0.5, & & 0.0, & & +0.5, +1.0, +1.5, +2.0, +2.2, +2.5, +2.7 ])

end program demo_int

Results:

     >          -10   10
     >           42
     >           -3  -3
     >          -10  -10  -10   10   10  10
     >  -2147483648   2.14748467E+09
     >   2147484672   2.14748467E+09
     >   9223372036854775807
     >   9223372036854775807
     >   9223372036854775807
     >
     >  -2          -2          -2          -2          -1
     >  -1           0           0           0           1
     >   1           2           2           2           2

STANDARD

FORTRAN 77

SEE ALSO

AINT(3), ANINT(3), NINT(3), SELECTED_INT_KIND(3), CEILING(3), FLOOR(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 int (3fortran) April 28, 2024
Generated by manServer 1.08 from 8a3c063f-04be-4502-b3bb-2c6647330226 using man macros.