aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/utils/adt/float.c44
-rw-r--r--src/backend/utils/adt/int8.c22
-rw-r--r--src/backend/utils/adt/timestamp.c2
3 files changed, 13 insertions, 55 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index 7540ca22efe..f2521999ac0 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -1206,15 +1206,8 @@ dtoi4(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT32_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT32_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float8) PG_INT32_MIN ||
- num >= -((float8) PG_INT32_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT32(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
@@ -1238,15 +1231,8 @@ dtoi2(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT16_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT16_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float8) PG_INT16_MIN ||
- num >= -((float8) PG_INT16_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT16(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
@@ -1294,15 +1280,8 @@ ftoi4(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT32_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT32_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float4) PG_INT32_MIN ||
- num >= -((float4) PG_INT32_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT32(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
@@ -1326,15 +1305,8 @@ ftoi2(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT16_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT16_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float4) PG_INT16_MIN ||
- num >= -((float4) PG_INT16_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT16(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 0ff9394a2fb..93acabce42c 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -1216,15 +1216,8 @@ dtoi8(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT64_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT64_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float8) PG_INT64_MIN ||
- num >= -((float8) PG_INT64_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
@@ -1258,15 +1251,8 @@ ftoi8(PG_FUNCTION_ARGS)
*/
num = rint(num);
- /*
- * Range check. We must be careful here that the boundary values are
- * expressed exactly in the float domain. We expect PG_INT64_MIN to be an
- * exact power of 2, so it will be represented exactly; but PG_INT64_MAX
- * isn't, and might get rounded off, so avoid using it.
- */
- if (unlikely(num < (float4) PG_INT64_MIN ||
- num >= -((float4) PG_INT64_MIN) ||
- isnan(num)))
+ /* Range check */
+ if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 5861ffbbc97..68db766caba 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -3219,7 +3219,7 @@ interval_mul(PG_FUNCTION_ARGS)
/* cascade units down */
result->day += (int32) month_remainder_days;
result_double = rint(span->time * factor + sec_remainder * USECS_PER_SEC);
- if (result_double > PG_INT64_MAX || result_double < PG_INT64_MIN)
+ if (isnan(result_double) || !FLOAT8_FITS_IN_INT64(result_double))
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));