Manual Reference Pages  - floor (3fortran)

NAME

FLOOR(3) - [NUMERIC] Function to return largest integral value not greater than argument

SYNOPSIS

result = floor(a [,kind])

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

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

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o A is a real of any kind
o KIND is any valid value for type integer.
o the result is an integer of the specified or default kind

DESCRIPTION

FLOOR(3) returns the greatest integer less than or equal to A.

In other words, it picks the whole number at or to the left of the value on the number line.

This means care has to be taken that the magnitude of the real value A does not exceed the range of the output value, as the range of values supported by real values is typically larger than the range for integers.

OPTIONS

o A : The value to operate on. Valid values are restricted by the size of the returned integer kind to the range -HUGE(INT(A,KIND=KIND))-1 to HUGE(INT(A),KIND=KIND).
o KIND : A scalar integer constant initialization expression indicating the kind parameter of the result.

RESULT

The return value is of type integer(kind) if KIND is present and of default-kind integer otherwise.

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

If in range for the kind of the result the result is the whole number at or to the left of the input value on the number line.

If A is positive the result is the value with the fractional part removed.

If A is negative, it is the whole number at or to the left of the input value.

EXAMPLES

Sample program:

    program demo_floor
    implicit none
    real :: x = 63.29
    real :: y = -63.59
        print *, x, floor(x)
        print *, y, floor(y)
       ! elemental
       print *,floor([ &
       &  -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  ])

! note even a small deviation from the whole number changes the result print *, [2.0,2.0-epsilon(0.0),2.0-2*epsilon(0.0)] print *,floor([2.0,2.0-epsilon(0.0),2.0-2*epsilon(0.0)])

! A=Nan, Infinity or <huge(0_KIND)-1 < A > huge(0_KIND) is undefined end program demo_floor

Results:

     >     63.29000             63
     >    -63.59000            -64
     >            -3         -3         -3         -2         -2         -1
     >            -1          0          0          1          1          2
     >             2          2          2
     >     2.000000      2.000000      2.000000
     >             2          1          1

STANDARD

Fortran 95

SEE ALSO

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

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


Nemo Release 3.1 floor (3fortran) April 28, 2024
Generated by manServer 1.08 from 95e51a47-e86c-4e69-a501-6dc38e354764 using man macros.