Sign conversion pedantry.

This commit is contained in:
Daniel Lemire 2020-11-11 20:43:36 -05:00
parent 9c5dac3705
commit 1e92d59997
9 changed files with 18 additions and 18 deletions

View File

@ -71,7 +71,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
// a multiplication by 10 is cheaper than an arbitrary integer
// multiplication
i = 10 * i +
(*p - '0'); // might overflow, we will handle the overflow later
uint64_t(*p - '0'); // might overflow, we will handle the overflow later
++p;
}
int64_t exponent = 0;
@ -236,7 +236,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
}
answer.decimal_point += (neg_exp ? -exp_number : exp_number);
}
answer.decimal_point += answer.num_digits;
answer.decimal_point += int32_t(answer.num_digits);
if(answer.num_digits > max_digits) {
answer.truncated = true;
answer.num_digits = max_digits;

View File

@ -104,7 +104,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
// value128 product = compute_product(q, w);
// but in practice, we can win big with the compute_product_approximation if its additional branch
// is easily predicted. Which is best is data specific.
uint64_t upperbit = product.high >> 63;
int upperbit = int(product.high >> 63);
answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
@ -143,7 +143,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
// answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
// ... we dropped out only zeroes. But if this happened, then we can go back!!!
if((answer.mantissa << (upperbit + 64 - binary::mantissa_explicit_bits() - 3)) == product.high) {
answer.mantissa &= ~1; // flip it so that we do not round up
answer.mantissa &= ~uint64_t(1); // flip it so that we do not round up
}
}

View File

@ -175,7 +175,7 @@ struct decimal {
}
// Generate san exponent matching to_truncated_mantissa()
inline int32_t to_truncated_exponent() {
return decimal_point - max_digit_without_overflow;
return decimal_point - int32_t(max_digit_without_overflow);
}
};

View File

@ -77,7 +77,7 @@ from_chars_result from_chars(const char *first, const char *last,
from_chars_result answer;
while ((first != last) && fast_float::is_space(*first)) {
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
first++;
}
if (first == last) {

View File

@ -4,7 +4,7 @@ function(fast_float_add_cpp_test TEST_NAME)
add_test(${TEST_NAME} ${TEST_NAME})
if(NOT WIN32)
target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++)
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion)
endif()
target_link_libraries(${TEST_NAME} PUBLIC fast_float)
endfunction(fast_float_add_cpp_test)

View File

@ -10,7 +10,7 @@ template <typename T> std::string to_string(T d) {
std::string s(64, '\0');
auto written = std::snprintf(&s[0], s.size(), "%.*e",
std::numeric_limits<T>::max_digits10 - 1, d);
s.resize(written);
s.resize(size_t(written));
return s;
}
@ -18,7 +18,7 @@ template <typename T> std::string to_long_string(T d) {
std::string s(4096, '\0');
auto written = std::snprintf(&s[0], s.size(), "%.*e",
std::numeric_limits<T>::max_digits10 * 10, d);
s.resize(written);
s.resize(size_t(written));
return s;
}
@ -134,7 +134,7 @@ bool issue8() {
auto answer = fast_float::from_chars(s, s + strlen(s) - i, d);
if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return false; }
if(d != 0x1.921fb54442d18p+1) {
printf("%.*s\n", int(strlen(s) - i), s);
printf("%.*s\n", int(strlen(s) - size_t(i)), s);
std::cout << std::hexfloat << d << std::endl;
std::cout << std::defaultfloat << d << std::endl;
return false;
@ -308,7 +308,7 @@ bool test_fixed_only() {
for (int i = start_point; i <= 308; ++i) {// large negative values should be zero.
std::cout << ".";
std::cout.flush();
size_t n = snprintf(buf, sizeof(buf), "1e%d", i);
size_t n = size_t(snprintf(buf, sizeof(buf), "1e%d", i));
if (n >= sizeof(buf)) { abort(); }
double actual;
auto result = fast_float::from_chars(buf, buf + 1000, actual);

View File

@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
class RandomEngine {
public:
RandomEngine() = delete;
RandomEngine(int new_seed) : wyhash64_x_(new_seed) {};
RandomEngine(uint64_t new_seed) : wyhash64_x_(new_seed) {};
uint64_t next() {
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
// Inspired from
@ -59,7 +59,7 @@ public:
l = m.low;
}
}
return int(m.high + min);
return int(m.high) + min;
}
int next_digit() { return next_ranged_int(0, 9); }
@ -146,7 +146,7 @@ std::pair<float, bool> strtof_from_string(char *st) {
* We generate random strings and we try to parse them with both strtod/strtof,
* and we verify that we get the same answer with with fast_float::from_chars.
*/
bool tester(int seed, size_t volume) {
bool tester(uint64_t seed, size_t volume) {
char buffer[4096]; // large buffer (can't overflow)
RandomEngine rand(seed);
for (size_t i = 0; i < volume; i++) {

View File

@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
class RandomEngine {
public:
RandomEngine() = delete;
RandomEngine(int new_seed) : wyhash64_x_(new_seed) { };
RandomEngine(uint64_t new_seed) : wyhash64_x_(new_seed) { };
uint64_t next() {
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
// Inspired from
@ -59,7 +59,7 @@ public:
l = m.low;
}
}
return int(m.high + min);
return int(m.high) + min;
}
int next_digit() { return next_ranged_int(0, 9); }
@ -142,7 +142,7 @@ std::pair<float, bool> strtof_from_string(char *st) {
* We generate random strings and we try to parse them with both strtod/strtof,
* and we verify that we get the same answer with with fast_float::from_chars.
*/
bool tester(int seed, size_t volume) {
bool tester(uint64_t seed, size_t volume) {
char buffer[4096]; // large buffer (can't overflow)
RandomEngine rand(seed);
for (size_t i = 0; i < volume; i++) {

View File

@ -30,7 +30,7 @@ template <typename T> std::string to_string(T d) {
std::string s(64, '\0');
auto written = std::snprintf(&s[0], s.size(), "%.*e",
std::numeric_limits<T>::max_digits10 - 1, d);
s.resize(written);
s.resize(size_t(written));
return s;
}