-
Notifications
You must be signed in to change notification settings - Fork 257
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
Resolve NaN issue in Math with a few tests. #589
Conversation
insert: [], | ||
remove: [], | ||
}; |
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.
I would suggest adding errors: true
here to make sure that we effectively have an error.
insert: [], | ||
remove: [], | ||
}; |
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.
same here
insert: [], | ||
remove: [], | ||
}; |
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.
here also
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.
Lol, I tried that and pushed too early. errors: true seems to cause the test to expect an error to be raised in some way from the code. I reverted, and may need to receive guidance from the team.
Filtering NaN is a constraint, that causes the block to filter any results rather than a specific error condition that needs to be raised.
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.
Yeah, the behavior you have is correct here. What we want to verify is that if anything would otherwise return NaN that it instead returns nothing. It's not an error, it's the absence of a result.
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.
:thumpsup:
@@ -473,4 +483,4 @@ providers.provide("ln10", LN10); | |||
providers.provide("log2e",LOG2E ); | |||
providers.provide("log10e",LOG10E ); | |||
providers.provide("sqrt1/2", SQRT1_2); |
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.
What is sqrt1/2
?
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.
Square root of a half.
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.
Right. As in i
! :)
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.
No i is root -1 ;-)
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.
Yeah. I am confused. You are right.
proposal.providing = proposed; | ||
proposal.cardinality = 1; | ||
return proposal; | ||
if(this.returns.length) { |
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.
Out of curiosity, why are you checking if there's a return?
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.
To bring the code in line with the way that providers\logical.ts handles the same situation.
There's a slight discrepancy with the documentation in that it isn't returning a proposal with cardinality zero, but I've been unable to show that simply returning produces any strange behavious, so assumed returning an undefined is handled correctly by the runtime.
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.
Ah the logical providers do this for a reason that doesn't really apply here. There are two cases for the logic operators, the standard filtering case x > y
and the value returning case using is(x > y)
. In the former case, we never want to propose anything and instead just go through the testing phase. In the latter case, is
adds a return variable that we'll want to fill in with the boolean value of the expression. With math ops, they should always have a bound return, so the check doesn't buy us anything.
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.
Ok, I'll revert the getProposal function to original.
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.
Done.
@@ -63,6 +68,11 @@ function degreesToRadians(degrees:number){ | |||
} | |||
|
|||
class Add extends TotalFunctionConstraint { | |||
resolveProposal(proposal, prefix) { |
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.
Why override resolveProposal? Seems like add should have the same NaN guard.
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.
At the moment the add function in the Math file is also providing the ability to concatenate strings to the language. If the decision is that Eve should always use string interpolation then this can be removed.
My opinion is that concatenating strings with a + symbol is such second nature to programmers that it would provide a real WTF moment to filter a block anytime "" + "" is used.
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.
A fair number of languages have explicit concatenation operators instead of overloading + for strings. The main argument against doing so is that it doesn't make a lot of sense without implicit conversions which is something we want to stay far away from. E.g. "foo" + 1 implicit converts 1 to a string in JS. I think we should do more than just fail silently in the case where you try to add strings, but we need to think a bit about what that warning system would be.
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.
At the moment you don't fail silently, you add them using Javascripts implicit rules :-) . I didn't want to introduce a breaking change to other peoples Eve code, but I agree that some thought needs to be given to implicit conversion. What about a combine aggregate?
I'll leave this as is for the pull unless told otherwise.
@@ -13,7 +13,9 @@ abstract class TotalFunctionConstraint extends Constraint { | |||
// proposed variable. | |||
resolveProposal(proposal, prefix) { | |||
let {args} = this.resolve(prefix); | |||
return [this.getReturnValue(args)]; | |||
let result = this.getReturnValue(args); | |||
if (isNaN(result) || !(isFinite(result))) {return [];} |
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.
Inifinity is a well-defined value, so I think we can remove that check and just have the NaN one.
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.
Removed the check. This was also was what was handling the filtering for Divide by zero, so handled that in Div function.
…getProposal" This reverts commit ecf4231.
Looks great, we just need to fix the merge conflict in math.ts and in she goes :) |
Done :-) |
Huh, looks like something went sideways on the merge - there are actually more conflicts now and @cmontella's look like they maybe got overwritten? |
Ouch, well that's not as intended. |
Ok, that went even more sideways. Sometimes I hate git :-( I'm going to kill this pull request and send afresh with just the changes wanted. There'll soon be more commits than lines changed ;-) |
Thanks, sorry for the issues. |
Not your fault, my muckups. Recreated as #629. |
Should resolve #539