This is the rint() definition:
http://www.gnu.org/manual/glibc-2.2.5/html_node/Rounding-Functions.html

There was a bug in glibc rint, but I think it has been fixed.

Probably, most of the time nearbyint() is what is really wanted instead
of rint().  The rint() function can throw an exception even when it does
what is wanted.

If the current rounding mode is round toward -INF, rint(x) is identical
to floor(x).

If the current rounding mode is round toward +INF, rint(x) is identical
to ceil(x).

If the current rounding mode is round to nearest, rint(x) is identical
to nearest(x).

If the current rounding mode is round toward zero, rint(x) is identical
to trunc(x).

Most of the time, this is what rint() is doing if we are round to
nearest:
return floor(x+0.5);

> -----Original Message-----
> From: Andrew Dunstan [mailto:andrew@dunslane.net] 
> Sent: Friday, May 09, 2003 11:54 AM
> To: PostgreSQL-development
> Subject: Re: [HACKERS] rint() replacement
> 
> 
> 
> speaking of rint(), I just got this on Linux on a clean get from CVS:
> 
> gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations 
> -fpic -I../../../. ./src/interfaces/ecpg/include 
> -I../../../../src/include/utils -I../../../../
> src/include   -c -o dt_common.o dt_common.c
> dt_common.c: In function `dt2time':
> dt_common.c:1271: warning: implicit declaration of function `rint'
> 
> which I guess is kinda undesirable...
> 
> andrew
> 
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 


Fri, 9 May 2003 11:59:50 -0700
"Dann Corbit" <DCorbit@connx.com>
Re: rint() replacement
"Dann Corbit" <DCorbit@connx.com> writes:
> Probably, most of the time nearbyint() is what is really wanted instead
> of rint().  The rint() function can throw an exception even when it does
> what is wanted.

The real issue here is "what is portable behavior"?

PG never changes the rounding mode, so we should always get the default,
which is round-to-nearest-even unless there have been big changes made
while I wasn't looking.

Expressing that as nearest() instead of rint() would be fine with me if
all platforms recognized nearest().  But rint() is more likely to be
portable in the real world, AFAIK.

I do have a bit of a problem with the CVS-tip version of this code: it
falls back to implementing rint() in terms of modf().  I would like to
know the justification for assuming that modf() is more portable than
rint().

> Most of the time, this is what rint() is doing if we are round to
> nearest:
> return floor(x+0.5);

I'd be happier with that as a fallback implementation ...

			regards, tom lane


Sat, 10 May 2003 00:29:27 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: rint() replacement 
On Sat, May 10, 2003 at 12:29:27AM -0400, Tom Lane wrote:
> "Dann Corbit" <DCorbit@connx.com> writes:
> 
> I do have a bit of a problem with the CVS-tip version of this code: it
> falls back to implementing rint() in terms of modf().  I would like to
> know the justification for assuming that modf() is more portable than
> rint().

modf() is part of C89 and POSIX, just as floor().  I have modf()
here, I do not have rint().

rint() was a BSD thing and is now part of C99.


Kurt


Sat, 10 May 2003 13:53:10 +0200
Kurt Roeckx <Q@ping.be>
Re: rint() replacement