<div dir="ltr"><br clear="all"><div><div>Hi all,</div><div><br></div><div>I've been thinking about what is possible with the Proj code base with an assumption that the code must be C89/C90 compatible. I played around for a few in godbolt with PJ_august.c (because it's small) and ended up with this. I tried to be aggressive as I could. I think my modified version is likely to be more static analyzer friendly. What do you all think? For each of the change, is it better or worse for Proj as a whole? My brain is set to C++14/17, so I have a hard time evaluating this in context of what's best for Proj in the long run.</div><div><br></div><div>Original: <a href="https://godbolt.org/g/ci5Wfo">https://godbolt.org/g/ci5Wfo</a></div><div>Modified: <a href="https://godbolt.org/g/mz6NjD">https://godbolt.org/g/mz6NjD</a></div><div><br></div><div>Things I did:</div><div>- Combine definition and declaration</div><div>- Add const</div><div>- For double literals, have at least one digit before and after decimal point. e.g. .1 -> 0.1 and 3. -> 3.0</div><div>- Don't have assignments hidden inside expressions</div><div>- Convert #defines to typed const values</div><div>- IWYU - Include what you use... here math.h</div><div><br></div><div>Cheers,</div><div>-kurt</div><div><br></div><div>#include <math.h></div><div><br></div><div>typedef struct { double x, y; } XY;</div><div>typedef struct { double lam, phi; } LP;</div><div>typedef struct PJconsts PJ;</div><div>XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */</div><div><span style="white-space:pre">        </span>(void) P;</div><div><span style="white-space:pre">        </span>const double t = tan(0.5 * lp.phi);</div><div><span style="white-space:pre">        </span>const double c1 = sqrt(1.0 - t * t);</div><div><span style="white-space:pre">        </span>const double c = 1.0 + c1 * cos(lp.lam *= .5);</div><div><span style="white-space:pre">        </span>const double x1 = sin(lp.lam) * c1 / c;</div><div><span style="white-space:pre">        </span>const double y1 = t / c;</div><div> const double x12 = x1 * x1;</div><div> const double y12 = y1 * y1;</div><div> const double M = 1.333333333333333;</div><div> const XY xy = {</div><div> M * x1 * (3.0 + x12 - 3.0 * y12),</div><div> M * y1 * (3.0 + 3.0 * x12 - y12)};</div><div><span style="white-space:pre">        </span>return xy;</div><div>}</div></div><div><br></div><div>Screenshot: <a href="https://www.flickr.com/photos/schwehr/39802222790">https://www.flickr.com/photos/schwehr/39802222790</a></div><div class="gmail_signature"></div>
</div>