Skip to content

Commit 1e92d59

Browse files
committed
Sign conversion pedantry.
1 parent 9c5dac3 commit 1e92d59

9 files changed

Lines changed: 18 additions & 18 deletions

File tree

include/fast_float/ascii_number.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
7171
// a multiplication by 10 is cheaper than an arbitrary integer
7272
// multiplication
7373
i = 10 * i +
74-
(*p - '0'); // might overflow, we will handle the overflow later
74+
uint64_t(*p - '0'); // might overflow, we will handle the overflow later
7575
++p;
7676
}
7777
int64_t exponent = 0;
@@ -236,7 +236,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
236236
}
237237
answer.decimal_point += (neg_exp ? -exp_number : exp_number);
238238
}
239-
answer.decimal_point += answer.num_digits;
239+
answer.decimal_point += int32_t(answer.num_digits);
240240
if(answer.num_digits > max_digits) {
241241
answer.truncated = true;
242242
answer.num_digits = max_digits;

include/fast_float/decimal_to_binary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
104104
// value128 product = compute_product(q, w);
105105
// but in practice, we can win big with the compute_product_approximation if its additional branch
106106
// is easily predicted. Which is best is data specific.
107-
uint64_t upperbit = product.high >> 63;
107+
int upperbit = int(product.high >> 63);
108108

109109
answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
110110

@@ -143,7 +143,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
143143
// answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
144144
// ... we dropped out only zeroes. But if this happened, then we can go back!!!
145145
if((answer.mantissa << (upperbit + 64 - binary::mantissa_explicit_bits() - 3)) == product.high) {
146-
answer.mantissa &= ~1; // flip it so that we do not round up
146+
answer.mantissa &= ~uint64_t(1); // flip it so that we do not round up
147147
}
148148
}
149149

include/fast_float/float_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct decimal {
175175
}
176176
// Generate san exponent matching to_truncated_mantissa()
177177
inline int32_t to_truncated_exponent() {
178-
return decimal_point - max_digit_without_overflow;
178+
return decimal_point - int32_t(max_digit_without_overflow);
179179
}
180180
};
181181

include/fast_float/parse_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ from_chars_result from_chars(const char *first, const char *last,
7777

7878

7979
from_chars_result answer;
80-
while ((first != last) && fast_float::is_space(*first)) {
80+
while ((first != last) && fast_float::is_space(uint8_t(*first))) {
8181
first++;
8282
}
8383
if (first == last) {

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function(fast_float_add_cpp_test TEST_NAME)
44
add_test(${TEST_NAME} ${TEST_NAME})
55
if(NOT WIN32)
66
target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++)
7-
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
7+
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion)
88
endif()
99
target_link_libraries(${TEST_NAME} PUBLIC fast_float)
1010
endfunction(fast_float_add_cpp_test)

tests/basictest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ template <typename T> std::string to_string(T d) {
1010
std::string s(64, '\0');
1111
auto written = std::snprintf(&s[0], s.size(), "%.*e",
1212
std::numeric_limits<T>::max_digits10 - 1, d);
13-
s.resize(written);
13+
s.resize(size_t(written));
1414
return s;
1515
}
1616

1717
template <typename T> std::string to_long_string(T d) {
1818
std::string s(4096, '\0');
1919
auto written = std::snprintf(&s[0], s.size(), "%.*e",
2020
std::numeric_limits<T>::max_digits10 * 10, d);
21-
s.resize(written);
21+
s.resize(size_t(written));
2222
return s;
2323
}
2424

@@ -134,7 +134,7 @@ bool issue8() {
134134
auto answer = fast_float::from_chars(s, s + strlen(s) - i, d);
135135
if(answer.ec != std::errc()) { std::cerr << "parsing failure\n"; return false; }
136136
if(d != 0x1.921fb54442d18p+1) {
137-
printf("%.*s\n", int(strlen(s) - i), s);
137+
printf("%.*s\n", int(strlen(s) - size_t(i)), s);
138138
std::cout << std::hexfloat << d << std::endl;
139139
std::cout << std::defaultfloat << d << std::endl;
140140
return false;
@@ -308,7 +308,7 @@ bool test_fixed_only() {
308308
for (int i = start_point; i <= 308; ++i) {// large negative values should be zero.
309309
std::cout << ".";
310310
std::cout.flush();
311-
size_t n = snprintf(buf, sizeof(buf), "1e%d", i);
311+
size_t n = size_t(snprintf(buf, sizeof(buf), "1e%d", i));
312312
if (n >= sizeof(buf)) { abort(); }
313313
double actual;
314314
auto result = fast_float::from_chars(buf, buf + 1000, actual);

tests/random_string.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
2424
class RandomEngine {
2525
public:
2626
RandomEngine() = delete;
27-
RandomEngine(int new_seed) : wyhash64_x_(new_seed) {};
27+
RandomEngine(uint64_t new_seed) : wyhash64_x_(new_seed) {};
2828
uint64_t next() {
2929
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
3030
// Inspired from
@@ -59,7 +59,7 @@ class RandomEngine {
5959
l = m.low;
6060
}
6161
}
62-
return int(m.high + min);
62+
return int(m.high) + min;
6363
}
6464
int next_digit() { return next_ranged_int(0, 9); }
6565

@@ -146,7 +146,7 @@ std::pair<float, bool> strtof_from_string(char *st) {
146146
* We generate random strings and we try to parse them with both strtod/strtof,
147147
* and we verify that we get the same answer with with fast_float::from_chars.
148148
*/
149-
bool tester(int seed, size_t volume) {
149+
bool tester(uint64_t seed, size_t volume) {
150150
char buffer[4096]; // large buffer (can't overflow)
151151
RandomEngine rand(seed);
152152
for (size_t i = 0; i < volume; i++) {

tests/short_random_string.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
2424
class RandomEngine {
2525
public:
2626
RandomEngine() = delete;
27-
RandomEngine(int new_seed) : wyhash64_x_(new_seed) { };
27+
RandomEngine(uint64_t new_seed) : wyhash64_x_(new_seed) { };
2828
uint64_t next() {
2929
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
3030
// Inspired from
@@ -59,7 +59,7 @@ class RandomEngine {
5959
l = m.low;
6060
}
6161
}
62-
return int(m.high + min);
62+
return int(m.high) + min;
6363
}
6464
int next_digit() { return next_ranged_int(0, 9); }
6565

@@ -142,7 +142,7 @@ std::pair<float, bool> strtof_from_string(char *st) {
142142
* We generate random strings and we try to parse them with both strtod/strtof,
143143
* and we verify that we get the same answer with with fast_float::from_chars.
144144
*/
145-
bool tester(int seed, size_t volume) {
145+
bool tester(uint64_t seed, size_t volume) {
146146
char buffer[4096]; // large buffer (can't overflow)
147147
RandomEngine rand(seed);
148148
for (size_t i = 0; i < volume; i++) {

tests/string_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ template <typename T> std::string to_string(T d) {
3030
std::string s(64, '\0');
3131
auto written = std::snprintf(&s[0], s.size(), "%.*e",
3232
std::numeric_limits<T>::max_digits10 - 1, d);
33-
s.resize(written);
33+
s.resize(size_t(written));
3434
return s;
3535
}
3636

0 commit comments

Comments
 (0)