Skip to content

Fix support for widening on equals operator#4617

Merged
jpbempel merged 2 commits into
masterfrom
jpbempel/number-wdiening
Feb 1, 2023
Merged

Fix support for widening on equals operator#4617
jpbempel merged 2 commits into
masterfrom
jpbempel/number-wdiening

Conversation

@jpbempel

Copy link
Copy Markdown
Member

What Does This Do

only the equals operator in Expression Language was not supporting mixing integer and float. If the type does not match we are widening to BigDecimal for comparison

Motivation

Additional Notes

only the equals operator in Expression Language was not supporting
mixing integer and float. If the type does not match we are widening
to BigDecimal for comparison
@jpbempel
jpbempel requested a review from a team as a code owner January 30, 2023 08:43
@jpbempel
jpbempel requested review from shatzi and removed request for a team January 30, 2023 08:43
@jpbempel jpbempel added the comp: debugger Dynamic Instrumentation label Jan 30, 2023

@shatzi shatzi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great progress. Dobule.compare have some side effects that I believe need to be refined.

Arguments.of(new NumericValue(1), new NumericValue(2), LT, true, "1 < 2"),
Arguments.of(new NumericValue(2), new NumericValue(1), LT, false, "2 < 1"),
Arguments.of(new NumericValue(1.0), new NumericValue(1.1), LT, true, "1.0 < 1.1"),
Arguments.of(new NumericValue(1), new NumericValue(1.1), LT, true, "1 < 1.1"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might worth also check the false state?

Arguments.of(new NumericValue(1), new NumericValue(0.9), GE, true, "1 >= 0.9"),
Arguments.of(ValueExpression.NULL, new NumericValue(2), GE, false, "null >= 2"),
Arguments.of(
new NumericValue(Double.NaN), new NumericValue(Double.NaN), GE, true, "NaN >= NaN"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why this is true? I thought NaN is not equal to anything, include NaN. or JVM treat NaN differently?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

found that Double.compare treat NaN differently.
Which is interesting as person.height == NaN would return false even if person.height is NaN. but our DSL return true - which make more sense for me.

However, Dobule.compare(NaN, any-other-number) == 1 (always greater) - which I find wrong; DSL of person.height > 10 will return true when height is NaN - not what I would expect.

Maybe worth refine those details and ensure our DSL return what is expected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

well using Double.compare with NaN is not great because you need a result that is either 0, -1 or 1 while boolean comparison could be false which is another kind of result.
so we need to take care specially for NaN, I agree

Arguments.of(new NumericValue(1L), new NumericValue(1L), EQ, true, "1 == 1"),
Arguments.of(new NumericValue(1.0F), new NumericValue(1.0F), EQ, true, "1.0 == 1.0"),
Arguments.of(new NumericValue(1.0), new NumericValue(1.0), EQ, true, "1.0 == 1.0"),
Arguments.of(new NumericValue(1), new NumericValue(1.0), EQ, true, "1 == 1.0"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we also have 1 == 2.0 is false?

add more tests
@jpbempel
jpbempel force-pushed the jpbempel/number-wdiening branch from c1ac517 to f5952cf Compare February 1, 2023 16:48

@shatzi shatzi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice.

@jpbempel
jpbempel merged commit d07bbb8 into master Feb 1, 2023
@jpbempel
jpbempel deleted the jpbempel/number-wdiening branch February 1, 2023 17:31
@github-actions github-actions Bot added this to the 1.7.0 milestone Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: debugger Dynamic Instrumentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants