<html>#222: Dubious code in Hydro_InitExcision.c
<table style='border-spacing: 1ex 0pt; '>
<tr><td style='text-align:right'> Reporter:</td><td>Erik Schnetter</td></tr>
<tr><td style='text-align:right'>   Status:</td><td>resolved</td></tr>
<tr><td style='text-align:right'>Milestone:</td><td></td></tr>
<tr><td style='text-align:right'>  Version:</td><td></td></tr>
<tr><td style='text-align:right'>     Type:</td><td>enhancement</td></tr>
<tr><td style='text-align:right'> Priority:</td><td>minor</td></tr>
<tr><td style='text-align:right'>Component:</td><td>Cactus</td></tr>
</table>

<p>Changes (by Roland Haas):</p>
<p><table>
<tr><td>status:</td><td>resolved (was open)</td></tr>
</table></p>
<p>Hydro_InitExcision.c contains the following code:</p>
<div class="codehilite"><pre><span></span>             if ( (hydro_initexcision_coordinate_length &lt;= 0.0) &amp;&amp;
                  ( ( x_frac &gt; 0.5 - hydro_initexcision_fraction) &amp;&amp;
                    ( x_frac &lt; 0.5 + hydro_initexcision_fraction) &amp;&amp;
                    ( y_frac &gt; 0.5 - hydro_initexcision_fraction) &amp;&amp;
                    ( y_frac &lt; 0.5 + hydro_initexcision_fraction) &amp;&amp;
                    ( z_frac &gt; 0.5 - hydro_initexcision_fraction) &amp;&amp;
                    ( z_frac &lt; 0.5 + hydro_initexcision_fraction)
                  ) ||
                  ( (hydro_initexcision_coordinate_length &gt; 0.0) &amp;&amp;
                    ( fabs(x[point]-hydro_initexcision_position_x) &lt;=
                      hydro_initexcision_coordinate_length*0.5) &amp;&amp;
                    ( fabs(y[point]-hydro_initexcision_position_y) &lt;=
                      hydro_initexcision_coordinate_length*0.5) &amp;&amp;
                    ( fabs(z[point]-hydro_initexcision_position_z) &lt;=
                      hydro_initexcision_coordinate_length*0.5)
                  )
                )
</pre></div>


<p>This code has an "and" (&amp;&amp;) and an "or" (||) operation at top level. Is this intended? The code would be clearer with an additional set of parenthesis, or by introducing a suitable set of temporaries for sub-expressions.</p>
<p><strong>Keyword:</strong></p>
<p>Comment (by Roland Haas):</p>
<p>The parenthesis warnings were addressed in git hash <a data-is-external-link="true" href="https://bitbucket.org/einsteintoolkit/einsteininitialdata/commits/6a53332399865b1532b046b7c9045d057c7b5d2b" rel="nofollow">6a533323</a> "Hydro_InitExcision: place parentheses better (and thus silence compiler warnings)" of <a data-is-external-link="true" href="https://bitbucket.org/einsteintoolkit/einsteininitialdata" rel="nofollow">einsteininitialdata</a> on Thu Nov 15 04:35:46 2012 +0000 and the code compiles without warnings.</p>
<p>The proposed patch contained other changes that are unrelated to this. If desired to have them included, please rebase and re-propose.</p>
<p>--<br/>
Ticket URL: <a href='https://bitbucket.org/einsteintoolkit/tickets/issues/222/dubious-code-in-hydro_initexcisionc'>https://bitbucket.org/einsteintoolkit/tickets/issues/222/dubious-code-in-hydro_initexcisionc</a></p>
</html>