Skip to content

Commit

Permalink
Fix sign-conversion warnings reported by Clang7
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8000-0000 authored and vitaut committed Dec 4, 2018
1 parent ea5e479 commit 77656c6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ FMT_FUNC fp get_cached_power(int min_exponent, int &pow10_exponent) {
}

FMT_FUNC bool grisu2_round(
char *buf, size_t &size, size_t max_digits, uint64_t delta,
char *buf, ptrdiff_t &size, size_t max_digits, uint64_t delta,
uint64_t remainder, uint64_t exp, uint64_t diff, int &exp10) {
while (remainder < diff && delta - remainder >= exp &&
(remainder + exp < diff || diff - remainder > remainder + exp - diff)) {
--buf[size - 1];
remainder += exp;
}
if (size > max_digits) {
if (size > static_cast<ptrdiff_t>(max_digits)) {
--size;
++exp10;
if (buf[size] >= '5')
Expand All @@ -482,7 +482,7 @@ FMT_FUNC bool grisu2_round(

// Generates output using Grisu2 digit-gen algorithm.
FMT_FUNC bool grisu2_gen_digits(
char *buf, size_t &size, uint32_t hi, uint64_t lo, int &exp,
char *buf, ptrdiff_t &size, uint32_t hi, uint64_t lo, int &exp,
uint64_t delta, const fp &one, const fp &diff, size_t max_digits) {
// Generate digits for the most significant part (hi).
while (exp > 0) {
Expand All @@ -507,7 +507,7 @@ FMT_FUNC bool grisu2_gen_digits(
buf[size++] = static_cast<char>('0' + digit);
--exp;
uint64_t remainder = (static_cast<uint64_t>(hi) << -one.e) + lo;
if (remainder <= delta || size > max_digits) {
if (remainder <= delta || size > static_cast<ptrdiff_t>(max_digits)) {
return grisu2_round(
buf, size, max_digits, delta, remainder,
static_cast<uint64_t>(data::POWERS_OF_10_32[exp]) << -one.e,
Expand All @@ -523,7 +523,7 @@ FMT_FUNC bool grisu2_gen_digits(
buf[size++] = static_cast<char>('0' + digit);
lo &= one.f - 1;
--exp;
if (lo < delta || size > max_digits) {
if (lo < delta || size > static_cast<ptrdiff_t>(max_digits)) {
return grisu2_round(buf, size, max_digits, delta, lo, one.f,
diff.f * data::POWERS_OF_10_32[-exp], exp);
}
Expand Down Expand Up @@ -751,7 +751,7 @@ FMT_FUNC typename std::enable_if<sizeof(Double) == sizeof(uint64_t), bool>::type
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
// lo = supper % one.
uint64_t lo = upper.f & (one.f - 1);
size_t size = 0;
ptrdiff_t size = 0;
if (!grisu2_gen_digits(buf.data(), size, hi, lo, exp, delta, one, diff,
params.num_digits)) {
buf.clear();
Expand Down

0 comments on commit 77656c6

Please sign in to comment.