moved
authorClaus Gittinger <cg@exept.de>
Thu, 04 Aug 2011 22:46:43 +0200
changeset 13548 c45aedb0aaf4
parent 13547 f08daec3c459
child 13549 655271bb409b
moved
Complex.st
--- a/Complex.st	Thu Aug 04 21:38:06 2011 +0200
+++ b/Complex.st	Thu Aug 04 22:46:43 2011 +0200
@@ -8,17 +8,17 @@
 	* The material shall not be used for commercial gain without the prior
 	  written consent of the author(s).
 
- For more information about the Manchester Goodies Library (from which 
+ For more information about the Manchester Goodies Library (from which
  this file was distributed) send e-mail:
 	To: goodies-lib@cs.man.ac.uk
-	Subject: help 
+	Subject: help
 
  This is an additional goody-class, which is NOT covered by the
  ST/X license. It has been packaged with the ST/X distribution to
  make your live easier instead. NO WARRANTY.
 "
 
-"{ Package: 'stx:goodies' }"
+"{ Package: 'stx:libbasic' }"
 
 ArithmeticValue subclass:#Complex
 	instanceVariableNames:'real imaginary'
@@ -40,10 +40,10 @@
 	* The material shall not be used for commercial gain without the prior
 	  written consent of the author(s).
 
- For more information about the Manchester Goodies Library (from which 
+ For more information about the Manchester Goodies Library (from which
  this file was distributed) send e-mail:
 	To: goodies-lib@cs.man.ac.uk
-	Subject: help 
+	Subject: help
 
  This is an additional goody-class, which is NOT covered by the
  ST/X license. It has been packaged with the ST/X distribution to
@@ -53,22 +53,22 @@
 
 documentation
 "
-    This class implements complex numbers.  
-    A complex number has real and imaginary parts which must be manipulated simultaneously 
+    This class implements complex numbers.
+    A complex number has real and imaginary parts which must be manipulated simultaneously
     in any numeric processing.
     Complex numbers can be used in many of the same places that regular numbers
     can be used with one major exception of comparisons, since complex numbers cannot
-    be directly compared for size 
+    be directly compared for size
     (except through lengths of vectors (see absolute value)).
 
     [Instance variables:]
        real        <Number> the part of the number which can be expressed as a Real number
        imaginary   <Number> the part of the number which, in terms of how the number behaves,
-                            has been multiplied by 'i' (-1 sqrt)
+			    has been multiplied by 'i' (-1 sqrt)
 
     [Author:]
-        Kurt Hebel (hebel@uinova.cerl.uiuc.edu)
-        minor changes and double dispatching code by cg.
+	Kurt Hebel (hebel@uinova.cerl.uiuc.edu)
+	minor changes and double dispatching code by cg.
 "
 !
 
@@ -77,21 +77,21 @@
     (5 % 7) real
     (5 % 7) imaginary
     (5 % 7) = 5
-    (5 % 0) = 5     
-    (5.0 % 0) = 5       
+    (5 % 0) = 5
+    (5.0 % 0) = 5
 
-    (1 % 0) + (2 % 0)   
-    (1 % 0) + (0 % 2)   
+    (1 % 0) + (2 % 0)
+    (1 % 0) + (0 % 2)
     (1 % 0) + (2 % 3)
 
-    (1 % 0) * (2 % 0)   
-    (1 % 0) * (0 % 2)   
+    (1 % 0) * (2 % 0)
+    (1 % 0) * (0 % 2)
     (1 % 0) * (2 % 3)
 
     (1 % 2) + 2
     (1 % 2) * 2
-    2 + (1 % 2) 
-    2 * (1 % 2) 
+    2 + (1 % 2)
+    2 * (1 % 2)
 
 "
 ! !
@@ -138,22 +138,22 @@
 
 unity
     "Answer the value which allows, for any given arithmetic value, the following to be true:
-        aNumber * aNumber class unity = aNumber
+	aNumber * aNumber class unity = aNumber
      This must be true regardless of how a given subclass chooses to define #*"
 
     ComplexOne isNil ifTrue:[
-        ComplexOne := self fromReal: 1
+	ComplexOne := self fromReal: 1
     ].
     ^ ComplexOne
 !
 
 zero
     "Answer the value which allows, for any given arithmetic value, the following to be true:
-        aNumber + aNumber class zero = aNumber
+	aNumber + aNumber class zero = aNumber
      This must be true regardless of how a given subclass chooses to define #+"
 
     ComplexZero isNil ifTrue:[
-        ComplexZero := self fromReal: 0
+	ComplexZero := self fromReal: 0
     ].
     ^ ComplexZero
 ! !
@@ -168,35 +168,35 @@
     |send|
 
     ^ ImaginaryResultError handle: [:ex |
-        |selector|
+	|selector|
 
-        send := ex parameter.
-        selector := send selector.
-        (selector = #sqrt or: [selector = #sqrtTruncated]) ifTrue: [
-            send receiver: send receiver asComplex.
-            ex proceedWith: send value
-        ] ifFalse: [
-            ex reject
-        ]
+	send := ex parameter.
+	selector := send selector.
+	(selector = #sqrt or: [selector = #sqrtTruncated]) ifTrue: [
+	    send receiver: send receiver asComplex.
+	    ex proceedWith: send value
+	] ifFalse: [
+	    ex reject
+	]
     ] do: aBlock
 
     "
-     Complex trapImaginary: [-2 sqrt] 
+     Complex trapImaginary: [-2 sqrt]
     "
 
     "failing code:
-         |a|
+	 |a|
 
-         a := -2.
-         (a sqrt + 5) * 17. 
+	 a := -2.
+	 (a sqrt + 5) * 17.
     "
     "complex code:
-         |a|
+	 |a|
 
-         Complex trapImaginary:[       
-             a := -2.
-             (a sqrt + 5) * 2. 
-         ]
+	 Complex trapImaginary:[
+	     a := -2.
+	     (a sqrt + 5) * 2.
+	 ]
     "
 ! !
 
@@ -230,7 +230,7 @@
 
 !Complex methodsFor:'arithmetic'!
 
-* aNumber 
+* aNumber
     "Return the product of the receiver and the argument."
 
 "/    | u v r i |
@@ -243,12 +243,12 @@
 "/        i = 0 ifTrue:[ ^ r ].
 "/        ^ Complex real:r imaginary:i
 "/    ].
-    ^ aNumber productFromComplex:self. 
+    ^ aNumber productFromComplex:self.
 
     "Modified: / 8.7.1998 / 12:12:37 / cg"
 !
 
-+ aNumber 
++ aNumber
     "Return the sum of the receiver and the argument."
 
 "/    | r i |
@@ -259,7 +259,7 @@
 "/        i = 0 ifTrue:[ ^ r ].
 "/        ^ Complex real:r imaginary:i
 "/    ].
-    ^ aNumber sumFromComplex:self. 
+    ^ aNumber sumFromComplex:self.
 
     "Modified: / 8.7.1998 / 12:15:42 / cg"
 !
@@ -275,17 +275,17 @@
 "/        i = 0 ifTrue:[ ^ r ].
 "/        ^ Complex real:r imaginary:i.
 "/    ].
-    ^ aNumber differenceFromComplex:self. 
+    ^ aNumber differenceFromComplex:self.
 
     "Modified: / 8.7.1998 / 12:15:38 / cg"
 !
 
-/ aNumber 
+/ aNumber
     "Return the quotient of the receiver and the argument."
 
 "/    | denom u v r i |
 "/
-"/    aNumber isComplex ifTrue:[ 
+"/    aNumber isComplex ifTrue:[
 "/        u := aNumber real.
 "/        v := aNumber imaginary.
 "/        denom := u * u + (v * v).
@@ -294,7 +294,7 @@
 "/        i = 0 ifTrue:[ ^ r ].
 "/        ^ Complex real:r imaginary:i
 "/    ].
-    ^ aNumber quotientFromComplex:self. 
+    ^ aNumber quotientFromComplex:self.
 
     "Modified: / 8.7.1998 / 12:15:34 / cg"
 !
@@ -314,9 +314,9 @@
     "Return the complex conjugate of this complex number
      (i.e. with imaginary part negated)."
 
-    ^ Complex 
-        real: real
-        imaginary: imaginary negated
+    ^ Complex
+	real: real
+	imaginary: imaginary negated
 !
 
 modulus
@@ -325,12 +325,12 @@
     absReal := real abs.
     absImag := imaginary abs.
 
-    absReal >= absImag ifTrue: [ 
-        multiplicand := absReal.  
-        quotient := imaginary / real 
-    ] ifFalse: [ 
-        multiplicand := absImag.  
-        quotient := real / imaginary 
+    absReal >= absImag ifTrue: [
+	multiplicand := absReal.
+	quotient := imaginary / real
+    ] ifFalse: [
+	multiplicand := absImag.
+	quotient := real / imaginary
     ].
     ^ multiplicand * ((1 + (quotient * quotient)) sqrt)
 !
@@ -338,9 +338,9 @@
 negated
     "return a new complex with both real and imaginary parts negated"
 
-    ^ Complex 
-        real: real negated 
-        imaginary: imaginary negated
+    ^ Complex
+	real: real negated
+	imaginary: imaginary negated
 ! !
 
 !Complex methodsFor:'coercing'!
@@ -359,11 +359,11 @@
     "raises an error - complex numbers are not well ordered"
 
     ^ Number
-        raise: #unorderedSignal
-        receiver: self
-        selector: #<
-        arg: aNumber
-        errorString: 'Complex numbers are not well ordered'
+	raise: #unorderedSignal
+	receiver: self
+	selector: #<
+	arg: aNumber
+	errorString: 'Complex numbers are not well ordered'
 
     "
      1 < (2 % 2)
@@ -375,7 +375,7 @@
     "return true, if the argument represents the same numeric value
      as the receiver, false otherwise."
 
-    ^ aNumber equalFromComplex:self    
+    ^ aNumber equalFromComplex:self
 !
 
 hash
@@ -384,7 +384,7 @@
     ^ (real hash) bitXor:(imaginary hash bitShift:16)
 
     "
-     (1+0i) hash 
+     (1+0i) hash
      (1+1i) hash
     "
 ! !
@@ -400,19 +400,19 @@
 asFloat
     imaginary = 0 ifTrue: [^ real asFloat].
     ^ Number
-            raise: #coercionErrorSignal
-            receiver: self
-            selector: #asFloat
-            errorString: 'Can''t coerce an instance of Complex to a Float'
+	    raise: #coercionErrorSignal
+	    receiver: self
+	    selector: #asFloat
+	    errorString: 'Can''t coerce an instance of Complex to a Float'
 !
 
 asInteger
     imaginary = 0 ifTrue: [^real asInteger].
     ^ Number
-        raise: #coercionErrorSignal
-        receiver: self
-        selector: #asInteger
-        errorString: 'Can''t coerce an instance of Complex to an Integer'
+	raise: #coercionErrorSignal
+	receiver: self
+	selector: #asInteger
+	errorString: 'Can''t coerce an instance of Complex to an Integer'
 !
 
 asPoint
@@ -422,13 +422,13 @@
 !
 
 reduceGeneralityIfPossible
-    "Answer the receiver transformed to a lower generality, if such a 
-     transformation is possible without losing information. 
+    "Answer the receiver transformed to a lower generality, if such a
+     transformation is possible without losing information.
      If not, answer the receiver"
 
     imaginary isZero
-        ifTrue: [^ real]
-        ifFalse: [^ self]
+	ifTrue: [^ real]
+	ifFalse: [^ self]
 ! !
 
 !Complex methodsFor:'double dispatching'!
@@ -456,8 +456,8 @@
     ^ Complex real:r imaginary:imaginary negated
 
     "
-     (1 % 1) - 1.0 
-     1.0 - (1 % 1) 
+     (1 % 1) - 1.0
+     1.0 - (1 % 1)
     "
 !
 
@@ -478,7 +478,7 @@
     ^ real = aFloat
 !
 
-productFromComplex:aComplex 
+productFromComplex:aComplex
     "Return the product of the receiver and the argument, aComplex."
 
     | u v r i |
@@ -505,8 +505,8 @@
     ^ Complex real:r imaginary:i
 
     "
-     (1 % 1) * 2.0 
-     (1 % 1) * 0.0 
+     (1 % 1) * 2.0
+     (1 % 1) * 0.0
      2.0 * (1 % 1)
     "
 !
@@ -519,7 +519,7 @@
     ^ anInteger asComplex * self
 !
 
-quotientFromComplex:aComplex 
+quotientFromComplex:aComplex
     "Return the quotient of the argument, aComplex and the receiver."
 
     | denom nr ni r i |
@@ -533,23 +533,23 @@
     ^ Complex real:r imaginary:i
 
 "/ is the stuff below better ?
-"/    "Implement complex division (a + ib) / (c + id).  
+"/    "Implement complex division (a + ib) / (c + id).
 "/     Due to double dispatch, in this routine
 "/        self = (c + id) and aComplex = (a + ib)."
 "/
 "/    | quotient denominator |
 "/
 "/    self realPart abs >= (self imaginaryPart abs)
-"/        ifTrue: [ 
+"/        ifTrue: [
 "/            quotient := self imaginaryPart / self realPart.
 "/            denominator := self realPart + (self imaginaryPart * quotient).
-"/            ^ Complex 
+"/            ^ Complex
 "/                real: (aComplex realPart + (aComplex imaginaryPart * quotient)) / denominator
 "/                imaginary: (aComplex imaginaryPart - (aComplex realPart * quotient)) / denominator ]
-"/        ifFalse: [ 
+"/        ifFalse: [
 "/            quotient := self realPart / self imaginaryPart.
 "/            denominator := (self realPart * quotient) + self imaginaryPart.
-"/            ^ Complex 
+"/            ^ Complex
 "/                real: ((aComplex realPart * quotient) + aComplex imaginaryPart) / denominator
 "/                imaginary: ((aComplex imaginaryPart * quotient) - aComplex realPart) / denominator ]
 !
@@ -572,7 +572,7 @@
     ^ anInteger asComplex / self
 !
 
-sumFromComplex:aComplex 
+sumFromComplex:aComplex
     "Return the sum of the receiver and the argument, aComplex."
 
     | r i |
@@ -595,8 +595,8 @@
     ^ Complex real:r imaginary:imaginary
 
     "
-     (1 % 1) + 1.0  
-     1.0 + (1 % 1)  
+     (1 % 1) + 1.0
+     1.0 + (1 % 1)
     "
 !
 
@@ -614,10 +614,10 @@
     "Return the radian angle for this Complex number."
 
     real < 0 ifTrue: [
-        imaginary < 0 ifTrue: [
-            ^ (imaginary / real) arcTan - Float pi
-        ].
-        ^ Float pi + (imaginary / real) arcTan
+	imaginary < 0 ifTrue: [
+	    ^ (imaginary / real) arcTan - Float pi
+	].
+	^ Float pi + (imaginary / real) arcTan
     ].
     ^ (imaginary / real) arcTan
 
@@ -637,25 +637,25 @@
 
     | w quotient absReal absImag |
 
-    ((real = 0) and: [ imaginary = 0 ]) ifTrue: [ 
-        ^ Complex zero 
+    ((real = 0) and: [ imaginary = 0 ]) ifTrue: [
+	^ Complex zero
     ].
     absReal := real abs.
     absImag := imaginary abs.
 
-    absReal >= absImag ifTrue:[ 
-        quotient := imaginary / real.
-        w := (absReal sqrt) * (((1 + (1 + (quotient * quotient)) sqrt) / 2) sqrt) 
-    ] ifFalse: [ 
-        quotient := real / imaginary.
-        w := (absImag sqrt) * (((quotient abs + (1 + (quotient * quotient)) sqrt) / 2) sqrt) 
+    absReal >= absImag ifTrue:[
+	quotient := imaginary / real.
+	w := (absReal sqrt) * (((1 + (1 + (quotient * quotient)) sqrt) / 2) sqrt)
+    ] ifFalse: [
+	quotient := real / imaginary.
+	w := (absImag sqrt) * (((quotient abs + (1 + (quotient * quotient)) sqrt) / 2) sqrt)
     ].
 
-    real >= 0 ifTrue:[ 
-        ^ Complex real: w imaginary: (imaginary / (2 * w)) 
+    real >= 0 ifTrue:[
+	^ Complex real: w imaginary: (imaginary / (2 * w))
     ].
-    imaginary >= 0 ifTrue: [ 
-        ^ Complex real: absImag / (2 * w) imaginary: w 
+    imaginary >= 0 ifTrue: [
+	^ Complex real: absImag / (2 * w) imaginary: w
     ].
     ^ Complex real: absImag / (2 * w) imaginary: -1 * w
 !
@@ -671,11 +671,11 @@
     ^ Complex real: u imaginary: v
 
     "
-     -4 asComplex sqrt   
-     4 asComplex sqrt   
+     -4 asComplex sqrt
+     4 asComplex sqrt
     "
     "
-     -4 asComplex sqrt squared 
+     -4 asComplex sqrt squared
     "
 ! !
 
@@ -685,8 +685,8 @@
     aStream nextPut: $(.
     self realPart printOn: aStream.
     self imaginaryPart >= 0
-        ifTrue: [ aStream nextPut: $+ ]
-        ifFalse: [ aStream nextPut: $- ].
+	ifTrue: [ aStream nextPut: $+ ]
+	ifFalse: [ aStream nextPut: $- ].
     self imaginaryPart abs printOn: aStream.
     aStream nextPutAll: 'i)'
 
@@ -734,7 +734,7 @@
 !
 
 isZero
-    "Answer whether 'self = self class zero'.  
+    "Answer whether 'self = self class zero'.
      We can't use #= because #= is defined in terms of #isZero"
 
     ^real isZero and: [imaginary isZero]
@@ -764,5 +764,5 @@
 !Complex class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Complex.st,v 1.13 2006-02-17 12:01:59 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Complex.st,v 1.14 2011-08-04 20:46:43 cg Exp $'
 ! !