Bert Freudenberg, replying to me on Wed, 20 Apr:
Someone must have been there before; Number currently accepts an #argument message, and answers 0 or pi according to sign. I think everything that knows its modulus and argument should know its real and imaginary parts.
That would be trivial to add to Number.
See changeset below.
What else do you think is missing?
That's all I've found so far. In my image, I'll add anything whose absence requires me to write "+0i".
I found that, tried it, and got sick of saying "0 asComplex" in about two minutes.
So why don't you write 0i instead of "0 asComplex"?
It was actually "z asComplex" in the method "foo:", so that "foo: 0" would work. I think "foo: 0i" looks tricky.
Rodney
'From Squeak4.2 of 4 February 2011 [latest update: #10966] on 3 May 2011 at 1:03:49 pm'!
!Number methodsFor: 'arithmetic' stamp: 'RESP 4/19/2011 11:23'! imaginary "Answer the imaginary part of the receiver (see Complex | imaginary)." ^ self * 0! !
!Number methodsFor: 'arithmetic' stamp: 'RESP 4/19/2011 11:22'! real "Answer the real part of the receiver (see Complex | real)." ^ self! !
!TestCase methodsFor: 'accessing' stamp: 'RESP 4/19/2011 11:49'! assert: aValue fixedPointOf: aMethod
aValue = (aValue perform: aMethod) ifFalse: [self signalFailure: 'Assertion failed'].
! !
!ComplexTest methodsFor: 'tests' stamp: 'RESP 5/3/2011 13:02'! testCreation "self run: #testCreation" | c | c := 5 i. self assert: (c real = 0). self assert: (c imaginary = 5). c := 6 + 7 i. self assert: (c real = 6). self assert: ( c imaginary = 7). c := 5.6 - 8 i. self assert: (c real = 5.6). self assert: (c imaginary = -8). c := Complex real: 10 imaginary: 5. self assert: (c real = 10). self assert: (c imaginary = 5). c := Complex abs: 5 arg: (Float pi/2). self assert: (c real rounded = 0). self assert: (c imaginary = 5). "The real and imaginary methods work, for negative, zero, and positive Numbers of all kinds." "Float" self assert: 0.0 fixedPointOf: #real. self assert: 0.0 imaginary = 0. self assert: Float pi fixedPointOf: #real. self assert: Float pi imaginary = 0. self assert: Float pi negated fixedPointOf: #real. self assert: Float pi negated imaginary = 0. "Fraction" self assert: (2/5) fixedPointOf: #real. self assert: (2/5) imaginary = 0. self assert: (-2/5) fixedPointOf: #real. self assert: (-2/5) imaginary = 0. "SmallInteger" self assert: 0 fixedPointOf: #real. self assert: 0 imaginary = 0. self assert: 42 fixedPointOf: #real. self assert: 42 imaginary = 0. self assert: -42 fixedPointOf: #real. self assert: -42 imaginary = 0. "LargePositiveInteger" self assert: ((2 raisedTo: 100) isMemberOf: LargePositiveInteger). self assert: (2 raisedTo: 100) fixedPointOf: #real. self assert: (2 raisedTo: 100) imaginary = 0. "LargeNegativeInteger" self assert: ((2 raisedTo: 100) negated isMemberOf: LargeNegativeInteger). self assert: (2 raisedTo: 100) negated fixedPointOf: #real. self assert: (2 raisedTo: 100) negated imaginary = 0. ! !
squeak-dev@lists.squeakfoundation.org