Debian Codegraph @

doc/src/intrinsics/numeric/floor.md

raw
1 # floor(x, kind): Integer Floor
2
3 Integer floor function.
4
5 ## Declaration
6
7 ### Syntax
8
9 ```fortran
10 retval = floor(x)
11 elemental integer function floor(x, kind)
12 ```
13
14 ### Arguments
15
16 `x` the input value must be of type real.
17
18 `kind` the optional input parameter must be a scalar integer constant expression.
19
20 ### Return values
21
22 The return value is of type integer(kind) if kind is passed as input parameter.
23 If not, default kind integer is returned.
24
25 The return value is equal to or nearest greatest integer less than or equal to
26 `x`.
27
28 ## Description
29
30 **floor(x)** returns the greatest integer less than or equal to x. It returns
31 an integer value unless spefically specified using second optional paramter.
32
33 ## Types
34
35 Supported argument types is real.
36
37 ```fortran
38 interface floor
39 module procedure sfloor_i32, sfloor_i64, dfloor_i32, dfloor_i64
40 end interface
41
42 contains
43
44 elemental integer(i32) function sfloor_i32(x, kind)
45 real(sp), intent(in) :: x
46 integer(i32), intent(in) :: kind
47 end function
48
49 elemental integer(i64) function sfloor_i64(x, kind)
50 real(sp), intent(in) :: x
51 integer(i64), intent(in) :: kind
52 end function
53
54 elemental integer(i32) function dfloor_i32(x, kind)
55 real(dp), intent(in) :: x
56 integer(i32), intent(in) :: kind
57 end function
58
59 elemental integer(i64) function dfloor_i64(x, kind)
60 real(dp), intent(in) :: x
61 integer(i64), intent(in) :: kind
62 end function
63 ```
64
65 ## Examples
66
67 ```fortran
68 program intrinsics_floor
69 implicit none
70 real, parameter :: x = 3.1
71 print *, floor(x)
72 print *, floor(-3.1)
73 end program
74 ```
75
76 **Result:**
77
78 ```
79 3
80 -4
81 ```
82
83 ## See Also
84
85 [ceiling](ceiling.md), [mod](mod.md).