]> granicus.if.org Git - postgresql/blob - src/port/rint.c
8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
[postgresql] / src / port / rint.c
1 /*-------------------------------------------------------------------------
2  *
3  * rint.c
4  *        rint() implementation
5  *
6  * Copyright (c) 1999, repas AEG Automation GmbH
7  *
8  *
9  * IDENTIFICATION
10  *        $PostgreSQL: pgsql/src/port/rint.c,v 1.2 2003/11/29 19:52:13 pgsql Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14
15 #include "c.h"
16 #include <math.h>
17
18 double
19 rint(double x)
20 {
21         double          f,
22                                 n = 0.;
23
24         f = modf(x, &n);
25
26         if (x > 0.)
27         {
28                 if (f > .5)
29                         n += 1.;
30         }
31         else if (x < 0.)
32         {
33                 if (f < -.5)
34                         n -= 1.;
35         }
36         return n;
37 }