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

[Java] Choose The Correct RoundingMode For Checking Decimal OutOfBounds #14731

Merged
merged 9 commits into from
Jan 12, 2024

Conversation

razajafri
Copy link
Contributor

@razajafri razajafri commented Jan 10, 2024

Description

This PR fixes an error in the outOfBounds method in which the RoundingMode was selected based on positive values only. The RHS should be rounded towards positive infinity (ROUND_CEILING) for the lower bound and towards negative infinity (ROUND_FLOOR) for the upper bound

closes #14732

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@razajafri razajafri added bug Something isn't working non-breaking Non-breaking change labels Jan 10, 2024
@razajafri razajafri requested a review from a team as a code owner January 10, 2024 02:02
Copy link

copy-pr-bot bot commented Jan 10, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions bot added the Java Affects Java cuDF API. label Jan 10, 2024
Signed-off-by: Raza Jafri <rjafri@nvidia.com>

Added tests
@razajafri
Copy link
Contributor Author

/ok to test

@razajafri
Copy link
Contributor Author

/ok to test

Comment on lines 91 to 92
// In ex:1 If we rounded down the rhs 100.19 would become 100.1, and now 100.1 is not < 100.1
// In ex:2 If we rounded up the rhs -100.19 would become -100.2, and now -100.2 is not < -100.2
Copy link
Contributor

Choose a reason for hiding this comment

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

So what are the correct rounding for these examples? I'm confused. Please be explicit.

Comment on lines 147 to 156

// First we have to round the scalar (rhs) to the same scale as lhs.
// Because this is a greater-than, and it is rhs that we are rounding, we will round towards 0 (DOWN) in case rhs is
// positive and away from 0 (UP) if rhs is negative to make sure we always return the correct value.
// For example:
// ex:1 100.2 > 100.19
// ex:2 -100.1 > -100.19
// In ex:1 If we rounded up the rhs 100.19 would become 100.2, and now 100.2 is not > 100.2
// In ex:2 If we rounded down the rhs -100.19 would become -100.1, and now -100.1 is not > -100.1
BigDecimal roundedRhs = rhs.setScale(-cvScale, rhs.signum() > 0 ? BigDecimal.ROUND_DOWN : BigDecimal.ROUND_UP);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just repeated of the code above. We should not copy-paste code around. If there is the same code used multiple times, let's extract it into a function and call it multiple times instead.

@razajafri
Copy link
Contributor Author

@jlowe @ttnghia Thanks for taking a look PTAL again

@razajafri
Copy link
Contributor Author

/ok to test

@razajafri
Copy link
Contributor Author

/ok to test

@razajafri
Copy link
Contributor Author

/ok to test

@razajafri
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 27b106f into rapidsai:branch-24.02 Jan 12, 2024
67 checks passed
@razajafri razajafri deleted the fixed-decimal-bounds branch January 12, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Java Affects Java cuDF API. non-breaking Non-breaking change
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUG] Error In Calculating Bounds for DecimalUtils OOB Check
4 participants