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
This commit is contained in:
Peter D. Barnes, Jr.
2013-07-25 12:17:08 -07:00
parent 0ae8b1cb8d
commit d14530f0ca
2 changed files with 2 additions and 2 deletions

View File

@@ -414,7 +414,7 @@ private:
{
bool toMul;
bool fromMul;
uint64_t factor;
int64_t factor;
int64x64_t timeTo;
int64x64_t timeFrom;
};

View File

@@ -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)