Fixed overflow with vector_norm

This commit is contained in:
Andrew Kane
2023-08-09 16:33:54 -07:00
parent 4b887a98ae
commit dab8f25d1c
3 changed files with 10 additions and 3 deletions

View File

@@ -736,13 +736,13 @@ vector_norm(PG_FUNCTION_ARGS)
{
Vector *a = PG_GETARG_VECTOR_P(0);
float *ax = a->x;
float norm = 0.0;
double norm = 0.0;
/* Auto-vectorized */
for (int i = 0; i < a->dim; i++)
norm += ax[i] * ax[i];
norm += (double) ax[i] * (double) ax[i];
PG_RETURN_FLOAT8(sqrt((double) norm));
PG_RETURN_FLOAT8(sqrt(norm));
}
/*