Skip to content

feat(attribute_value): Don't target NAN, INF, -INF and > 2^53 #147

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

Merged
merged 5 commits into from
Dec 26, 2018

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Dec 20, 2018

Summary

Don't target NAN, INF or -INF doubles
Don't target Values > 2^53.
Both in EventBuilder payload and Audience Evaluation

Test plan

Issues

@oakbani oakbani requested a review from nchilada December 20, 2018 14:55
$this->assertTrue(Validator::IsFiniteNumber(0));
$this->assertTrue(Validator::IsFiniteNumber(5));
$this->assertTrue(Validator::IsFiniteNumber(5.5));
// float(2**53) + 1.0 evaluates to float(2**53)
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like copied from python, please change it.

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

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

LGTM. Minor feedback.

Please address @msohailhussain 's comment. I can help merge once ready.

* @return boolean Representing whether attribute's value is
* a number and not NAN, INF, -INF or greater than 2^53.
*/
public static function isFiniteNumber($value)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Just a code arrangement recommendation.
I would prefer if you defined isFiniteNumber before referencing it on line 91.

*/
public static function isFiniteNumber($value)
{
if (!(is_int($value) || is_float($value))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically you have already performed this check on line 91. If you want you can call isFiniteNumber directly on line 91.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isFiniteNumber is also called from conditionEvaluator when determining valid values in exact, gt, lt match types. So we need this check here.

return false;
}

if (abs($value) > pow(2,53)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Insert space after ,

@aliabbasrizvi aliabbasrizvi merged commit b0173f7 into master Dec 26, 2018
@aliabbasrizvi aliabbasrizvi deleted the oakbani/dont-target-nan-inf-2pow53 branch December 26, 2018 19:36
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.

3 participants