File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
lib/node_modules/@stdlib/stats/strided/dpcorrwd/src Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 1818
1919#include "stdlib/stats/strided/dpcorrwd.h"
2020#include "stdlib/math/base/special/sqrt.h"
21+ #include "stdlib/math/base/special/clamp.h"
2122#include "stdlib/blas/base/shared.h"
2223#include "stdlib/strided/base/stride2offset.h"
2324
@@ -166,6 +167,7 @@ double API_SUFFIX(stdlib_strided_dpcorrwd_ndarray)( const CBLAS_INT N, const dou
166167 double sy ;
167168 double sx ;
168169 double C ;
170+ double r ;
169171
170172 if ( N <= 0 ) {
171173 return 0.0 / 0.0 ; // NaN
@@ -197,5 +199,6 @@ double API_SUFFIX(stdlib_strided_dpcorrwd_ndarray)( const CBLAS_INT N, const dou
197199 }
198200 sx = stdlib_base_sqrt ( M2x /N );
199201 sy = stdlib_base_sqrt ( M2y /N );
200- return ( C /N ) / ( sx * sy ); // Note: why all the dividing by `N`? To avoid overflow.
202+ r = ( C /N ) / ( sx * sy ); // Why all the dividing by `N`? To avoid overflow.
203+ return stdlib_base_clamp ( r , -1.0 , 1.0 ); // Guard against accumulated floating-point errors resulting in |r| > 1
201204}
You can’t perform that action at this time.
0 commit comments