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

TermUtils.isReal(IStrategoTerm, double) does not follow standard Stratego term equality #23

Open
Apanatshka opened this issue Nov 18, 2020 · 3 comments
Assignees

Comments

@Apanatshka
Copy link
Contributor

Stratego is weird. Equality between two Real terms (double precision floating point numbers) is done with Java's built-in == operator, despite how common wisdom for comparing floats goes by comparing if their difference in under a certain threshold. TermUtils uses a fuzzy equals that uses difference under a threshold of 1e-30. I think to avoid more confusion, it should instead use the equality that Stratego uses for terms everywhere else. Thoughts?

return isReal(term) && fuzzyEquals(((IStrategoReal)term).realValue(), value);

@Virtlink
Copy link
Contributor

If the rest of Stratego uses == for floating-point equality, then that should be changed. In practice, two floating points are rarely exactly equal, so matching will almost always fail.

@Apanatshka
Copy link
Contributor Author

Yeah, here is just one of the places where this happens:

if(realValue() != ((IStrategoReal) second).realValue())

Ok, can you change it then @Virtlink? I know it's a silly way to do comparisons this way, but there is not much use of floating points in Stratego anyway.
Perhaps we can add a strategy to the standard library of Stratego for proper comparison of reals like real-diff-within(|real) :: (real, real) -> (real, real) where you provide the epsilon value yourself. But that's separate from this issue.

@Gohla
Copy link
Member

Gohla commented Nov 19, 2020

Changing this probably will not affect anything, as I don't think we ever use floats in Stratego, let alone compare them. But to be sure, the change should be tested by creating a new spoofax-libs.jar, copying that to strategoxt (https://github.com/metaborg/strategoxt/blob/master/strategoxt/stratego-libraries/java-backend/java/spoofax-libs.jar), and by building (bootstrapping?) strategoxt.

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

No branches or pull requests

3 participants