Skip to content

Commit bbf4fdc

Browse files
author
Neil Conway
committed
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.
1 parent 4893ead commit bbf4fdc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/backend/utils/adt/float.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.150 2007/06/05 21:31:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.151 2007/09/19 22:31:48 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2274,8 +2274,7 @@ float8_corr(PG_FUNCTION_ARGS)
22742274
if (numeratorX <= 0 || numeratorY <= 0)
22752275
PG_RETURN_NULL();
22762276

2277-
PG_RETURN_FLOAT8(sqrt((numeratorXY * numeratorXY) /
2278-
(numeratorX * numeratorY)));
2277+
PG_RETURN_FLOAT8(numeratorXY / sqrt(numeratorX * numeratorY));
22792278
}
22802279

22812280
Datum

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy