Skip to content

Commit 2ac091f

Browse files
Extracted the implementation to a new method that clients should use.
1 parent b5affe0 commit 2ac091f

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/Math-Complex/PMComplex.class.st

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,18 @@ PMComplex >> asComplex [
403403
^self
404404
]
405405

406+
{ #category : #arithmetic }
407+
PMComplex >> complexConjugate [
408+
409+
^ self class real: real imaginary: imaginary negated
410+
]
411+
406412
{ #category : #arithmetic }
407413
PMComplex >> conjugated [
414+
408415
"Return the complex conjugate of this complex number."
409416

410-
^self class real: real imaginary: imaginary negated
417+
^ self complexConjugate
411418
]
412419

413420
{ #category : #'mathematical functions' }

src/Math-Complex/PMComplex.extension.st

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ PMComplex >> productWithVector: aVector [
1717
^ aVector collect: [ :each | each * self ]
1818
]
1919

20-
{ #category : #'*Math-Complex' }
21-
PMComplex >> random [
22-
"analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced."
23-
^ self class random * self
24-
25-
]
26-
2720
{ #category : #'*Math-Complex' }
2821
PMComplex class >> random [
2922
"Answers a random number with abs between 0 and 1."
3023

3124
^ self abs: 1.0 random arg: 2 * Float pi random
3225
]
3326

27+
{ #category : #'*Math-Complex' }
28+
PMComplex >> random [
29+
"analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced."
30+
^ self class random * self
31+
32+
]
33+
3434
{ #category : #'*Math-Complex' }
3535
PMComplex >> subtractToPolynomial: aPolynomial [
3636
^ aPolynomial addNumber: self negated

src/Math-Tests-Complex/PMComplexTest.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ PMComplexTest >> testComplexCollection [
195195

196196
{ #category : #tests }
197197
PMComplexTest >> testConjugated [
198-
| c cc |
198+
| c cc expected |
199199
c := 5 - 6 i.
200200
cc := c conjugated.
201-
self assert: cc real equals: c real.
202-
self assert: cc imaginary equals: c imaginary negated
201+
expected := 5 + 6 i.
202+
self assert: cc equals: expected.
203203
]
204204

205205
{ #category : #tests }

0 commit comments

Comments
 (0)