Mercurial > hg > svcore
diff base/RealTimeSV.cpp @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 48e9f538e6e9 |
children | 71207822a7e0 |
line wrap: on
line diff
--- a/base/RealTimeSV.cpp Mon Dec 12 15:18:52 2016 +0000 +++ b/base/RealTimeSV.cpp Mon Sep 17 13:51:14 2018 +0100 @@ -19,6 +19,7 @@ */ #include <iostream> +#include <limits.h> #include <cstdlib> #include <sstream> @@ -43,16 +44,10 @@ RealTime::RealTime(int s, int n) : sec(s), nsec(n) { - if (sec == 0) { - while (nsec <= -ONE_BILLION) { nsec += ONE_BILLION; --sec; } - while (nsec >= ONE_BILLION) { nsec -= ONE_BILLION; ++sec; } - } else if (sec < 0) { - while (nsec <= -ONE_BILLION) { nsec += ONE_BILLION; --sec; } - while (nsec > 0 && sec < 0) { nsec -= ONE_BILLION; ++sec; } - } else { - while (nsec >= ONE_BILLION) { nsec -= ONE_BILLION; ++sec; } - while (nsec < 0 && sec > 0) { nsec += ONE_BILLION; --sec; } - } + while (nsec <= -ONE_BILLION && sec > INT_MIN) { nsec += ONE_BILLION; --sec; } + while (nsec >= ONE_BILLION && sec < INT_MAX) { nsec -= ONE_BILLION; ++sec; } + while (nsec > 0 && sec < 0) { nsec -= ONE_BILLION; ++sec; } + while (nsec < 0 && sec > 0) { nsec += ONE_BILLION; --sec; } } RealTime @@ -174,9 +169,9 @@ std::ostream &operator<<(std::ostream &out, const RealTime &rt) { if (rt < RealTime::zeroTime) { - out << "-"; + out << "-"; } else { - out << " "; + out << " "; } int s = (rt.sec < 0 ? -rt.sec : rt.sec); @@ -187,8 +182,8 @@ int nn(n); if (nn == 0) out << "00000000"; else while (nn < (ONE_BILLION / 10)) { - out << "0"; - nn *= 10; + out << "0"; + nn *= 10; } out << n << "R"; @@ -319,24 +314,24 @@ int ms = msec(); if (ms != 0) { - out << "."; - out << (ms / 100); - ms = ms % 100; - if (ms != 0) { - out << (ms / 10); - ms = ms % 10; - } else if (fixedDp) { - out << "0"; - } - if (ms != 0) { - out << ms; - } else if (fixedDp) { - out << "0"; - } + out << "."; + out << (ms / 100); + ms = ms % 100; + if (ms != 0) { + out << (ms / 10); + ms = ms % 10; + } else if (fixedDp) { + out << "0"; + } + if (ms != 0) { + out << ms; + } else if (fixedDp) { + out << "0"; + } } else if (fixedDp) { - out << ".000"; + out << ".000"; } - + std::string s = out.str(); return s; @@ -371,7 +366,7 @@ out << d; div /= 10; } - + std::string s = out.str(); // cerr << "converted " << toString() << " to " << s << endl;