Debian Codegraph @

doc/src/intrinsics/numeric/anint.md

raw
1 # anint(x, [kind]): Round to Nearest Whole Number
2
3 Round to nearest whole number.
4
5 ## Declaration
6
7 ### Syntax
8
9 ```fortran
10 retval = anint(x, [kind])
11 elemental real function anint(x, [kind])
12 ```
13
14 ### Arguments
15
16 `x` the input value must be of type real.
17
18 `kind` the optional input parameter initialises the kind of the result.
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 real is returned.
24
25 The return value is equal to rounded whole number.
26
27 ## Description
28
29 **anint(x)** calculates rounded value of input parameter `x`.
30
31 If `x` is less than or equal to 0 i.e., if `x` is negative or 0, `anint(x)`
32 returns `aint(x - 0.5)`.
33
34 If `x` is greater than 0, `anint(x)` returns `aint(x + 0.5)`.
35
36 The optional parameter `kind` specifies the kind of the result.
37
38 ## Types
39
40 Supported argument types is real.
41
42 ## Examples
43
44 ```fortran
45 program intrinsics_anint
46 print *, anint(2.6)
47 print *, anint(-2.6)
48 end program
49 ```
50
51 **Result:**
52
53 ```
54 3.0
55 -3.0
56 ```
57
58 ## See Also
59
60 [aint](aint.md).