-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Refactor: Introduce complexConjugate Message, Deprecate conjugated #231
Conversation
Pharo is then able to put a dot next to the method in production.
src/Math-Complex/PMComplex.class.st
Outdated
PMComplex >> isReal [ | ||
|
||
^ imaginary = 0 and: [ real >= 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.
-1 is not real?
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.
Very true. Thus we may have a bug and a missing test.
src/Math-Complex/PMComplex.class.st
Outdated
"Return the square root of the receiver with a positive imaginary part." | ||
|
||
| u v | | ||
(imaginary = 0 and: [real >= 0]) | ||
ifTrue: [^self class real: real sqrt imaginary: 0]. | ||
self isReal ifTrue: [ ^ self class real: real sqrt imaginary: 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.
I think you extract (imaginary = 0 and: [real >= 0])
a bit too fast, this is not replaced by isReal but by isReal and positive.
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.
How about z isZero or: z isAPositiveReal
?
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 don't know if this is necessary. Maybe keep it like it was before.
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.
Sure. Perhaps we need more tests before refactoring.
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 have inlined the method for us.
v := (self abs - real / 2) sqrt. | ||
u := imaginary / 2 / v. | ||
^self class real: u imaginary: v | ||
^ self class real: u imaginary: v |
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.
These may be formatting improvements by Pharo when I inlined the isReal
method
@SergeStinckwich I think we could add more tests for the square root message. I can do that as my next PR. Rather than tests in one method, I would rather write separate test methods with good names. |
Issue no. #192.