<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 <= 0.0) &&
( ( x_frac > 0.5 - hydro_initexcision_fraction) &&
( x_frac < 0.5 + hydro_initexcision_fraction) &&
( y_frac > 0.5 - hydro_initexcision_fraction) &&
( y_frac < 0.5 + hydro_initexcision_fraction) &&
( z_frac > 0.5 - hydro_initexcision_fraction) &&
( z_frac < 0.5 + hydro_initexcision_fraction)
) ||
( (hydro_initexcision_coordinate_length > 0.0) &&
( fabs(x[point]-hydro_initexcision_position_x) <=
hydro_initexcision_coordinate_length*0.5) &&
( fabs(y[point]-hydro_initexcision_position_y) <=
hydro_initexcision_coordinate_length*0.5) &&
( fabs(z[point]-hydro_initexcision_position_z) <=
hydro_initexcision_coordinate_length*0.5)
)
)
</pre></div>
<p>This code has an "and" (&&) 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>