Skip to content

Commit

Permalink
Slightly improve accuracy of stod in to_floats
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwendt committed Apr 8, 2022
1 parent fb03c8b commit 18a565b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cpp/src/strings/convert/convert_floats.cu
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ __device__ inline double stod(string_view const& d_str)
else if (exp_ten < std::numeric_limits<double>::min_exponent10)
return double{0};

exp_ten += 1 - num_digits;
// exp10() is faster than pow(10.0,exp_ten)
double const base =
sign * static_cast<double>(digits) * exp10(static_cast<double>(1 - num_digits));
double const exponent = exp10(static_cast<double>(exp_ten));
return base * exponent;
double const exponent = exp10(static_cast<double>(std::abs(exp_ten)));
double const base = sign * static_cast<double>(digits);
return exp_ten < 0 ? base / exponent : base * exponent;
}

/**
Expand Down

0 comments on commit 18a565b

Please sign in to comment.