Skip to content

Commit

Permalink
fixup! Clean-up sign-conversion warnings in implementation code
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8000-0000 committed Dec 1, 2019
1 parent fa935f3 commit fdedf0d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#include "format.h"

#include <cassert>
#include <cctype>
#include <cerrno>
Expand All @@ -18,7 +16,9 @@
#include <cstdarg>
#include <cstring> // for std::memmove
#include <cwchar>
#include <memory> // for std::uninitialized_fill_n
#include <memory> // for std::uninitialized_fill_n

#include "format.h"
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
# include <locale>
#endif
Expand Down Expand Up @@ -482,10 +482,10 @@ inline fp operator*(fp x, fp y) { return {multiply(x.f, y.f), x.e + y.e + 64}; }
FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) {
const uint64_t one_over_log2_10 = 0x4d104d42; // round(pow(2, 32) / log2(10))
int index = static_cast<int>(
static_cast<int64_t>(
static_cast<uint64_t>(min_exponent + fp::significand_size - 1) * one_over_log2_10 +
((1ULL << 32) - 1) // ceil
) >>
(static_cast<uint64_t>(min_exponent + fp::significand_size - 1) *
one_over_log2_10 +
((1ULL << 32) - 1) // ceil
) >>
32 // arithmetic shift
);
// Decimal exponent of the first (smallest) cached power of 10.
Expand Down Expand Up @@ -550,8 +550,7 @@ class bigint {
FMT_ASSERT(compare(*this, other) >= 0, "");
bigit borrow = 0;
size_t i = static_cast<size_t>(other.exp_ - exp_);
for (size_t j = 0, n = other.bigits_.size(); j != n;
++i, ++j) {
for (size_t j = 0, n = other.bigits_.size(); j != n; ++i, ++j) {
subtract_bigits(i, other.bigits_[j], borrow);
}
while (borrow > 0) subtract_bigits(i, 0, borrow);
Expand Down Expand Up @@ -641,8 +640,8 @@ class bigint {
size_t i = lhs.bigits_.size();
size_t j = rhs.bigits_.size();
while ((i != 0) && (j != 0)) {
-- i;
-- j;
--i;
--j;
bigit lhs_bigit = lhs.bigits_[i], rhs_bigit = rhs.bigits_[j];
if (lhs_bigit != rhs_bigit) return lhs_bigit > rhs_bigit ? 1 : -1;
}
Expand All @@ -658,7 +657,9 @@ class bigint {
if (max_lhs_bigits + 1 < num_rhs_bigits) return -1;
if (max_lhs_bigits > num_rhs_bigits) return 1;
auto get_bigit = [](const bigint& n, int i) -> bigit {
return i >= n.exp_ && i < n.num_bigits() ? n.bigits_[static_cast<size_t>(i - n.exp_)] : 0;
return i >= n.exp_ && i < n.num_bigits()
? n.bigits_[static_cast<size_t>(i - n.exp_)]
: 0;
};
double_bigit borrow = 0;
int min_exp = (std::min)((std::min)(lhs1.exp_, lhs2.exp_), rhs.exp_);
Expand Down Expand Up @@ -704,7 +705,7 @@ class bigint {
for (size_t bigit_index = 0; bigit_index < num_bigits; ++bigit_index) {
// Compute bigit at position bigit_index of the result by adding
// cross-product terms n[i] * n[j] such that i + j == bigit_index.
for (size_t i = 0; i <= bigit_index; ++ i) {
for (size_t i = 0; i <= bigit_index; ++i) {
// Most terms are multiplied twice which can be optimized in the future.
sum += static_cast<double_bigit>(n[i]) * n[bigit_index - i];
}
Expand Down Expand Up @@ -735,7 +736,8 @@ class bigint {
const auto exp_difference = static_cast<size_t>(exp_ - divisor.exp_);
// Align bigints by adding trailing zeros to simplify subtraction.
bigits_.resize(num_bigits + exp_difference);
std::memmove(&bigits_[exp_difference], &bigits_[0], num_bigits * sizeof(bigits_[0]));
std::memmove(&bigits_[exp_difference], &bigits_[0],
num_bigits * sizeof(bigits_[0]));
std::uninitialized_fill_n(bigits_.data(), exp_difference, 0);
exp_ = divisor.exp_;
}
Expand Down

0 comments on commit fdedf0d

Please sign in to comment.