Skip to content

Avoid casting from double to int

Sergey Kosukhin requested to merge m300488/cray_fix into develop

The current logic of converting a double argument to the CdiTime structure relies on the explicit casting from double to int. Although the truncated value of the double is always supposed to be representable as int in this particular case and we should not enter the undefined behaviour area, we seem to be pretty close to it. In fact, the optimized (even with -O1) code generated by the Cray compiler (versions 12.0.3, 13.0.1 and 14.0.0 are known to be affected) raises the floating point exception (it looks like the register that is used as a buffer for the conversion is not cleaned up properly in advance but I'm not 100% about that).

The first working solution that I had in mind and that solved the problem with the Cray compiler was to do an intermediate cast from double to long. However, I don't have any strong arguments for why casting to long should be better than casting to int in this context. So, the solution implemented in this MR is to get rid of any casting at all (at least in our code) and rely on the standard functions instead.

I know I should have created a separate MR for that but I also put a commit that cleans the Makefile.am a little bit.

Merge request reports