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

Resolve NaN issue in Math with a few tests. #589

Closed
wants to merge 12 commits into from

Conversation

Cormac-Williams
Copy link
Contributor

Should resolve #539

insert: [],
remove: [],
};
Copy link
Contributor

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: [],
};
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

insert: [],
remove: [],
};
Copy link
Contributor

Choose a reason for hiding this comment

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

here also

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is sqrt1/2 ?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. As in i ! :)

Copy link
Contributor Author

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 ;-)

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 [];}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ibdknox
Copy link
Contributor

ibdknox commented Dec 1, 2016

Looks great, we just need to fix the merge conflict in math.ts and in she goes :)

@Cormac-Williams
Copy link
Contributor Author

Done :-)

@ibdknox
Copy link
Contributor

ibdknox commented Dec 1, 2016

Huh, looks like something went sideways on the merge - there are actually more conflicts now and @cmontella's look like they maybe got overwritten?

@Cormac-Williams
Copy link
Contributor Author

Ouch, well that's not as intended.
I'm going to revert the conflict merge.
Pull from master.
Apply changes again.
Hope and pray :-)

…math_NaN2"

This reverts commit 15d7dbe, reversing
changes made to 46e81a5.
@Cormac-Williams
Copy link
Contributor Author

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 ;-)

@Cormac-Williams Cormac-Williams deleted the math_NaN2 branch December 1, 2016 22:36
@cmontella
Copy link
Contributor

Thanks, sorry for the issues.

@Cormac-Williams
Copy link
Contributor Author

Not your fault, my muckups.

Recreated as #629.

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

Successfully merging this pull request may close these issues.

Numeric functions shouldn't return NaN
5 participants