Skip to content
Snippets Groups Projects

Avoid casting from double to int

Merged Sergey Kosukhin requested to merge m300488/cray_fix into develop
1 unresolved thread

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

Pipeline #35506 passed

Pipeline passed for 840a37a0 on m300488/cray_fix

Approval is optional

Merged by Sergey KosukhinSergey Kosukhin 1 year ago (May 25, 2023 7:16am UTC)

Merge details

  • Changes merged into with 840a37a0.
  • Deleted the source branch.
  • Auto-merge enabled

Pipeline #35589 passed

Pipeline passed for 840a37a0 on develop

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading