Skip to content

Commit 3cf9948

Browse files
authored
Merge pull request #251 from olekscode/247-Add-complexConjugate-to-Number-and-remove-isComplexConjugateOf
Fixed #247. Added complexConjugate to Number and removed isCompleConjugateOf:
2 parents 261ca40 + 7342d75 commit 3cf9948

File tree

6 files changed

+22
-98
lines changed

6 files changed

+22
-98
lines changed

src/Math-Complex/Number.extension.st

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ Number >> asComplex [
1515

1616
{ #category : #'*Math-Complex' }
1717
Number >> complexConjugate [
18-
^ self.
18+
"The complex conjugate of a complex number (a + bi) is another complex number (a - bi).
19+
Every real number x is also a complex number with imaginary part equal to 0.
20+
In other words, x = x + 0i and x = x - 0i.
21+
Therefore, the complex conjugate of a real number is the same real number"
22+
23+
^ self
1924
]
2025

2126
{ #category : #'*Math-Complex' }
@@ -37,13 +42,11 @@ Number >> i: aNumber [
3742
{ #category : #'*Math-Complex' }
3843
Number >> isComplexConjugateOf: aNumber [
3944
"A complex conjugate of a real number is same real number"
40-
^ self = aNumber
41-
]
45+
self
46+
deprecated: 'This method is redundant. Just check the equality with complexConjugate'
47+
transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.
4248

43-
{ #category : #'*Math-Complex' }
44-
Number >> isComplexConjugateOfAComplexNumber: aComplexNumber [
45-
"A complex conjugate of a real number is same real number"
46-
^ self isComplexConjugateOf: aComplexNumber
49+
^ self complexConjugate = aNumber
4750
]
4851

4952
{ #category : #'*Math-Complex' }

src/Math-Complex/PMComplex.class.st

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,11 @@ PMComplex >> imaginary [
537537
{ #category : #testing }
538538
PMComplex >> isComplexConjugateOf: aNumber [
539539
"Answer true if self and aNumber are complex conjugates of each other. The complex conjugate of a complex number is the number with an equal real part and an imaginary part equal in magnitude but opposite in sign."
540-
^ aNumber isComplexConjugateOfAComplexNumber: self
541-
]
540+
self
541+
deprecated: 'This method is redundant. Just check the equality with complexConjugate'
542+
transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.
542543

543-
{ #category : #testing }
544-
PMComplex >> isComplexConjugateOfAComplexNumber: aComplexNumber [
545-
"Answer true if self and aComplexNumber are complex conjugates of each other. The complex conjugate of a complex number is the number with an equal real part and an imaginary part equal in magnitude but opposite in sign."
546-
^ (aComplexNumber real = real) and: [ aComplexNumber imaginary = (-1 * imaginary) ]
544+
^ self complexConjugate = aNumber
547545
]
548546

549547
{ #category : #testing }

src/Math-Matrix/PMMatrix.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ PMMatrix >> isHermitian [
567567

568568
1 to: self numberOfRows do: [ :i |
569569
1 to: (i - 1) do: [ :j |
570-
((self at: i at: j) isComplexConjugateOf: (self at: j at: i))
570+
((self at: i at: j) complexConjugate = (self at: j at: i))
571571
ifFalse: [ ^ false ] ] ].
572572

573573
^ true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Extension { #name : #NumberTest }
2+
3+
{ #category : #'*Math-Tests-Complex' }
4+
NumberTest >> testComplexConjugate [
5+
6+
self assert: 5 complexConjugate equals: 5
7+
]

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

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -384,60 +384,6 @@ PMComplexTest >> testHash [
384384
self assert: aComplex copy hash equals: aComplex hash
385385
]
386386

387-
{ #category : #tests }
388-
PMComplexTest >> testIsComplexConjugateOfConjugateComplex [
389-
390-
self assert: ((3 + 2i) isComplexConjugateOf: (3 - 2i))
391-
]
392-
393-
{ #category : #tests }
394-
PMComplexTest >> testIsComplexConjugateOfConjugateComplexAndReal [
395-
396-
self assert: ((5 + 0i) isComplexConjugateOf: 5)
397-
]
398-
399-
{ #category : #tests }
400-
PMComplexTest >> testIsComplexConjugateOfConjugateRealAndComplex [
401-
402-
self assert: (5 isComplexConjugateOf: (5 - 0i))
403-
]
404-
405-
{ #category : #tests }
406-
PMComplexTest >> testIsComplexConjugateOfDifferentReal [
407-
408-
self deny: (-5 isComplexConjugateOf: 5)
409-
]
410-
411-
{ #category : #tests }
412-
PMComplexTest >> testIsComplexConjugateOfNonConjugateComplexAndReal [
413-
414-
self deny: ((5 + 3i) isComplexConjugateOf: 5)
415-
]
416-
417-
{ #category : #tests }
418-
PMComplexTest >> testIsComplexConjugateOfNonConjugateDifferentComplex [
419-
420-
self deny: ((-0.5 - 1i) isComplexConjugateOf: (3 - 2i))
421-
]
422-
423-
{ #category : #tests }
424-
PMComplexTest >> testIsComplexConjugateOfNonConjugateRealAndComplex [
425-
426-
self deny: (5 isComplexConjugateOf: (5 - 3i))
427-
]
428-
429-
{ #category : #tests }
430-
PMComplexTest >> testIsComplexConjugateOfSameComplex [
431-
432-
self deny: ((3 - 2i) isComplexConjugateOf: (3 - 2i))
433-
]
434-
435-
{ #category : #tests }
436-
PMComplexTest >> testIsComplexConjugateOfSameReal [
437-
438-
self assert: (5 isComplexConjugateOf: 5)
439-
]
440-
441387
{ #category : #tests }
442388
PMComplexTest >> testIsComplexNumberOnComplex [
443389

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)