diff options
author | Neil Conway <neilc@samurai.com> | 2004-05-16 23:18:55 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2004-05-16 23:18:55 +0000 |
commit | 2871f60f232a5a5b496f3d75156bfeb679c3d161 (patch) | |
tree | ec553ac498df2de5313f5775d34f0e627eee118a /src/backend/utils/adt/float.c | |
parent | 335cf9ae7f2c10d8ce77247fd8c2f9cd123f1f16 (diff) | |
download | postgresql-2871f60f232a5a5b496f3d75156bfeb679c3d161.tar.gz postgresql-2871f60f232a5a5b496f3d75156bfeb679c3d161.zip |
Change ln(), log(), power(), and sqrt() to emit the correct SQLSTATE
error codes for certain error conditions, as specified by SQL2003.
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r-- | src/backend/utils/adt/float.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index c48af109e3e..bef89f38c70 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.104 2004/05/07 00:24:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.105 2004/05/16 23:18:55 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -1415,7 +1415,7 @@ dsqrt(PG_FUNCTION_ARGS) if (arg1 < 0) ereport(ERROR, - (errcode(ERRCODE_FLOATING_POINT_EXCEPTION), + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION), errmsg("cannot take square root of a negative number"))); result = sqrt(arg1); @@ -1450,6 +1450,16 @@ dpow(PG_FUNCTION_ARGS) float8 result; /* + * The SQL spec requires that we emit a particular SQLSTATE error + * code for certain error conditions. + */ + if ((arg1 == 0 && arg2 < 0) || + (arg1 < 0 && floor(arg2) != arg2)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION), + errmsg("invalid argument for power function"))); + + /* * We must check both for errno getting set and for a NaN result, in * order to deal with the vagaries of different platforms... */ @@ -1501,7 +1511,6 @@ dexp(PG_FUNCTION_ARGS) /* * dlog1 - returns the natural logarithm of arg1 - * ("dlog" is already a logging routine...) */ Datum dlog1(PG_FUNCTION_ARGS) @@ -1509,14 +1518,17 @@ dlog1(PG_FUNCTION_ARGS) float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; + /* + * Emit particular SQLSTATE error codes for ln(). This is required + * by the SQL standard. + */ if (arg1 == 0.0) ereport(ERROR, - (errcode(ERRCODE_FLOATING_POINT_EXCEPTION), + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of zero"))); - if (arg1 < 0) ereport(ERROR, - (errcode(ERRCODE_FLOATING_POINT_EXCEPTION), + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of a negative number"))); result = log(arg1); @@ -1535,14 +1547,19 @@ dlog10(PG_FUNCTION_ARGS) float8 arg1 = PG_GETARG_FLOAT8(0); float8 result; + /* + * Emit particular SQLSTATE error codes for log(). The SQL spec + * doesn't define log(), but it does define ln(), so it makes + * sense to emit the same error code for an analogous error + * condition. + */ if (arg1 == 0.0) ereport(ERROR, - (errcode(ERRCODE_FLOATING_POINT_EXCEPTION), + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of zero"))); - if (arg1 < 0) ereport(ERROR, - (errcode(ERRCODE_FLOATING_POINT_EXCEPTION), + (errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG), errmsg("cannot take logarithm of a negative number"))); result = log10(arg1); |