#222: Dubious code in Hydro_InitExcision.c
Reporter:Erik Schnetter
Status:resolved
Milestone:
Version:
Type:enhancement
Priority:minor
Component:Cactus

Changes (by Roland Haas):

status:resolved (was open)

Hydro_InitExcision.c contains the following code:

             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)
                  )
                )

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.

Keyword:

Comment (by Roland Haas):

The parenthesis warnings were addressed in git hash 6a533323 "Hydro_InitExcision: place parentheses better (and thus silence compiler warnings)" of einsteininitialdata on Thu Nov 15 04:35:46 2012 +0000 and the code compiles without warnings.

The proposed patch contained other changes that are unrelated to this. If desired to have them included, please rebase and re-propose.

--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/222/dubious-code-in-hydro_initexcisionc