Skip to content

Commit

Permalink
Use AtofPrecise in Common::__StringToTHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Mar 29, 2021
1 parent ba8e4aa commit 498090d
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions include/LightGBM/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,22 +1100,8 @@ struct __StringToTHelper<T, true> {
T operator()(const std::string& str) const {
double tmp;

// Fast (common) path: For numeric inputs in RFC 7159 format:
const bool fast_parse_succeeded = fast_double_parser::parse_number(str.c_str(), &tmp);

// Rare path: Not in RFC 7159 format. Possible "inf", "nan", etc.
if (!fast_parse_succeeded) {
std::string strlower(str);
std::transform(strlower.begin(), strlower.end(), strlower.begin(), [](int c) -> char { return static_cast<char>(::tolower(c)); });
if (strlower == std::string("inf"))
tmp = std::numeric_limits<double>::infinity();
else if (strlower == std::string("-inf"))
tmp = -std::numeric_limits<double>::infinity();
else if (strlower == std::string("nan"))
tmp = std::numeric_limits<double>::quiet_NaN();
else if (strlower == std::string("-nan"))
tmp = -std::numeric_limits<double>::quiet_NaN();
else
const char* end = Common::AtofPrecise(str.c_str(), &tmp);
if (end == str.c_str()) {
Log::Fatal("Failed to parse double: %s", str.c_str());
}

Expand Down

0 comments on commit 498090d

Please sign in to comment.