[Dart-dev] [6904] DART/trunk/time_manager/time_manager_mod.f90: add an extra set of parens around an integer expression of
nancy at ucar.edu
nancy at ucar.edu
Mon Apr 21 10:09:35 MDT 2014
Revision: 6904
Author: nancy
Date: 2014-04-21 10:09:35 -0600 (Mon, 21 Apr 2014)
Log Message:
-----------
add an extra set of parens around an integer expression of
the form: a / b * b which has always been evaluated
(a / b) * b as expected, doing integer math roundoff.
however, on one recent compiler apparently evaluated it
as a / (b * b), possibly because b is a constant and
more aggressive optimization could evaluate it early.
the result here was always 0 instead of the expected
roundoff expression.
Modified Paths:
--------------
DART/trunk/time_manager/time_manager_mod.f90
-------------- next part --------------
Modified: DART/trunk/time_manager/time_manager_mod.f90
===================================================================
--- DART/trunk/time_manager/time_manager_mod.f90 2014-04-18 20:17:38 UTC (rev 6903)
+++ DART/trunk/time_manager/time_manager_mod.f90 2014-04-21 16:09:35 UTC (rev 6904)
@@ -169,9 +169,12 @@
if(seconds < 0 .or. days_in < 0) &
call error_handler(E_ERR,'set_time',errstring,source,revision,revdate)
-! Make sure seconds greater than a day are fixed up
+! Make sure seconds greater than a day are fixed up.
+! Extra parens to force the divide before the multiply are REQUIRED
+! on some compilers to prevent them from combining constants first
+! which makes the expression always return 0.
-set_time%seconds = seconds - seconds / (60*60*24) * (60*60*24)
+set_time%seconds = seconds - (seconds / (60*60*24)) * (60*60*24)
! Check for overflow on days before doing operation
More information about the Dart-dev
mailing list