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

[BUG] String to Double return 0.0 for very large number and vice versa #15508

Closed
thirtiseven opened this issue Apr 11, 2024 · 0 comments · Fixed by #15517
Closed

[BUG] String to Double return 0.0 for very large number and vice versa #15508

thirtiseven opened this issue Apr 11, 2024 · 0 comments · Fixed by #15517
Assignees
Labels
bug Something isn't working

Comments

@thirtiseven
Copy link
Contributor

Describe the bug

cudf::strings::detail::stod returns inf for a number very close to zero, like 9.299999257686047e-0005603333574677677, and returns 0.0 for a very large number, like 9.299999257686047e0005603333574677677.

Steps/Code to reproduce bug

cudf::strings::detail::stod (link) uses int to save exponent value, so it will overflow to a negative sign if input exponent is larger than INT_MAX.
For the above 1st double string, it will overflow from negative value to positive value.
For the above 2nd double string, it will overflow from positive value to negative value.
So it gets wrong results.

  // check for exponent char
  int exp_ten  = 0;
  int exp_sign = 1;
  if (in_ptr < end) {
    char ch = *in_ptr++;
    if (ch == 'e' || ch == 'E') {
      if (in_ptr < end) {
        ch = *in_ptr;
        if (ch == '-' || ch == '+') {
          exp_sign = (ch == '-' ? -1 : 1);
          ++in_ptr;
        }
        while (in_ptr < end) {
          ch = *in_ptr++;
          if (ch < '0' || ch > '9') break;
          exp_ten = (exp_ten * 10) + (int)(ch - '0');  // Overflow here!
        }
      }
    }
  }

Not sure if this is intentional and matches some behavior.

getJsonObject in spark-rapids-jni needs this function to perform floating point number normalization, so we copied this function to spark-rapids-jni and fixed it. But we would like to call it from cuDF in a long term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants