-
-
Notifications
You must be signed in to change notification settings - Fork 915
Add support for negating a complex number #193
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
Add support for negating a complex number #193
Conversation
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.
@ShraddheyaS Thanks for working on this! Main questions center around positive and negative zeros. Once these are resolved, this PR should be ready for acceptance.
|
|
||
| v = cnegate( 0.0, 0.0 ); | ||
| // returns [ TODO, TODO ] | ||
| // returns [ 0.0, 0.0 ] |
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.
Is this correct? Why not negative zeros?
| * var out = new Array( 2 ); | ||
| * var v = cnegate( out, 0.0, 0.0 ); | ||
| * // returns [ TODO, TODO ] | ||
| * // returns [ 0.0, 0.0 ] |
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 not negative zeros?
| * | ||
| * v = cnegate( 0.0, 0.0 ); | ||
| * // returns [ TODO, TODO ] | ||
| * // returns [ 0.0, 0.0 ] |
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 not negative zeros?
| * @example | ||
| * var v = cnegate( 0.0, 0.0 ); | ||
| * // returns [ TODO, TODO ] | ||
| * // returns [ 0.0, 0.0 ] |
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 not negative zeros?
| t.deepEqual( actual, expected, 'returns expected value' ); | ||
|
|
||
| actual = cnegate( 0.0, 0.0 ); | ||
| expected = [ 0.0, 0.0 ]; |
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.
This test is a bit more nuanced, as one needs to test for negative/positive zeros. Ideally, we would have tests for both.
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 believe this test is actually already taken care of in the tests starting at L118 and L125. Feel free to modify this test with, say, two negative numbers.
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.
Yes, thank you for pointing it out. I saw the isPositiveZero and isNegativeZero tests now. I have changed these tests in the latest commit.
|
|
||
| actual = cnegate( 0.0, 0.0 ); | ||
| expected = [ -0.0, -0.0 ]; | ||
| t.deepEqual( actual, expected, 'returns expected value' ); |
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.
Unfortunately, deepEqual does not check for sign equality when comparing zeros. Hence, the following test passes
actual = cnegate( 0.0, 0.0 );
expected = [ 0.0, 0.0 ];
t.deepEqual( actual, expected, 'returns expected value' );even if it shouldn't. Unfortunately, one cannot use deepEqual, but, instead, one must manually check individual array elements. In this case, that entails checking for value and sign equality. This has already been done, in later tests. So having tests here which test function signed zero behavior is not necessary. Perhaps, better might be to just test other values, perhaps with a different sign combination. For example,
actual = cnegate( -1.0, -1.0 );
expected = [ 1.0, 1.0 ];
t.deepEqual( actual, expected, 'returns expected value' );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.
Yes, I realized the redundancy and changed the tests.
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.
@ShraddheyaS Looks good! Will merge once the canary build passes.
* Add pkg scaffold * Fix pkg path * Add support for negating a complex number (#193) * Completed all the TODO's * Fixed the minus zero results * Edited the redundant tests which are being checked later
Resolves #101.
Checklist
develop.developbranch.Description
This pull request:
Related Issues
This pull request:
Questions
No.
Other
Yes.
feature/complex-negatebranch.@stdlib-js/reviewers