The function sqrt operates on doubles, which was triggering a -Wfloat-conversion
compiler warning. The float version of this function is sqrtf, but we can
further abbreviate this operation by observing it is computing the hypotenuse of
a right-angled triangle and use the library function for that instead.
for (ij=0; ij<n_terms; ij++) {
float dx = pos[2*terms[ij].i] - pos[2*terms[ij].j];
float dy = pos[2*terms[ij].i+1] - pos[2*terms[ij].j+1];
- float r = sqrt(dx*dx + dy*dy) - terms[ij].d;
+ float r = hypotf(dx, dy) - terms[ij].d;
stress += terms[ij].w * (r * r);
}
return stress;