summaryrefslogtreecommitdiff
path: root/ACE/ace/Time_Value.cpp
diff options
context:
space:
mode:
authorOssama Othman <ossama-othman@users.noreply.github.com>2007-03-09 09:51:29 +0000
committerOssama Othman <ossama-othman@users.noreply.github.com>2007-03-09 09:51:29 +0000
commit7ac437e9f43b76301cf9223d4aa93f14395314a3 (patch)
tree8e9329c8c16535f4011e8a0413a439cbd4645e97 /ACE/ace/Time_Value.cpp
parentd9b3a24f97097976f7555371f2b2e2cad6bba6a4 (diff)
downloadATCD-7ac437e9f43b76301cf9223d4aa93f14395314a3.tar.gz
ChangeLogTag:Thu Mar 9 09:44:14 UTC 2007 Ossama Othman <ossama_othman at symantec dot com>
Diffstat (limited to 'ACE/ace/Time_Value.cpp')
-rw-r--r--ACE/ace/Time_Value.cpp71
1 files changed, 27 insertions, 44 deletions
diff --git a/ACE/ace/Time_Value.cpp b/ACE/ace/Time_Value.cpp
index c65a2880e7a..52d85c78ae8 100644
--- a/ACE/ace/Time_Value.cpp
+++ b/ACE/ace/Time_Value.cpp
@@ -228,52 +228,35 @@ ACE_Time_Value::operator *= (double d)
double,
long double>::result_type float_type;
- // Handle seconds and microseconds separately, rather than
- // converting microseconds to a fraction of a second and adding that
- // fraction to the floating point equivalent of seconds. This
- // allows for improved precision.
- float_type time_sec = static_cast<float_type> (this->sec ()) * d;
- float_type time_usec = static_cast<float_type> (this->usec ()) * d;
-
- float_type const max_time_t =
- static_cast<float_type> (ACE_Numeric_Limits<time_t>::max ());
- float_type const min_time_t =
- static_cast<float_type> (ACE_Numeric_Limits<time_t>::min ());
-
- // -999999 to 999999 microseconds
- float_type const max_suseconds_t =
- static_cast<float_type> (ACE_Numeric_Limits<suseconds_t>::max ());
- float_type const min_suseconds_t =
- static_cast<float_type> (ACE_Numeric_Limits<suseconds_t>::min ());
-
- // Truncate if necessary.
- if (time_sec > max_time_t)
- time_sec = max_time_t;
- else if (time_sec < min_time_t)
- time_sec = min_time_t;
-
- if (time_usec > max_suseconds_t)
- time_usec = max_suseconds_t;
- else if (time_sec < min_suseconds_t)
- time_usec = min_suseconds_t;
-
- time_t const seconds = static_cast<time_t> (time_sec);
- suseconds_t useconds = static_cast<suseconds_t> (time_usec);
-
- float_type const usec_diff = time_usec - static_cast<float_type> (useconds);
- static float_type const roundup_threshold = 0.5; // Always 0.5.
+ float_type time_total =
+ (this->sec ()
+ + static_cast<float_type> (this->usec ()) / ACE_ONE_SECOND_IN_USECS) * d;
+
+ // shall we saturate the result?
+ static const float_type max_int =
+ ACE_Numeric_Limits<time_t>::max () + 0.999999;
+ static const float_type min_int =
+ ACE_Numeric_Limits<time_t>::min () - 0.999999;
+
+ if (time_total > max_int)
+ time_total = max_int;
+ if (time_total < min_int)
+ time_total = min_int;
+
+ const time_t time_sec = static_cast<time_t> (time_total);
+
+ time_total -= time_sec;
+ time_total *= ACE_ONE_SECOND_IN_USECS;
+
+ suseconds_t time_usec = static_cast<suseconds_t> (time_total);
// round up the result to save the last usec
- if (useconds > 0
- && time_usec < max_suseconds_t
- && usec_diff >= roundup_threshold)
- ++useconds;
- else if (useconds < 0
- && time_usec > min_suseconds_t
- && usec_diff <= -roundup_threshold)
- --useconds;
-
- this->set (seconds, useconds);
+ if (time_usec > 0 && (time_total - time_usec) >= 0.5)
+ ++time_usec;
+ else if (time_usec < 0 && (time_total - time_usec) <= -0.5)
+ --time_usec;
+
+ this->set (time_sec, time_usec);
return *this;
}