Re: BUG #12885: The result of casting a double to an integer depends on the database version

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: rschaaf(at)commoninf(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12885: The result of casting a double to an integer depends on the database version
Date: 2015-03-25 00:19:37
Message-ID: CAB7nPqSkh+Kma8+oGd5w67qZzSaVtkFo-2dgHwf5MAsr+enk4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Mar 24, 2015 at 10:37 PM, Tom Lane wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>> For example by passing 2.5, we would get 3.0, and not 2.0 (nearest
>> even number). So isn't the problem here?
>
> Hmm ... why are we using src/port's version? rint() has been required
> by POSIX for decades, surely MSVC has got it?
>
> (IOW, I'd rather fix this by removing src/port's version than by
> trying to upgrade it to full IEEE spec.)

rint() has been added in MSVC 2013, per se for example this thing
introduced by cec8394:
src/tools/msvc/Mkvcbuild.pm: push(@pgportfiles, 'rint.c') if
($vsVersion < '12.00');

So I would imagine that in a majority of cases the version of rint()
used by an MSVC build on Windows is src/port/rint.c, not to mention
that on platforms where rint() is not available (the world is full of
surprises), the behavior would be incorrect. It is possible to blame
Redmond's folks about missing rint() from MSVC for more than 10 years,
but the blame could be put on PG-side as well.

Hence I'd rather think that patching src/port is the way to go, with
for example something like the patch attached. That's a behavioral
change, so maybe a backpatch is not welcome. See for example Rich's
email meaning that 9.4 behavior is broken as I understand it, but
that's actually the other way around, and I suspect that the version
of 9.4 Rich has used was built with at least MSVC 2013, while the
version of 9.3 he used was built with src/port/rint.c.
--
Michael

Attachment Content-Type Size
20150325_port_rint_fix.patch text/x-diff 389 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2015-03-25 00:53:42 Re: minor: contrib/btree_gin/btree_gin.c uses DirectFunctionCall3(inet_in,..)
Previous Message Bruce Momjian 2015-03-24 23:53:00 Re: ALTER TABLE documentation or parser bug