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

NumberNode's equal definition is impacted by the underlying representation #1378

Closed
Baccata opened this issue Aug 31, 2022 · 2 comments · Fixed by #1955
Closed

NumberNode's equal definition is impacted by the underlying representation #1378

Baccata opened this issue Aug 31, 2022 · 2 comments · Fixed by #1955
Labels
feature-request A feature should be added or improved.

Comments

@Baccata
Copy link

Baccata commented Aug 31, 2022

I'm not sure whether this qualifies as a bug, as it's directly coming from what I'd qualify as a java gotcha, but the two nodes values defined below are not equal with one another :

  • Node.from(new java.math.BigDecimal("1.0e+10"))
  • Node.from(1.0e+10)

This makes comparing some models hard. It'd be nice to have the equals method of number nodes protect against this gotcha.

@mtdowling
Copy link
Member

We do have an equals method but it just compares the exact string representation of numbers. Comparing across numeric types is going to be... fun.

@mtdowling mtdowling added the feature-request A feature should be added or improved. label Sep 5, 2022
@Baccata
Copy link
Author

Baccata commented Sep 6, 2022

Scala actually has this solved, and different representations of numbers can be compared accurately with a lot less edge cases.

In particular, Scala libraries tend that need to support several number representations (such as Json libraries) tend to delegate to the scala.math.BigDecimal type, the implementation of which could be replicated in NumberNode.

mtdowling added a commit that referenced this issue Aug 25, 2023
Attempts to use the most optimal comparisons of number nodes,
using .equals if both number values are of the same type, then the
string representation of each value, finally followed by comparing
the BigDecimal representation of each value using the string cache.
If a BigDecimal is needed, it is cached on the number node for future
checks.

Closes #1378
mtdowling added a commit that referenced this issue Aug 25, 2023
Attempts to use the most optimal comparisons of number nodes,
using .equals if both number values are of the same type, then the
string representation of each value, finally followed by comparing
the BigDecimal representation of each value using the string cache.
If a BigDecimal is needed, it is cached on the number node for future
checks.

Closes #1378
mtdowling added a commit that referenced this issue Aug 25, 2023
Attempts to use the most optimal comparisons of number nodes,
using .equals if both number values are of the same type, then the
string representation of each value, finally followed by comparing
the BigDecimal representation of each value using the string cache.
If a BigDecimal is needed, it is cached on the number node for future
checks.

Closes #1378
alextwoods pushed a commit to alextwoods/smithy that referenced this issue Sep 15, 2023
Attempts to use the most optimal comparisons of number nodes,
using .equals if both number values are of the same type, then the
string representation of each value, finally followed by comparing
the BigDecimal representation of each value using the string cache.
If a BigDecimal is needed, it is cached on the number node for future
checks.

Closes smithy-lang#1378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants