mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
Build with pedantic flags under GNU GCC.
This commit is contained in:
parent
7eae925b51
commit
9c5dac3705
@ -108,7 +108,7 @@ adjusted_mantissa compute_float(int64_t q, uint64_t w) noexcept {
|
|||||||
|
|
||||||
answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
|
answer.mantissa = product.high >> (upperbit + 64 - binary::mantissa_explicit_bits() - 3);
|
||||||
|
|
||||||
answer.power2 = power(int(q)) + upperbit - lz - binary::minimum_exponent();
|
answer.power2 = int(power(int(q)) + upperbit - lz - binary::minimum_exponent());
|
||||||
if (answer.power2 <= 0) { // we have a subnormal?
|
if (answer.power2 <= 0) { // we have a subnormal?
|
||||||
// Here have that answer.power2 <= 0 so -answer.power2 >= 0
|
// Here have that answer.power2 <= 0 so -answer.power2 >= 0
|
||||||
if(-answer.power2 + 1 >= 64) { // if we have more than 64 bits below the minimum exponent, you have a zero for sure.
|
if(-answer.power2 + 1 >= 64) { // if we have more than 64 bits below the minimum exponent, you have a zero for sure.
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
function(fast_float_add_cpp_test TEST_NAME)
|
function(fast_float_add_cpp_test TEST_NAME)
|
||||||
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
|
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
|
||||||
add_test(${TEST_NAME} ${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)
|
||||||
|
endif()
|
||||||
target_link_libraries(${TEST_NAME} PUBLIC fast_float)
|
target_link_libraries(${TEST_NAME} PUBLIC fast_float)
|
||||||
endfunction(fast_float_add_cpp_test)
|
endfunction(fast_float_add_cpp_test)
|
||||||
fast_float_add_cpp_test(short_random_string)
|
fast_float_add_cpp_test(short_random_string)
|
||||||
|
|||||||
@ -192,7 +192,6 @@ bool test_scientific_only() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
input = "3.14e10";
|
input = "3.14e10";
|
||||||
result;
|
|
||||||
answer = fast_float::from_chars(input.data(), input.data()+input.size(), result, fast_float::chars_format::scientific);
|
answer = fast_float::from_chars(input.data(), input.data()+input.size(), result, fast_float::chars_format::scientific);
|
||||||
if(answer.ec != std::errc()) {
|
if(answer.ec != std::errc()) {
|
||||||
std::cerr << "It is scientific!\n";
|
std::cerr << "It is scientific!\n";
|
||||||
@ -450,7 +449,7 @@ int main() {
|
|||||||
Assert(basic_test_32bit("0.0015924838953651488",0x1.a175cap-10f));
|
Assert(basic_test_32bit("0.0015924838953651488",0x1.a175cap-10f));
|
||||||
Assert(basic_test_32bit("0.0008602388261351734",0.0008602388261351734f));
|
Assert(basic_test_32bit("0.0008602388261351734",0.0008602388261351734f));
|
||||||
Assert(basic_test_32bit("0.00036393293703440577",0x1.7d9c82p-12f));
|
Assert(basic_test_32bit("0.00036393293703440577",0x1.7d9c82p-12f));
|
||||||
Assert(basic_test_32bit("0.00013746770127909258",0.00013746770127909258));
|
Assert(basic_test_32bit("0.00013746770127909258",0.00013746770127909258f));
|
||||||
Assert(basic_test_32bit("16407.9462890625", 16407.9462890625f));
|
Assert(basic_test_32bit("16407.9462890625", 16407.9462890625f));
|
||||||
Assert(basic_test_32bit("1.1754947011469036e-38", 0x1.000006p-126f));
|
Assert(basic_test_32bit("1.1754947011469036e-38", 0x1.000006p-126f));
|
||||||
Assert(basic_test_32bit("7.0064923216240854e-46", 0x1p-149f));
|
Assert(basic_test_32bit("7.0064923216240854e-46", 0x1p-149f));
|
||||||
@ -458,7 +457,7 @@ int main() {
|
|||||||
Assert(basic_test_32bit("0e9999999999999999999999999999", 0));
|
Assert(basic_test_32bit("0e9999999999999999999999999999", 0));
|
||||||
Assert(basic_test_32bit("1234456789012345678901234567890e9999999999999999999999999999", std::numeric_limits<float>::infinity()));
|
Assert(basic_test_32bit("1234456789012345678901234567890e9999999999999999999999999999", std::numeric_limits<float>::infinity()));
|
||||||
Assert(basic_test_32bit("4.7019774032891500318749461488889827112746622270883500860350068251e-38",4.7019774032891500318749461488889827112746622270883500860350068251e-38f));
|
Assert(basic_test_32bit("4.7019774032891500318749461488889827112746622270883500860350068251e-38",4.7019774032891500318749461488889827112746622270883500860350068251e-38f));
|
||||||
Assert(basic_test_32bit("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679", 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679));
|
Assert(basic_test_32bit("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679", 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679f));
|
||||||
Assert(basic_test_32bit("2.3509887016445750159374730744444913556373311135441750430175034126e-38", 2.3509887016445750159374730744444913556373311135441750430175034126e-38f));
|
Assert(basic_test_32bit("2.3509887016445750159374730744444913556373311135441750430175034126e-38", 2.3509887016445750159374730744444913556373311135441750430175034126e-38f));
|
||||||
Assert(basic_test_32bit("+1", 1));
|
Assert(basic_test_32bit("+1", 1));
|
||||||
Assert(basic_test_32bit("2e3000", std::numeric_limits<float>::infinity()));
|
Assert(basic_test_32bit("2e3000", std::numeric_limits<float>::infinity()));
|
||||||
@ -472,9 +471,9 @@ int main() {
|
|||||||
Assert(basic_test_32bit("3.4028234665e38", 0x1.fffffep+127f));
|
Assert(basic_test_32bit("3.4028234665e38", 0x1.fffffep+127f));
|
||||||
Assert(basic_test_32bit("3.4028234666e38", 0x1.fffffep+127f));
|
Assert(basic_test_32bit("3.4028234666e38", 0x1.fffffep+127f));
|
||||||
Assert(basic_test_32bit("0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625", 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625));
|
Assert(basic_test_32bit("0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625", 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625));
|
||||||
Assert(basic_test_32bit("0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125));
|
Assert(basic_test_32bit("0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125", 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125f));
|
||||||
Assert(basic_test_32bit("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875));
|
Assert(basic_test_32bit("0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875", 0.00000000000000000000000000000000000002350988561514728583455765982071533026645717985517980855365926236850006129930346077117064851336181163787841796875f));
|
||||||
Assert(basic_test_32bit("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875));
|
Assert(basic_test_32bit("0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875", 0.00000000000000000000000000000000000001175494210692441075487029444849287348827052428745893333857174530571588870475618904265502351336181163787841796875f));
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
Assert(powers_of_ten());
|
Assert(powers_of_ten());
|
||||||
|
|||||||
@ -19,7 +19,7 @@ void allvalues() {
|
|||||||
std::cout << ".";
|
std::cout << ".";
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
uint32_t word = w;
|
uint32_t word = uint32_t(w);
|
||||||
memcpy(&v, &word, sizeof(v));
|
memcpy(&v, &word, sizeof(v));
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@ -53,7 +53,7 @@ void allvalues() {
|
|||||||
std::cout << ".";
|
std::cout << ".";
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
uint32_t word = w;
|
uint32_t word = uint32_t(w);
|
||||||
memcpy(&v, &word, sizeof(v));
|
memcpy(&v, &word, sizeof(v));
|
||||||
if(std::isfinite(v)) {
|
if(std::isfinite(v)) {
|
||||||
float nextf = std::nextafterf(v, INFINITY);
|
float nextf = std::nextafterf(v, INFINITY);
|
||||||
@ -64,7 +64,7 @@ void allvalues() {
|
|||||||
double v2{nextf};
|
double v2{nextf};
|
||||||
assert(float(v2) == nextf);
|
assert(float(v2) == nextf);
|
||||||
double midv{v1 + (v2 - v1) / 2};
|
double midv{v1 + (v2 - v1) / 2};
|
||||||
float expected_midv(midv);
|
float expected_midv = float(midv);
|
||||||
|
|
||||||
const char *string_end = to_string(midv, buffer);
|
const char *string_end = to_string(midv, buffer);
|
||||||
float str_answer;
|
float str_answer;
|
||||||
|
|||||||
@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
|
|||||||
class RandomEngine {
|
class RandomEngine {
|
||||||
public:
|
public:
|
||||||
RandomEngine() = delete;
|
RandomEngine() = delete;
|
||||||
RandomEngine(int new_seed) { wyhash64_x_ = new_seed; };
|
RandomEngine(int new_seed) : wyhash64_x_(new_seed) {};
|
||||||
uint64_t next() {
|
uint64_t next() {
|
||||||
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
|
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
|
||||||
// Inspired from
|
// Inspired from
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
/* if (min == max) {
|
/* if (min == max) {
|
||||||
return min;
|
return min;
|
||||||
}*/
|
}*/
|
||||||
int s = max - min + 1;
|
uint64_t s = uint64_t(max - min + 1);
|
||||||
uint64_t x = next();
|
uint64_t x = next();
|
||||||
fast_float::value128 m = fast_float::full_multiplication(x, s);
|
fast_float::value128 m = fast_float::full_multiplication(x, s);
|
||||||
uint64_t l = m.low;
|
uint64_t l = m.low;
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
l = m.low;
|
l = m.low;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (m.high) + min;
|
return int(m.high + min);
|
||||||
}
|
}
|
||||||
int next_digit() { return next_ranged_int(0, 9); }
|
int next_digit() { return next_ranged_int(0, 9); }
|
||||||
|
|
||||||
@ -78,8 +78,8 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
|
|||||||
number_of_digits = rand.next_ranged_int(1, 2000);
|
number_of_digits = rand.next_ranged_int(1, 2000);
|
||||||
}
|
}
|
||||||
int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits);
|
int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits);
|
||||||
for (size_t i = 0; i < number_of_digits; i++) {
|
for (size_t i = 0; i < size_t(number_of_digits); i++) {
|
||||||
if (i == location_of_decimal_separator) {
|
if (i == size_t(location_of_decimal_separator)) {
|
||||||
buffer[pos++] = '.';
|
buffer[pos++] = '.';
|
||||||
}
|
}
|
||||||
buffer[pos++] = char(rand.next_digit() + '0');
|
buffer[pos++] = char(rand.next_digit() + '0');
|
||||||
@ -98,7 +98,7 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
number_of_digits = rand.next_ranged_int(1, 3);
|
number_of_digits = rand.next_ranged_int(1, 3);
|
||||||
for (size_t i = 0; i < number_of_digits; i++) {
|
for (size_t i = 0; i < size_t(number_of_digits); i++) {
|
||||||
buffer[pos++] = char(rand.next_digit() + '0');
|
buffer[pos++] = char(rand.next_digit() + '0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ double cygwin_strtod_l(const char* start, char** end) {
|
|||||||
class RandomEngine {
|
class RandomEngine {
|
||||||
public:
|
public:
|
||||||
RandomEngine() = delete;
|
RandomEngine() = delete;
|
||||||
RandomEngine(int new_seed) { wyhash64_x_ = new_seed; };
|
RandomEngine(int new_seed) : wyhash64_x_(new_seed) { };
|
||||||
uint64_t next() {
|
uint64_t next() {
|
||||||
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
|
// Adapted from https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h
|
||||||
// Inspired from
|
// Inspired from
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
/* if (min == max) {
|
/* if (min == max) {
|
||||||
return min;
|
return min;
|
||||||
}*/
|
}*/
|
||||||
int s = max - min + 1;
|
uint64_t s = uint64_t(max - min + 1);
|
||||||
uint64_t x = next();
|
uint64_t x = next();
|
||||||
fast_float::value128 m = fast_float::full_multiplication(x, s);
|
fast_float::value128 m = fast_float::full_multiplication(x, s);
|
||||||
uint64_t l = m.low;
|
uint64_t l = m.low;
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
l = m.low;
|
l = m.low;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (m.high) + min;
|
return int(m.high + min);
|
||||||
}
|
}
|
||||||
int next_digit() { return next_ranged_int(0, 9); }
|
int next_digit() { return next_ranged_int(0, 9); }
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
|
|||||||
}
|
}
|
||||||
int number_of_digits = rand.next_ranged_int(1, 19);
|
int number_of_digits = rand.next_ranged_int(1, 19);
|
||||||
int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits);
|
int location_of_decimal_separator = rand.next_ranged_int(1, number_of_digits);
|
||||||
for (size_t i = 0; i < number_of_digits; i++) {
|
for (size_t i = 0; i < size_t(number_of_digits); i++) {
|
||||||
if (i == location_of_decimal_separator) {
|
if (i == size_t(location_of_decimal_separator)) {
|
||||||
buffer[pos++] = '.';
|
buffer[pos++] = '.';
|
||||||
}
|
}
|
||||||
buffer[pos++] = char(rand.next_digit() + '0');
|
buffer[pos++] = char(rand.next_digit() + '0');
|
||||||
@ -94,7 +94,7 @@ size_t build_random_string(RandomEngine &rand, char *buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
number_of_digits = rand.next_ranged_int(1, 3);
|
number_of_digits = rand.next_ranged_int(1, 3);
|
||||||
for (size_t i = 0; i < number_of_digits; i++) {
|
for (size_t i = 0; i < size_t(number_of_digits); i++) {
|
||||||
buffer[pos++] = char(rand.next_digit() + '0');
|
buffer[pos++] = char(rand.next_digit() + '0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user