Fix the int8 and int2 cases of (minimum possible integer) % (-1).
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Nov 2012 22:30:18 +0000 (17:30 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Nov 2012 22:30:18 +0000 (17:30 -0500)
commit46c79df29e5fafdec1569ad217890809df068c24
treeaacc7494cc7272d4e87c3c817ca2f4e87324810b
parentc027d84c81d5e07e58cd25ea38805d6f1ae4dfcd
Fix the int8 and int2 cases of (minimum possible integer) % (-1).

The correct answer for this (or any other case with arg2 = -1) is zero,
but some machines throw a floating-point exception instead of behaving
sanely.  Commit f9ac414c35ea084ff70c564ab2c32adb06d5296f dealt with this
in int4mod, but overlooked the fact that it also happens in int8mod
(at least on my Linux x86_64 machine).  Protect int2mod as well; it's
not clear whether any machines fail there (mine does not) but since the
test is so cheap it seems better safe than sorry.  While at it, simplify
the original guard in int4mod: we need only check for arg2 == -1, we
don't need to check arg1 explicitly.

Xi Wang, with some editing by me.
src/backend/utils/adt/int.c
src/backend/utils/adt/int8.c