From d14530f0caec04f495f4cda5922e495f60c2d12f Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Thu, 25 Jul 2013 12:17:08 -0700 Subject: [PATCH] Fix unit conversion of negative Times Thanks to Vedran for finding this. Example: Time tneg = Seconds (-1); NS_LOG_UNCOND ( tneg << ", in s: " << tneg.ToInteger (Time::S)); produces -1000000000.0ns, in s: 18446744072 Correct result is -1000000000.0ns, in s: -1 --- src/core/model/nstime.h | 2 +- src/core/model/time.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/model/nstime.h b/src/core/model/nstime.h index 4a5a672ba..65acd55f2 100644 --- a/src/core/model/nstime.h +++ b/src/core/model/nstime.h @@ -414,7 +414,7 @@ private: { bool toMul; bool fromMul; - uint64_t factor; + int64_t factor; int64x64_t timeTo; int64x64_t timeFrom; }; diff --git a/src/core/model/time.cc b/src/core/model/time.cc index 46cc78d77..9a2420552 100644 --- a/src/core/model/time.cc +++ b/src/core/model/time.cc @@ -108,7 +108,7 @@ Time::SetResolution (enum Unit unit, struct Resolution *resolution) for (int i = 0; i < Time::LAST; i++) { int shift = power[i] - power[(int)unit]; - uint64_t factor = (uint64_t) std::pow (10, std::fabs (shift)); + int64_t factor = (int64_t) std::pow (10, std::fabs (shift)); struct Information *info = &resolution->info[i]; info->factor = factor; if (shift == 0)