1999-12-16 02:25:23 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* rint.c
|
|
|
|
* rint() implementation
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999, repas AEG Automation GmbH
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2003-05-09 18:26:29 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/port/rint.c,v 1.1 2003/05/09 16:26:29 momjian Exp $
|
1999-12-16 02:25:23 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2001-08-24 16:07:50 +02:00
|
|
|
#include "c.h"
|
1999-12-16 02:25:23 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
double
|
|
|
|
rint(double x)
|
1999-12-16 02:25:23 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
double f,
|
|
|
|
n = 0.;
|
1999-12-16 02:25:23 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
f = modf(x, &n);
|
1999-12-16 02:25:23 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (x > 0.)
|
|
|
|
{
|
|
|
|
if (f > .5)
|
|
|
|
n += 1.;
|
|
|
|
}
|
|
|
|
else if (x < 0.)
|
|
|
|
{
|
|
|
|
if (f < -.5)
|
|
|
|
n -= 1.;
|
|
|
|
}
|
|
|
|
return n;
|
1999-12-16 02:25:23 +01:00
|
|
|
}
|