summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINMakrus <markus.hossner@innovative-navigation.de>2016-02-22 23:17:29 +0100
committerINMakrus <markus.hossner@innovative-navigation.de>2016-02-22 23:17:29 +0100
commit53f4a8826c9002a81f8c37acee13778c3f6674d0 (patch)
treefc4e42d7f5ab562738edf4d73d88c889bcb30645
parentfdd3f9a1ad3f1ff3d3e009c0317fa04c1809f9f2 (diff)
downloadATCD-53f4a8826c9002a81f8c37acee13778c3f6674d0.tar.gz
Update Time_Value.inl
- Handle big positiv and negativ double values by limiting them to possible values for sec and usec - Correct round for negativ double values: -10.5 => -10 -500000 (not -10 -499999) - no normalize needed cause result is already normalized
-rw-r--r--ACE/ace/Time_Value.inl20
1 files changed, 16 insertions, 4 deletions
diff --git a/ACE/ace/Time_Value.inl b/ACE/ace/Time_Value.inl
index a4b095033e7..98459b47713 100644
--- a/ACE/ace/Time_Value.inl
+++ b/ACE/ace/Time_Value.inl
@@ -70,10 +70,22 @@ ACE_INLINE void
ACE_Time_Value::set (double d)
{
// ACE_OS_TRACE ("ACE_Time_Value::set");
- time_t l = (time_t) d;
- this->tv_.tv_sec = l;
- this->tv_.tv_usec = (suseconds_t) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS + .5);
- this->normalize ();
+ if (d < ACE_Numeric_Limits<time_t>::min())
+ {
+ this->tv_.tv_sec = ACE_Numeric_Limits<time_t>::min();
+ this->tv_.tv_usec = -ACE_ONE_SECOND_IN_USECS + 1;
+ }
+ else if (d > ACE_Numeric_Limits<time_t>::max())
+ {
+ this->tv_.tv_sec = ACE_Numeric_Limits<time_t>::max();
+ this->tv_.tv_usec = ACE_ONE_SECOND_IN_USECS - 1;
+ }
+ else
+ {
+ time_t l = (time_t) d;
+ this->tv_.tv_sec = l;
+ this->tv_.tv_usec = (suseconds_t) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS + (d < 0 ? -0.5 : 0.5));
+ }
}
/// Initializes a timespec_t. Note that this approach loses precision