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

Math operations for int values fail for big values #4132

Closed
harshil-goel opened this issue Oct 7, 2019 · 1 comment · Fixed by #4257
Closed

Math operations for int values fail for big values #4132

harshil-goel opened this issue Oct 7, 2019 · 1 comment · Fixed by #4257
Assignees
Labels
area/querylang Issues related to the query language specification and implementation. kind/bug Something is broken. priority/P0 Critical issue that requires immediate attention. status/accepted We accept to investigate/work on it.

Comments

@harshil-goel
Copy link
Contributor

What version of Dgraph are you using?

v1.1.0-134-gd9767791

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

32gb ram, ubuntu 19.04

Steps to reproduce the issue (command/config used to run Dgraph).

{
  set {
    _:user1 <money> "48038396025285290" .
  }
}

{
  q(func: has(money)) {
    f as money
    g: math(2+f)
  }
}

Expected behaviour and actual result.

Expected Behaviour

"q": [
      {
        "money": 48038396025285290,
        "g": 48038396025285292
      }
    ]

Actual Result:

"q": [
      {
        "money": 48038396025285290,
        "g": 48038396025285290
      }
    ]

This happens because all the math operations happen in float64 (https://github.com/dgraph-io/dgraph/blob/master/query/aggregator.go#L124), which only has a precision of 53 bits. So int, being 64 bits can overflow when put into float64 and hence the error.

@harshil-goel harshil-goel added kind/bug Something is broken. priority/P0 Critical issue that requires immediate attention. area/querylang Issues related to the query language specification and implementation. status/accepted We accept to investigate/work on it. labels Oct 7, 2019
@harshil-goel
Copy link
Contributor Author

We are going to change the current implementation in which we typecast int to float, to an implementation in which we keep the highest information type among the corresponding arguments.
Potentially it would allow for queries described in the issue, and if one wants a float result of their queries, the user can ask for math(f + 2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/querylang Issues related to the query language specification and implementation. kind/bug Something is broken. priority/P0 Critical issue that requires immediate attention. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

1 participant