@@ -124,52 +124,52 @@ PMComplexNumber class >> zero [
124124{ #category : #arithmetic }
125125PMComplexNumber >> * anObject [
126126 " Answer the result of multiplying the receiver by aNumber."
127+
127128 | a b c d newReal newImaginary |
128- anObject isComplexNumber
129- ifTrue:
130- [a := self real.
131- b := self imaginary.
132- c := anObject real.
133- d := anObject imaginary.
134- newReal := (a * c) - (b * d).
135- newImaginary := (a * d) + (b * c).
136- ^ PMComplexNumber real: newReal imaginary: newImaginary]
137- ifFalse:
138- [^ anObject adaptToComplex: self andSend: #* ]
129+ ^ anObject isComplexNumber
130+ ifTrue: [
131+ a := self real.
132+ b := self imaginary.
133+ c := anObject real.
134+ d := anObject imaginary.
135+ newReal := a * c - (b * d).
136+ newImaginary := a * d + (b * c).
137+ PMComplexNumber real: newReal imaginary: newImaginary ]
138+ ifFalse: [ anObject adaptToComplex: self andSend: #* ]
139139]
140140
141141{ #category : #arithmetic }
142142PMComplexNumber >> + anObject [
143143 " Answer the sum of the receiver and aNumber."
144+
144145 | a b c d newReal newImaginary |
145- anObject isComplexNumber
146- ifTrue:
147- [a := self real.
148- b := self imaginary.
149- c := anObject real.
150- d := anObject imaginary.
151- newReal := a + c.
152- newImaginary := b + d.
153- ^ PMComplexNumber real: newReal imaginary: newImaginary]
154- ifFalse:
155- [^ anObject adaptToComplex: self andSend: #+ ]
146+ ^ anObject isComplexNumber
147+ ifTrue: [
148+ a := self real.
149+ b := self imaginary.
150+ c := anObject real.
151+ d := anObject imaginary.
152+ newReal := a + c.
153+ newImaginary := b + d.
154+ PMComplexNumber real: newReal imaginary: newImaginary ]
155+ ifFalse: [ anObject adaptToComplex: self andSend: #+ ]
156156]
157157
158158{ #category : #arithmetic }
159159PMComplexNumber >> - anObject [
160160 " Answer the difference between the receiver and aNumber."
161+
161162 | a b c d newReal newImaginary |
162- anObject isComplexNumber
163- ifTrue:
164- [a := self real.
165- b := self imaginary.
166- c := anObject real.
167- d := anObject imaginary.
168- newReal := a - c.
169- newImaginary := b - d.
170- ^ PMComplexNumber real: newReal imaginary: newImaginary]
171- ifFalse:
172- [^ anObject adaptToComplex: self andSend: #- ]
163+ ^ anObject isComplexNumber
164+ ifTrue: [
165+ a := self real.
166+ b := self imaginary.
167+ c := anObject real.
168+ d := anObject imaginary.
169+ newReal := a - c.
170+ newImaginary := b - d.
171+ PMComplexNumber real: newReal imaginary: newImaginary ]
172+ ifFalse: [ anObject adaptToComplex: self andSend: #- ]
173173]
174174
175175{ #category : #arithmetic }
@@ -189,10 +189,11 @@ PMComplexNumber >> / aNumber [
189189
190190{ #category : #comparing }
191191PMComplexNumber >> = anObject [
192- anObject isNumber ifFalse: [^ false ].
193- anObject isComplexNumber
194- ifTrue: [^ (real = anObject real) & (imaginary = anObject imaginary)]
195- ifFalse: [^ anObject adaptToComplex: self andSend: #= ]
192+
193+ anObject isNumber ifFalse: [ ^ false ].
194+ ^ anObject isComplexNumber
195+ ifTrue: [ real = anObject real & (imaginary = anObject imaginary) ]
196+ ifFalse: [ anObject adaptToComplex: self andSend: #= ]
196197]
197198
198199{ #category : #arithmetic }
@@ -262,16 +263,17 @@ PMComplexNumber >> arCosh [
262263 ^self arcCos i
263264 This implementation provides an answer with a positive real part.
264265 It also avoids creating intermediate Complex."
265-
266+
266267 | x y tmp sh2x shx delta ch2x chx |
267- imaginary = 0 ifTrue: [real abs > 1
268- ifTrue:
269- [y := real < 0
270- ifTrue: [Float pi]
271- ifFalse: [0 ].
272- x := real abs arCosh.
273- ^ self class real: x imaginary: y]
274- ifFalse: [^ self class real: 0 imaginary: real arcCos]].
268+ imaginary = 0 ifTrue: [
269+ ^ real abs > 1
270+ ifTrue: [
271+ y := real < 0
272+ ifTrue: [ Float pi ]
273+ ifFalse: [ 0 ].
274+ x := real abs arCosh.
275+ self class real: x imaginary: y ]
276+ ifFalse: [ self class real: 0 imaginary: real arcCos ] ].
275277 tmp := self squaredNorm - 1 / 2 .
276278 delta := tmp squared + imaginary squared.
277279 sh2x := tmp + delta sqrt.
@@ -280,7 +282,7 @@ PMComplexNumber >> arCosh [
280282 chx := ch2x sqrt.
281283 x := shx arSinh.
282284 y := imaginary copySignTo: (real / chx) arcCos.
283- ^ self class real: x imaginary: y
285+ ^ self class real: x imaginary: y
284286]
285287
286288{ #category : #' mathematical functions' }
@@ -315,14 +317,15 @@ PMComplexNumber >> arcCos [
315317 This is the inverse function of cos."
316318
317319 | x y tmp sh2y shy delta ch2y chy |
318- imaginary = 0 ifTrue: [real abs > 1
319- ifTrue:
320- [x := real < 0
321- ifTrue: [Float pi]
322- ifFalse: [0 ].
323- y := real copySignTo: real abs arCosh.
324- ^ self class real: x imaginary: y]
325- ifFalse: [^ self class real: real arcCos imaginary: 0 ]].
320+ imaginary = 0 ifTrue: [
321+ ^ real abs > 1
322+ ifTrue: [
323+ x := real < 0
324+ ifTrue: [ Float pi ]
325+ ifFalse: [ 0 ].
326+ y := real copySignTo: real abs arCosh.
327+ self class real: x imaginary: y ]
328+ ifFalse: [ self class real: real arcCos imaginary: 0 ] ].
326329 tmp := self squaredNorm - 1 / 2 .
327330 delta := tmp squared + imaginary squared.
328331 sh2y := tmp + delta sqrt.
@@ -331,7 +334,7 @@ PMComplexNumber >> arcCos [
331334 chy := ch2y sqrt.
332335 y := imaginary copySignTo: shy arSinh.
333336 x := (real / chy) arcCos.
334- ^ self class real: x imaginary: y negated
337+ ^ self class real: x imaginary: y negated
335338]
336339
337340{ #category : #' mathematical functions' }
@@ -340,23 +343,22 @@ PMComplexNumber >> arcSin [
340343 This is the inverse function of sin."
341344
342345 | x y tmp delta sh2y shy ch2y chy |
343- imaginary = 0
344- ifTrue:
345- [real abs > 1
346- ifTrue:
347- [x := Float pi / 2 * real sign.
348- y := (real copySignTo: real abs arCosh) negated.
349- ^ self class real: x imaginary: y]
350- ifFalse: [^ self class real: real arcSin imaginary: 0 ]].
351- tmp := (self squaredNorm - 1 ) / 2 .
346+ imaginary = 0 ifTrue: [
347+ ^ real abs > 1
348+ ifTrue: [
349+ x := Float pi / 2 * real sign.
350+ y := (real copySignTo: real abs arCosh) negated.
351+ self class real: x imaginary: y ]
352+ ifFalse: [ self class real: real arcSin imaginary: 0 ] ].
353+ tmp := self squaredNorm - 1 / 2 .
352354 delta := tmp squared + imaginary squared.
353355 sh2y := tmp + delta sqrt.
354356 shy := sh2y sqrt.
355357 ch2y := 1 + sh2y.
356358 chy := ch2y sqrt.
357359 y := imaginary copySignTo: shy arSinh.
358360 x := (real / chy) arcSin.
359- ^ self class real: x imaginary: y
361+ ^ self class real: x imaginary: y
360362]
361363
362364{ #category : #' mathematical functions' }
@@ -686,10 +688,9 @@ PMComplexNumber >> reciprocal [
686688 " Answer 1 divided by the receiver. Create an error notification if the
687689 receiver is 0."
688690
689- self = 0
690- ifTrue: [^ (ZeroDivide dividend: self ) signal ]
691- ifFalse: [^ 1 / self ]
692-
691+ ^ self = 0
692+ ifTrue: [ (ZeroDivide dividend: self ) signal ]
693+ ifFalse: [ 1 / self ]
693694]
694695
695696{ #category : #testing }
0 commit comments