diff options
author | David Kalnischkies <david@kalnischkies.de> | 2017-12-13 21:51:52 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2017-12-13 23:53:48 +0100 |
commit | 0b5e329a8ba2461ccb7017d3adfc972f9dccd830 (patch) | |
tree | 61fe422eeca8c5bd5cb2de6060f11e71343d4602 /apt-pkg | |
parent | 1adcf56bec7d2127d83aa423916639740fe8e586 (diff) |
deal with floats without old-style cast
We have no speed problem with handling floats/doubles in our progress
handling, but that shouldn't prevent us from cleaning up the handling
slightly to avoid unclean casting to ints.
Reported-By: gcc -Wdouble-promotion -Wold-style-cast
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/acquire.cc | 13 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.cc | 5 | ||||
-rw-r--r-- | apt-pkg/install-progress.cc | 8 |
3 files changed, 14 insertions, 12 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 408cf6df5..f6e323d30 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -31,6 +31,7 @@ #include <sstream> #include <string> #include <vector> +#include <cmath> #include <dirent.h> #include <errno.h> @@ -437,7 +438,7 @@ string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config) clog << "Found " << Instances << " instances of " << U.Access << endl; } - if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10)) + if (Instances >= static_cast<decltype(Instances)>(_config->FindI("Acquire::QueueHost::Limit",10))) return U.Access; return FullQueueName; @@ -1074,7 +1075,7 @@ bool pkgAcquire::Queue::Cycle() // Look for a queable item QItem *I = Items; int ActivePriority = 0; - while (PipeDepth < (signed)MaxPipeDepth) + while (PipeDepth < static_cast<decltype(PipeDepth)>(MaxPipeDepth)) { for (; I != 0; I = I->Next) { if (I->Owner->Status == pkgAcquire::Item::StatFetching) @@ -1285,7 +1286,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) else CurrentCPS = ((CurrentBytes - ResumeSize) - LastBytes)/Delta; LastBytes = CurrentBytes - ResumeSize; - ElapsedTime = (unsigned long long)Delta; + ElapsedTime = std::llround(Delta); Time = NewTime; } @@ -1295,8 +1296,8 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner) Percent = 0; else // use both files and bytes because bytes can be unreliable - Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) + - 0.2 * (CurrentItems/float(TotalItems)*100.0)); + Percent = (0.8 * (CurrentBytes/double(TotalBytes)*100.0) + + 0.2 * (CurrentItems/double(TotalItems)*100.0)); // debug if (_config->FindB("Debug::acquire::progress", false) == true) @@ -1380,7 +1381,7 @@ void pkgAcquireStatus::Stop() else CurrentCPS = FetchedBytes/Delta; LastBytes = CurrentBytes; - ElapsedTime = (unsigned long long)Delta; + ElapsedTime = std::llround(Delta); } /*}}}*/ // AcquireStatus::Fetched - Called when a byte set has been fetched /*{{{*/ diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc index 7c5b15e6b..5499f0946 100644 --- a/apt-pkg/contrib/progress.cc +++ b/apt-pkg/contrib/progress.cc @@ -14,6 +14,7 @@ #include <apt-pkg/error.h> #include <apt-pkg/progress.h> +#include <cmath> #include <cstring> #include <iostream> #include <string> @@ -44,7 +45,7 @@ void OpProgress::Progress(unsigned long long Cur) if (Total == 0 || Size == 0 || SubTotal == 0) Percent = 0; else - Percent = (Current + Cur/((float)SubTotal)*Size)*100.0/Total; + Percent = (Current + Cur/((double)SubTotal)*Size)*100.0/Total; Update(); } /*}}}*/ @@ -106,7 +107,7 @@ bool OpProgress::CheckChange(float Interval) return true; } - if ((int)LastPercent == (int)Percent) + if (std::lround(LastPercent) == std::lround(Percent)) return false; LastPercent = Percent; diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index 2c2205d2b..09bf465bf 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -55,8 +55,8 @@ bool PackageManager::StatusChanged(std::string /*PackageName*/, std::string /*HumanReadableAction*/) { int reporting_steps = _config->FindI("DpkgPM::Reporting-Steps", 1); - percentage = StepsDone/(float)TotalSteps * 100.0; - strprintf(progress_str, _("Progress: [%3i%%]"), (int)percentage); + percentage = StepsDone/(double)TotalSteps * 100.0; + strprintf(progress_str, _("Progress: [%3li%%]"), std::lround(percentage)); if(percentage < (last_reported_progress + reporting_steps)) return false; @@ -382,8 +382,8 @@ bool PackageManagerFancy::DrawStatusLine() if (_config->FindB("Dpkg::Progress-Fancy::Progress-Bar", true)) { int padding = 4; - float progressbar_size = size.columns - padding - progress_str.size(); - float current_percent = percentage / 100.0; + auto const progressbar_size = size.columns - padding - progress_str.size(); + auto const current_percent = percentage / 100.0; std::cout << " " << GetTextProgressStr(current_percent, progressbar_size) << " "; |