mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 19:30:13 -06:00
cmCTestRunTest: Avoid float/int conversions in number width logic
Use of `std::log10` added by commit 02c5091c90 (cmCTestRunTest: Simplify
number width computation, 2018-09-08) broke our number width computation
on some platforms where
static_cast<int>(std::log10(static_cast<size_t>(10)))
somehow produces `0` instead of `1`. Re-implement the logic to avoid
floating-point computations.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
@@ -122,7 +121,12 @@ private:
|
||||
|
||||
inline int getNumWidth(size_t n)
|
||||
{
|
||||
return static_cast<int>(std::log10(n)) + 1;
|
||||
int w = 1;
|
||||
while (n >= 10) {
|
||||
n /= 10;
|
||||
++w;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user