]> granicus.if.org Git - graphviz/commitdiff
use floating point math functions to squash a -Wfloat-conversion warning
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 2 May 2021 03:15:30 +0000 (20:15 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 16 May 2021 16:40:28 +0000 (09:40 -0700)
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.

lib/neatogen/sgd.c

index bd7ad613238c7021bd1a0c675e85e8ba23140c68..f6600394260ff2d44e725a70144194458a8486ab 100644 (file)
@@ -13,7 +13,7 @@ static float calculate_stress(float *pos, term_sgd *terms, int n_terms) {
     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;