Re: rint() replacement - Mailing list pgsql-hackers

From Tom Lane
Subject Re: rint() replacement
Date
Msg-id 4254.1052540967@sss.pgh.pa.us
Whole thread Raw
In response to Re: rint() replacement  ("Dann Corbit" <DCorbit@connx.com>)
Responses Re: rint() replacement
List pgsql-hackers
"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



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Win32 runs configure and gmake test
Next
From: Joe Conway
Date:
Subject: Re: Beta July 1