summaryrefslogtreecommitdiff
path: root/src/tool_util.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-11-25 13:51:55 +0100
committerYang Tse <yangsita@gmail.com>2011-11-25 13:51:55 +0100
commit97d7a9260e4f2f335b3632180877c25e0efdc8e3 (patch)
tree41e91cd18bb9bb781a209a7a7edefde116a09528 /src/tool_util.c
parent4a4d04446da7b11c7c360d18bfd115a573001cde (diff)
downloadcurl-97d7a9260e4f2f335b3632180877c25e0efdc8e3.tar.gz
tvdiff_secs(): sub-zero time difference adjustment
Skip a floating point addition operation when integral part of time difference is zero. This avoids potential floating point addition rounding problems while preserving decimal part value.
Diffstat (limited to 'src/tool_util.c')
-rw-r--r--src/tool_util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tool_util.c b/src/tool_util.c
index 79c998295..93ab17fd4 100644
--- a/src/tool_util.c
+++ b/src/tool_util.c
@@ -123,8 +123,11 @@ long tool_tvdiff(struct timeval newer, struct timeval older)
*/
double tool_tvdiff_secs(struct timeval newer, struct timeval older)
{
- return (double)(newer.tv_sec-older.tv_sec)+
- (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+ if(newer.tv_sec != older.tv_sec)
+ return (double)(newer.tv_sec-older.tv_sec)+
+ (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+ else
+ return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
}
/* return the number of seconds in the given input timeval struct */