From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: victor@magic.io
Subject: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error
Date: Fri, 23 Nov 2018 22:03:56 +0000
Message-ID: <15519-4fc785b483201ff1@postgresql.org> (raw)
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"
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, victor@magic.io
Subject: Re: BUG #15519: Casting float4 into int4 gets the wrong sign instead of "integer out of range" error
In-Reply-To: <15519-4fc785b483201ff1@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox