Upgrade src/port/rint.c to be POSIX-compliant.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Mar 2015 19:54:08 +0000 (15:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Mar 2015 19:54:18 +0000 (15:54 -0400)
commit06bf0dd6e354c765403d1331cc9896b360754521
tree7548d7509693471c71e479f5314360f1f21106ad
parent2ed5b87f96d473962ec5230fd820abfeaccb2069
Upgrade src/port/rint.c to be POSIX-compliant.

The POSIX spec says that rint() rounds halfway cases to nearest even.
Our substitute implementation failed to do that, rather rounding halfway
cases away from zero; and it also got some other cases (such as minus
zero) wrong.  This led to observable cross-platform differences, as
reported in bug #12885 from Rich Schaaf; in particular, casting from
float to int didn't honor round-to-nearest-even on builds using rint.c.

Implement something that attempts to cover all cases per spec, and add
some simple regression tests so that we'll notice if any platforms still
get this wrong.

Although this is a bug fix, no back-patch, as a behavioral change in
the back branches was agreed not to be a good idea.

Pedro Gimeno Fortea, reviewed by Michael Paquier and myself
src/port/rint.c
src/test/regress/expected/int2.out
src/test/regress/expected/int4.out
src/test/regress/expected/int8-exp-three-digits.out
src/test/regress/expected/int8.out
src/test/regress/sql/int2.sql
src/test/regress/sql/int4.sql
src/test/regress/sql/int8.sql