Skip to content

Commit d377c92

Browse files
committed
minor fixes
1 parent cc90f24 commit d377c92

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

tests/basictest.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,12 +2105,17 @@ void integer_multiplication_by_power_of_10_test(Int mantissa,
21052105
CHECK_EQ(actual, expected);
21062106
}
21072107

2108-
#define verify_integer_multiplication_by_power_of_10(mantissa, \
2109-
decimal_exponent) \
2110-
do { \
2111-
integer_multiplication_by_power_of_10_test(mantissa, decimal_exponent, \
2112-
mantissa##e##decimal_exponent); \
2113-
} while (false)
2108+
template <typename Int>
2109+
void verify_integer_multiplication_by_power_of_10(Int mantissa, int32_t decimal_exponent) {
2110+
std::string constructed_string = std::to_string(mantissa) + "e" + std::to_string(decimal_exponent);
2111+
double expected_result;
2112+
auto result = fast_float::from_chars(constructed_string.data(), constructed_string.data() + constructed_string.size(), expected_result);
2113+
if(result.ec != std::errc()) {
2114+
INFO("Failed to parse: " << constructed_string);
2115+
}
2116+
std::cout << "Testing: " << constructed_string << " -> " << fHexAndDec(expected_result) << "\n";
2117+
integer_multiplication_by_power_of_10_test(mantissa, decimal_exponent, expected_result);
2118+
}
21142119

21152120
TEST_CASE("multiply_integer_and_power_of_10") {
21162121
// explicitly verifying API with different types of integers
@@ -2153,21 +2158,21 @@ TEST_CASE("multiply_integer_and_power_of_10") {
21532158
verify_integer_multiplication_by_power_of_10(1, -1);
21542159
verify_integer_multiplication_by_power_of_10(-1, -1);
21552160

2156-
integer_multiplication_by_power_of_10_test(49406564584124654, -340,
2161+
integer_multiplication_by_power_of_10_test<uint64_t>(49406564584124654, -340,
21572162
DBL_TRUE_MIN);
2158-
integer_multiplication_by_power_of_10_test(22250738585072014, -324,
2163+
integer_multiplication_by_power_of_10_test<uint64_t>(22250738585072014, -324,
21592164
DBL_MIN);
2160-
integer_multiplication_by_power_of_10_test(17976931348623158, 292, DBL_MAX);
2165+
integer_multiplication_by_power_of_10_test<uint64_t>(17976931348623158, 292, DBL_MAX);
21612166

21622167
// DBL_TRUE_MIN / 2 underflows to 0
2163-
integer_multiplication_by_power_of_10_test(49406564584124654 / 2, -340, 0.);
2168+
integer_multiplication_by_power_of_10_test<uint64_t>(49406564584124654 / 2, -340, 0.);
21642169

21652170
// DBL_TRUE_MIN / 2 + 0.0000000000000001e-324 rounds to DBL_TRUE_MIN
2166-
integer_multiplication_by_power_of_10_test(49406564584124654 / 2 + 1, -340,
2171+
integer_multiplication_by_power_of_10_test<uint64_t>(49406564584124654 / 2 + 1, -340,
21672172
DBL_TRUE_MIN);
21682173

21692174
// DBL_MAX + 0.0000000000000001e308 overflows to infinity
2170-
integer_multiplication_by_power_of_10_test(
2175+
integer_multiplication_by_power_of_10_test<uint64_t>(
21712176
17976931348623158 + 1, 292, std::numeric_limits<double>::infinity());
21722177

21732178
// loosely verifying correct rounding of 1 to 64 bits
@@ -2182,17 +2187,19 @@ TEST_CASE("multiply_integer_and_power_of_10") {
21822187
verify_integer_multiplication_by_power_of_10(12345678, 42);
21832188
verify_integer_multiplication_by_power_of_10(123456789, 42);
21842189
verify_integer_multiplication_by_power_of_10(1234567890, 42);
2185-
verify_integer_multiplication_by_power_of_10(12345678901, 42);
2186-
verify_integer_multiplication_by_power_of_10(123456789012, 42);
2187-
verify_integer_multiplication_by_power_of_10(1234567890123, 42);
2188-
verify_integer_multiplication_by_power_of_10(12345678901234, 42);
2189-
verify_integer_multiplication_by_power_of_10(123456789012345, 42);
2190-
verify_integer_multiplication_by_power_of_10(1234567890123456, 42);
2191-
verify_integer_multiplication_by_power_of_10(12345678901234567, 42);
2192-
verify_integer_multiplication_by_power_of_10(123456789012345678, 42);
2193-
verify_integer_multiplication_by_power_of_10(1234567890123456789, 42);
2194-
verify_integer_multiplication_by_power_of_10(12345678901234567890, 42);
2190+
verify_integer_multiplication_by_power_of_10<uint64_t>(12345678901, 42);
2191+
verify_integer_multiplication_by_power_of_10<uint64_t>(123456789012, 42);
2192+
verify_integer_multiplication_by_power_of_10<uint64_t>(1234567890123, 42);
2193+
verify_integer_multiplication_by_power_of_10<uint64_t>(12345678901234, 42);
2194+
verify_integer_multiplication_by_power_of_10<uint64_t>(123456789012345, 42);
2195+
verify_integer_multiplication_by_power_of_10<uint64_t>(1234567890123456, 42);
2196+
verify_integer_multiplication_by_power_of_10<uint64_t>(12345678901234567, 42);
2197+
verify_integer_multiplication_by_power_of_10<uint64_t>(123456789012345678, 42);
2198+
verify_integer_multiplication_by_power_of_10<uint64_t>(1234567890123456789, 42);
2199+
verify_integer_multiplication_by_power_of_10<uint64_t>(12345678901234567890ULL, 42);
21952200
// ULLONG_MAX
2196-
verify_integer_multiplication_by_power_of_10(18446744073709551615, 42);
2201+
verify_integer_multiplication_by_power_of_10<uint64_t>(18446744073709551615ULL, 42);
2202+
verify_integer_multiplication_by_power_of_10<int64_t>(std::numeric_limits<int64_t>::max(), 42);
2203+
verify_integer_multiplication_by_power_of_10<int64_t>(std::numeric_limits<int64_t>::min(), 42);
21972204
}
21982205
}

0 commit comments

Comments
 (0)