diff options
author | Neil Conway <neilc@samurai.com> | 2007-09-19 22:31:48 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2007-09-19 22:31:48 +0000 |
commit | bbf4fdc2538097bb3103806e1419ceef1f289203 (patch) | |
tree | a965f57699c4eb681d5c4fad8a09df96b78e18b5 /src/backend/utils/adt/float.c | |
parent | 4893eadc3ce58bb0793bd2cadd2e67f91c126a06 (diff) | |
download | postgresql-bbf4fdc2538097bb3103806e1419ceef1f289203.tar.gz postgresql-bbf4fdc2538097bb3103806e1419ceef1f289203.zip |
Prevent corr() from returning the wrong results for negative correlation
values. The previous coding essentially assumed that x = sqrt(x*x), which
does not hold for x < 0.
Thanks to Jie Zhang at Greenplum and Gavin Sherry for reporting this
issue.
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r-- | src/backend/utils/adt/float.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 7a66bd4c56b..53bfd321d7d 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.150 2007/06/05 21:31:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.151 2007/09/19 22:31:48 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -2274,8 +2274,7 @@ float8_corr(PG_FUNCTION_ARGS) if (numeratorX <= 0 || numeratorY <= 0) PG_RETURN_NULL(); - PG_RETURN_FLOAT8(sqrt((numeratorXY * numeratorXY) / - (numeratorX * numeratorY))); + PG_RETURN_FLOAT8(numeratorXY / sqrt(numeratorX * numeratorY)); } Datum |