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

Problem when use fast::json::decode with negavite decimal number less than zero #104

Open
blogdarkspot opened this issue Apr 19, 2021 · 0 comments

Comments

@blogdarkspot
Copy link

The code below return a positive number when the value is less then zero, for example -0.2.

std::istream &operator>>(std::istream &strm, decimal_value_storage &storage) {

  int64_t mantissa;
  int16_t exponent = 0;
  if (!(strm >> std::skipws >> mantissa)) {
    return strm;
  }
  // BOOST_THROW_EXCEPTION(json_decode_error(strm, "Expect decimal"));

  std::streambuf *sbuf = strm.rdbuf();

  int c = sbuf->sbumpc();
  if (c == '.') {
    bool negative = false;

    if (mantissa < 0) { //here mantissa value is 0, there isn't negative zero
      negative = true;
      mantissa = -mantissa;
    }
 (...)
  }

This problem occurs because there is not negative zero, so the value -0.2 become 0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant