-
Notifications
You must be signed in to change notification settings - Fork 525
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(expr): fix interval div float #3631
Conversation
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
Codecov Report
@@ Coverage Diff @@
## main #3631 +/- ##
=======================================
Coverage 74.37% 74.37%
=======================================
Files 776 776
Lines 110155 110163 +8
=======================================
+ Hits 81927 81934 +7
- Misses 28228 28229 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
src/common/src/types/interval.rs
Outdated
@@ -196,7 +196,10 @@ impl IntervalUnit { | |||
} | |||
|
|||
let months = (self.months as f64) / rhs; | |||
let days = (self.days as f64) / rhs + (months % 1.0) * 30.0; | |||
let mut days = (self.days as f64) / rhs + (months % 1.0) * 30.0; | |||
if (days - days.round()).abs() <= 0.0000001 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use https://doc.rust-lang.org/std/primitive.f64.html#associatedconstant.EPSILON instead?
days.fract().abs() < f64::EPSILON
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy <wyf000219@126.com>
…wave into interval_mul_float
* fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com> * fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com> * fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com> * fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com> * fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com> * fix(expr): fix interval div float Signed-off-by: Shmiwy <wyf000219@126.com>
Signed-off-by: Shmiwy wyf000219@126.com
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
where we should get
2 mons 12 days 00:00:00
https://github.com/singularity-data/risingwave/blob/722ba98b33fe87e8de028d31d57f7bd63d6bcd63/src/common/src/types/interval.rs#L199
float are not exact in computer, so it is not advisable to use float numbers directly for mod and division operations. Thus, the month numbers are inexact. As in the example above, where we should get 12.0, but often we get 11.99999999
Checklist
./risedev check
(or alias,./risedev c
)Refer to a related PR or issue link (optional)
#3341