aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/float.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-02-18 19:23:26 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-02-18 19:23:26 +0000
commit86ffdcad1bfd1a02e58458baf6d0b265f3814121 (patch)
treeb20161914d18cdd2262aa7247efdecf10f9ae325 /src/backend/utils/adt/float.c
parentcdd46c765488a317997c266ba2bdcc85c4a95c8f (diff)
downloadpostgresql-86ffdcad1bfd1a02e58458baf6d0b265f3814121.tar.gz
postgresql-86ffdcad1bfd1a02e58458baf6d0b265f3814121.zip
Remove the special cases to prevent minus-zero results in float4 and float8
unary minus operators. We weren't attempting to prevent minus zero anywhere else; in view of our gradual trend to make the float datatypes more IEEE standard compliant, we should allow minus zero here rather than disallow it elsewhere. We don't, however, expect that all platforms will produce minus zero, so we need to adjust the one affected regression test to allow both results. Per discussion of bug #4660. (In passing, clean up a couple other minor infelicities in float.c.)
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r--src/backend/utils/adt/float.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index f74367d64c4..6ad06788fc4 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.159 2009/01/01 17:23:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.160 2009/02/18 19:23:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -576,9 +576,7 @@ float4um(PG_FUNCTION_ARGS)
float4 arg1 = PG_GETARG_FLOAT4(0);
float4 result;
- result = ((arg1 != 0) ? -(arg1) : arg1);
-
- CHECKFLOATVAL(result, isinf(arg1), true);
+ result = -arg1;
PG_RETURN_FLOAT4(result);
}
@@ -645,9 +643,7 @@ float8um(PG_FUNCTION_ARGS)
float8 arg1 = PG_GETARG_FLOAT8(0);
float8 result;
- result = ((arg1 != 0) ? -(arg1) : arg1);
-
- CHECKFLOATVAL(result, isinf(arg1), true);
+ result = -arg1;
PG_RETURN_FLOAT8(result);
}
@@ -703,16 +699,16 @@ float8smaller(PG_FUNCTION_ARGS)
Datum
float4pl(PG_FUNCTION_ARGS)
{
- float8 arg1 = PG_GETARG_FLOAT4(0);
- float8 arg2 = PG_GETARG_FLOAT4(1);
+ float4 arg1 = PG_GETARG_FLOAT4(0);
+ float4 arg2 = PG_GETARG_FLOAT4(1);
float4 result;
result = arg1 + arg2;
/*
* There isn't any way to check for underflow of addition/subtraction
- * because numbers near the underflow value have been already been to the
- * point where we can't detect the that the two values were originally
+ * because numbers near the underflow value have already been rounded to
+ * the point where we can't detect that the two values were originally
* different, e.g. on x86, '1e-45'::float4 == '2e-45'::float4 ==
* 1.4013e-45.
*/
@@ -757,7 +753,6 @@ float4div(PG_FUNCTION_ARGS)
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
- /* Do division in float8, then check for overflow */
result = arg1 / arg2;
CHECKFLOATVAL(result, isinf(arg1) || isinf(arg2), arg1 == 0);
@@ -2693,7 +2688,7 @@ width_bucket_float8(PG_FUNCTION_ARGS)
errmsg("operand, lower bound and upper bound cannot be NaN")));
/* Note that we allow "operand" to be infinite */
- if (is_infinite(bound1) || is_infinite(bound2))
+ if (isinf(bound1) || isinf(bound2))
ereport(ERROR,
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
errmsg("lower and upper bounds must be finite")));