Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing issue 261 #262

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/fast_float/parse_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ from_chars(UC const *first, UC const *last, T &value,
template <typename T, typename UC>
FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
from_chars_advanced(parsed_number_string_t<UC> &pns, T &value) noexcept {

static_assert(is_supported_float_type<T>(),
"only some floating-point types are supported");
static_assert(is_supported_char_type<UC>(),
Expand Down Expand Up @@ -275,11 +274,12 @@ from_chars_advanced(parsed_number_string_t<UC> &pns, T &value) noexcept {
if (am.power2 < 0) {
am = digit_comp<T>(pns, am);
}
to_float(pns.negative, am, value);
// Test for over/underflow.
if ((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) ||
am.power2 == binary_format<T>::infinite_power()) {
answer.ec = std::errc::result_out_of_range;
} else {
to_float(pns.negative, am, value);
}
return answer;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/basictest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ const char *round_name(int d) {
#define FASTFLOAT_STR(x) #x
#define SHOW_DEFINE(x) printf("%s='%s'\n", #x, FASTFLOAT_STR(x))

TEST_CASE("issue261") {
std::string_view str = "5.47382e-48";
float value = 100.0f;
auto res = fast_float::from_chars(str.data(), str.data() + str.size(), value,
fast_float::general);
CHECK_MESSAGE(res.ec == std::errc::result_out_of_range,
"value is out of range (interpretation of the standard)");
std::cout << "value = " << fHexAndDec(value) << std::endl;
CHECK_MESSAGE(value == 100.0f, "value should be unchanged");
CHECK_MESSAGE(res.ptr == str.data() + str.size(),
"should point to end of matching pattern");
}
TEST_CASE("system_info") {
std::cout << "system info:" << std::endl;
#ifdef FASTFLOAT_CONSTEXPR_TESTS
Expand Down
Loading