1RINT(3P) POSIX Programmer's Manual RINT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 rint, rintf, rintl - round-to-nearest integral value
13
15 #include <math.h>
16
17 double rint(double x);
18 float rintf(float x);
19 long double rintl(long double x);
20
21
23 These functions shall return the integral value (represented as a dou‐
24 ble) nearest x in the direction of the current rounding mode. The cur‐
25 rent rounding mode is implementation-defined.
26
27 If the current rounding mode rounds toward negative infinity, then
28 rint() shall be equivalent to floor(). If the current rounding mode
29 rounds toward positive infinity, then rint() shall be equivalent to
30 ceil().
31
32 These functions differ from the nearbyint(), nearbyintf(), and nearby‐
33 intl() functions only in that they may raise the inexact floating-point
34 exception if the result differs in value from the argument.
35
36 An application wishing to check for error situations should set errno
37 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
38 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
39 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
40 occurred.
41
43 Upon successful completion, these functions shall return the integer
44 (represented as a double precision number) nearest x in the direction
45 of the current rounding mode.
46
47 If x is NaN, a NaN shall be returned.
48
49 If x is ±0 or ±Inf, x shall be returned.
50
51 If the correct value would cause overflow, a range error shall occur
52 and rint(), rintf(), and rintl() shall return the value of the macro
53 ±HUGE_VAL, ±HUGE_VALF, and ±HUGE_VALL (with the same sign as x),
54 respectively.
55
57 These functions shall fail if:
58
59 Range Error
60 The result would cause an overflow.
61
62 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
63 then errno shall be set to [ERANGE]. If the integer expression
64 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow
65 floating-point exception shall be raised.
66
67
68 The following sections are informative.
69
71 None.
72
74 On error, the expressions (math_errhandling & MATH_ERRNO) and
75 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
76 at least one of them must be non-zero.
77
79 None.
80
82 None.
83
85 abs(), ceil(), feclearexcept(), fetestexcept(), floor(), isnan(), near‐
86 byint(), the Base Definitions volume of IEEE Std 1003.1-2001, Section
87 4.18, Treatment of Error Conditions for Mathematical Functions,
88 <math.h>
89
91 Portions of this text are reprinted and reproduced in electronic form
92 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
93 -- Portable Operating System Interface (POSIX), The Open Group Base
94 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
95 Electrical and Electronics Engineers, Inc and The Open Group. In the
96 event of any discrepancy between this version and the original IEEE and
97 The Open Group Standard, the original IEEE and The Open Group Standard
98 is the referee document. The original Standard can be obtained online
99 at http://www.opengroup.org/unix/online.html .
100
101
102
103IEEE/The Open Group 2003 RINT(3P)