[ENH] Complex (v2)

denker at iam.unibe.ch denker at iam.unibe.ch
Thu Jul 22 09:50:41 UTC 2004


from preamble:

"Change Set:		Complex
Date:			16 July 2004
Author:			Matej Kosik

md: This is just a first stab at an implementation of Complex. This will
definitly need improvements, but the base functionality is there.
 -removed Matrix, fixed undef references
 -added test class.

v2: added two methods for save devision (Boris Gaertner) and tests.

I represent a complex number.

real			--	real part of the complex number
imaginary	--	imaginary part of the complex number

Complex number constructors:

	5 i
	6 + 7 i.
	5.6 - 8 i.
	Complex real: 10 imaginary: 5.
	Complex abs: 5 arg: (Float pi / 4)

Arithmetic operation with other complex or non-complex numbers work.

	(5 - 6 i) + (-5 + 8 i).			Arithmetic between two complex numbers.
	5 * (5 - 6 i).				Arithmetic between a non-complex and a complex
number.
					
It is also possible to perform arithmetic operations between a complex
number
and a array of (complex) numbers:

	2 * {1 + 2i.
	     3 + 4i.
	     5 + 6i}

	5 + 5i * {1 + 2i.
	          3.
	          5 + 6i}

It behaves analogously as it is with normal numbers and an array.

NOTE: Although Complex something similiar to the Smalltalk's Number
class, it would
not be a good idea to make a Complex to be a subclass of a Number
because:
- Number is subclass of Magnitude and Complex is certainly not a
magnitude.
  Complex does not behave very well as a Magnitude. Operations such as
	<
	>
	<=
	>=
  do not have sense in case of complex numbers.
- Methods in the following Number methods' categories do not have sense
for a Complex numbers
	trucation and round off
	testing
	intervals
	comparing
- However the following Number methods' categories do have sense for a
Complex number
	arithmetic (with the exception of operation
		//
		\\
		quo:
		rem:	
	mathematical functions

Thus Complex is somewhat similar to a Number but it is not a subclass of
it. Some operations
we would like to inherit (e.g. #abs, #negated, #reciprocal) but some of
the Number operation
do not have sens to inherit or to overload. Classes are not always neat
mechanism.

!!!!!! We had to COPY the implementation of the
		abs
		negated
		reciprocal
		log:
		isZero
		reciprocal
		...
	methods from the Number class to the Complex class. Awful solution. Now
I begin to
	appreciate the Self.

Missing methods
	String | converting | asComplex
	Complex | mathematical functions | arcSin
	Complex | mathematical functions | arcCos
	Complex | mathematical functions | arcTan
	
"!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Complex.cs.gz
Type: application/octet-stream
Size: 4410 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040722/6db90f75/Complex.cs.obj


More information about the Squeak-dev mailing list