BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error
The Post Office <noreply@postgresql.org>
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: victor@magic.io
Date: 2018-11-23T22:03:56Z
Lists: pgsql-bugs
The following bug has been logged on the website: Bug reference: 15519 Logged by: Victor Petrovykh Email address: victor@magic.io PostgreSQL version: 10.5 Operating system: Gentoo Linux 4.14.20 Description: Offending examples: SELECT ((2147483647::float4) - 1.0::float4)::int4; SELECT ((2147483590::float4) - 1.0::float4)::int4; SELECT ((2147483647::float4) + 1.0::float4)::int4; They all produce the same result: -2147483648 I understand that a float4 cannot represent large integers with the same precision as int4, that's OK. What surprised me is that instead of getting an "overflow error" or "integer out of range" I simply got a negative result for a value that is actually close to maximum int4. To contrast this, the query: SELECT ((2147483647::float4) + 200.0::float4)::int4; The above produces the expected "ERROR: integer out of range"
Commits
-
Update additional float4/8 expected-output files.
- bf9fb00dd107 9.4.21 landed
- 74587148314a 10.7 landed
- 3645d31934f4 11.2 landed
- 298510caee63 9.5.16 landed
- 1f99d0867020 9.6.12 landed
-
Fix float-to-integer coercions to handle edge cases correctly.
- d5231253e309 9.4.21 landed
- 93eec1238663 9.6.12 landed
- 1e78603a54a7 9.5.16 landed
- e473e1f2b8f1 11.2 landed
- c382a2b66909 10.7 landed
- cbdb8b4c0155 12.0 landed
-
Adjust new test case for more portability.
- 452b637d4b02 12.0 landed