/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
char buffer[20];
if (value < 0) {
result->push_back('-');
- result->append(buffer, uint64ToBufferUnsafe(-uint64_t(value), buffer));
+ result->append(
+ buffer,
+ uint64ToBufferUnsafe(~static_cast<uint64_t>(value) + 1, buffer));
} else {
- result->append(buffer, uint64ToBufferUnsafe(value, buffer));
+ result->append(buffer, uint64ToBufferUnsafe(uint64_t(value), buffer));
}
}
conv.ToShortest(value, &builder);
break;
case DoubleToStringConverter::FIXED:
- conv.ToFixed(value, numDigits, &builder);
+ conv.ToFixed(value, int(numDigits), &builder);
break;
default:
CHECK(mode == DoubleToStringConverter::PRECISION);
- conv.ToPrecision(value, numDigits, &builder);
+ conv.ToPrecision(value, int(numDigits), &builder);
break;
}
- const size_t length = builder.position();
+ const size_t length = size_t(builder.position());
builder.Finalize();
result->append(buffer, length);
}
// so 21 is the longest non-exponential number > 1.
detail::kConvMaxDecimalInShortestHigh
});
- return kMaxPositiveSpace + (value < 0); // +1 for minus sign, if negative
+ return size_t(
+ kMaxPositiveSpace +
+ (value < 0 ? 1 : 0)); // +1 for minus sign, if negative
}
/**
namespace detail {
/**
- * Bool to integral doesn't need any special checks, and this
+ * Bool to integral/float doesn't need any special checks, and this
* overload means we aren't trying to see if a bool is less than
* an integer.
*/
template <class Tgt>
typename std::enable_if<
- !std::is_same<Tgt, bool>::value && std::is_integral<Tgt>::value,
+ !std::is_same<Tgt, bool>::value &&
+ (std::is_integral<Tgt>::value || std::is_floating_point<Tgt>::value),
Expected<Tgt, ConversionCode>>::type
convertTo(const bool& value) noexcept {
return static_cast<Tgt>(value ? 1 : 0);
Expected<Tgt, ConversionCode>>::type
convertTo(const Src& value) noexcept {
/* static */ if (
- std::numeric_limits<Tgt>::max() < std::numeric_limits<Src>::max()) {
+ folly::_t<std::make_unsigned<Tgt>>(std::numeric_limits<Tgt>::max()) <
+ folly::_t<std::make_unsigned<Src>>(std::numeric_limits<Src>::max())) {
if (greater_than<Tgt, std::numeric_limits<Tgt>::max()>(value)) {
return makeUnexpected(ConversionCode::ARITH_POSITIVE_OVERFLOW);
}
return makeUnexpected(ConversionCode::ARITH_NEGATIVE_OVERFLOW);
}
}
- return boost::implicit_cast<Tgt>(value);
+ return static_cast<Tgt>(value);
}
/**