Re: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error

Andrew Gierth <andrew@tao11.riddles.org.uk>

From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: victor@magic.io, pgsql-bugs@lists.postgresql.org
Date: 2018-11-24T00:45:38Z
Lists: pgsql-bugs
>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

 Tom> if (unlikely(num < (float4) INT_MIN || num >= (float4) INT_MAX || isnan(num)))

 >> if (num < (float4)INT_MIN || num >= -(float4)INT_MIN || ...

 Tom> Meh. Seems to me that's relying on pretty much the same
 Tom> assumptions

No, because we know that INT_MIN is always exactly representable as a
float (whereas INT_MAX is not), and therefore the cast result will not
depend on any rounding choices whether at compile or run time. Nor does
it depend on knowing that float4 can't represent INT_MAX exactly.

-- 
Andrew (irc:RhodiumToad)


Commits

  1. Update additional float4/8 expected-output files.

  2. Fix float-to-integer coercions to handle edge cases correctly.

  3. Adjust new test case for more portability.