mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
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.
This commit is contained in:
parent
eb4f4f5b7c
commit
d5e6f4f828
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.130 2006/10/05 01:40:45 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.130.2.1 2007/09/19 22:31:51 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2469,8 +2469,7 @@ float8_corr(PG_FUNCTION_ARGS)
|
|||||||
if (numeratorX <= 0 || numeratorY <= 0)
|
if (numeratorX <= 0 || numeratorY <= 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
PG_RETURN_FLOAT8(sqrt((numeratorXY * numeratorXY) /
|
PG_RETURN_FLOAT8(numeratorXY / sqrt(numeratorX * numeratorY));
|
||||||
(numeratorX * numeratorY)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
|
Loading…
Reference in New Issue
Block a user