aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/numeric.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-07-30 19:48:41 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-07-30 19:48:41 +0000
commit4b1c6695f1dc55301ba17414cc0d00b85e17f7cc (patch)
treef950f2ff5e2d020aa35e0571bea5ef2fb3cf6f80 /src/backend/utils/adt/numeric.c
parent0159f7f2726e6323f2c44a2937b775bc72b2a638 (diff)
downloadpostgresql-4b1c6695f1dc55301ba17414cc0d00b85e17f7cc.tar.gz
postgresql-4b1c6695f1dc55301ba17414cc0d00b85e17f7cc.zip
Fix numeric_smaller, numeric_larger, float4smaller, float4larger,
float8smaller, float8larger (and thereby the MIN/MAX aggregates on these datatypes) to agree with the datatypes' comparison operations as regards NaN handling. In all these datatypes, NaN is arbitrarily considered larger than any normal value ... but MIN/MAX had not gotten the word. Per recent discussion on pgsql-sql.
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r--src/backend/utils/adt/numeric.c62
1 files changed, 12 insertions, 50 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 476d3d5b5ce..4f5029a26c1 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.63 2003/07/27 04:53:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.64 2003/07/30 19:48:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -316,7 +316,7 @@ numeric_in(PG_FUNCTION_ARGS)
/*
* Check for NaN
*/
- if (strcmp(str, "NaN") == 0)
+ if (strcasecmp(str, "NaN") == 0)
PG_RETURN_NUMERIC(make_result(&const_nan));
/*
@@ -1239,34 +1239,15 @@ numeric_smaller(PG_FUNCTION_ARGS)
{
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
- NumericVar arg1;
- NumericVar arg2;
- Numeric res;
-
- /*
- * Handle NaN
- */
- if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
- PG_RETURN_NUMERIC(make_result(&const_nan));
/*
- * Unpack the values, and decide which is the smaller one
+ * Use cmp_numerics so that this will agree with the comparison
+ * operators, particularly as regards comparisons involving NaN.
*/
- init_var(&arg1);
- init_var(&arg2);
-
- set_var_from_num(num1, &arg1);
- set_var_from_num(num2, &arg2);
-
- if (cmp_var(&arg1, &arg2) <= 0)
- res = make_result(&arg1);
+ if (cmp_numerics(num1, num2) < 0)
+ PG_RETURN_NUMERIC(num1);
else
- res = make_result(&arg2);
-
- free_var(&arg1);
- free_var(&arg2);
-
- PG_RETURN_NUMERIC(res);
+ PG_RETURN_NUMERIC(num2);
}
@@ -1280,34 +1261,15 @@ numeric_larger(PG_FUNCTION_ARGS)
{
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
- NumericVar arg1;
- NumericVar arg2;
- Numeric res;
-
- /*
- * Handle NaN
- */
- if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
- PG_RETURN_NUMERIC(make_result(&const_nan));
/*
- * Unpack the values, and decide which is the larger one
+ * Use cmp_numerics so that this will agree with the comparison
+ * operators, particularly as regards comparisons involving NaN.
*/
- init_var(&arg1);
- init_var(&arg2);
-
- set_var_from_num(num1, &arg1);
- set_var_from_num(num2, &arg2);
-
- if (cmp_var(&arg1, &arg2) >= 0)
- res = make_result(&arg1);
+ if (cmp_numerics(num1, num2) > 0)
+ PG_RETURN_NUMERIC(num1);
else
- res = make_result(&arg2);
-
- free_var(&arg1);
- free_var(&arg2);
-
- PG_RETURN_NUMERIC(res);
+ PG_RETURN_NUMERIC(num2);
}