I want a method called Cosine that I can send anything to.


No, you want cos implemented on Number in the usual way (and it already is) and you want a ComplexNumber class that has your different implementation. Then you don't care which is which.

There's a nice complex number implementation at [link|http://minnow.cc.gatech.edu/squeak/1964|http://minnow.cc.gatech.edu/squeak/1964] for Squeak. Just add a cos method to it that does what you want and you're in business.

like this:

cos
^((real cos) * (imaginary cosh)) + ((real sin)*(imaginary sinh))

The other hassle is you'll need to implement cosh and sinh, they don't seem to be there. Not too hard. There's a constant for E defined. So implement these on float:

cosh
^((E raisedTo: self) + (E raisedTo: (self negated))/2

sinh
^((E raisedTo: self) - (E raisedTo: (self negated))/2


and add more generic ones on Number:

cosh ^self asFloat cosh
sinh ^self asFloat sinh

I don't know how you implement these on ComplexNumber. If an operation is illegal, you can always implement it as 'self shouldNotImplement' which will raise an error if its ever called. If you leave it alone then you get the implementation in Number that ignores the imaginary part.

Looking over the code - I don't much like the class side creation method on ComplexNumber. Its implemented like:

real: r imaginary: i

^self basicNew real: r imaginary: i.

But if i is zero you really want to return just the real part. I'd change it to be:

real: r imaginary: i

^(i = 0) ifFalse: [self basicNew real: r imaginary: i] ifTrue: [r].

So that ComplexNumber real: 5 imaginary: 0 is just 5. This seems to be a bottleneck method - all type promotions go through here - so even 3 i: 0 will just end up being 3.

Hope this helps