From: Matthew Fernandez Date: Wed, 26 May 2021 15:12:03 +0000 (-0700) Subject: rephrase some magic numbers in Smyrna into their originating computation X-Git-Tag: 2.47.3~24^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0caa33790c8140b66ac4fbe27701f3c6b984dc83;p=graphviz rephrase some magic numbers in Smyrna into their originating computation This removes the use of some double literals with implicit conversion to floats, squashing some -Wfloat-conversion compiler warnings. It also makes the resulting code clearer. The compiler constant-folds these at -O1 and above, so there is no loss of performance. The resulting expressions are slightly different to the original, but if anything they are a more accurate representation of the intent here. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 649219744..a62750f33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- marginally more accurate computations in Smyrna sphere projection + ## [2.47.2] - 2021-05-26 ### Added diff --git a/cmd/smyrna/trackball.c b/cmd/smyrna/trackball.c index a49ad5cce..041f1165c 100644 --- a/cmd/smyrna/trackball.c +++ b/cmd/smyrna/trackball.c @@ -208,10 +208,10 @@ static float tb_project_to_sphere(float r, float x, float y) float d, t, z; d = hypotf(x, y); - if (d < r * 0.70710678118654752440) { /* Inside sphere */ + if (d < r * (1.0f / sqrtf(2.0f))) { /* Inside sphere */ z = sqrt(r * r - d * d); } else { /* On hyperbola */ - t = r / 1.41421356237309504880; + t = r / sqrtf(2.0f); z = t * t / d; } return z;