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

fix: floating point comparison was inexact #4372

Merged
merged 3 commits into from
Jan 24, 2020

Conversation

big-andy-coates
Copy link
Contributor

Description

fixes: #4370

Switches the generated Java code to convert the double to a String, and then using this to build the BigDecimal. This results in an exact BigDecimal for the comparison.

Without this change a double of 0.1 is converted to a BigDecimal of 0.1000000000000000055511151231257827021181583404541015625, which is greater than 0.1, hence the bug.

Testing done

Tests added.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

fixes: confluentinc#4370

Switches the generated Java code to convert the `double` to a `String`, and then using this to build the `BigDecimal`. This results in an exact `BigDecimal` for the comparison.

Without this change a `double` of `0.1` is converted to a `BigDecimal` of `0.1000000000000000055511151231257827021181583404541015625`, which is greater than `0.1`, hence the bug.
@big-andy-coates big-andy-coates requested a review from a team as a code owner January 23, 2020 17:21
Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Conflicting files
ksql-execution/src/test/java/io/confluent/ksql/execution/codegen/SqlToJavaVisitorTest.java
@big-andy-coates big-andy-coates merged commit 2a4ca47 into confluentinc:master Jan 24, 2020
@big-andy-coates big-andy-coates deleted the double_fix branch January 24, 2020 16:36
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

Successfully merging this pull request may close these issues.

WHERE clause on DOUBLE returning incorrect results
2 participants