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

Refactor: Introduce complexConjugate Message, Deprecate conjugated #231

Merged
merged 11 commits into from
Apr 5, 2022

Conversation

hemalvarambhia
Copy link
Contributor

@hemalvarambhia hemalvarambhia commented Apr 4, 2022

Issue no. #192.

PMComplex >> isReal [

^ imaginary = 0 and: [ real >= 0 ]
]
Copy link
Member

@SergeStinckwich SergeStinckwich Apr 5, 2022

Choose a reason for hiding this comment

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

-1 is not real?

Copy link
Contributor Author

@hemalvarambhia hemalvarambhia Apr 5, 2022

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.

"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 ].
Copy link
Member

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.

Copy link
Contributor Author

@hemalvarambhia hemalvarambhia Apr 5, 2022

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@SergeStinckwich SergeStinckwich merged commit 33bfd2c into master Apr 5, 2022
@SergeStinckwich SergeStinckwich deleted the refactor-to-deeper-insight branch April 5, 2022 06:53
v := (self abs - real / 2) sqrt.
u := imaginary / 2 / v.
^self class real: u imaginary: v
^ self class real: u imaginary: v
Copy link
Contributor Author

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

@hemalvarambhia
Copy link
Contributor Author

@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.

@SergeStinckwich SergeStinckwich added this to the v1.0.4 milestone Apr 25, 2022
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.

2 participants