Implicit type conversion: Difference between revisions

m
m (→‎{{header|REXX}}: reformatted the comment box.)
Line 516:
<lang Oforth>100 Number Class newPriority: Complex(re, im)
Complex method: re { @re };
Complex method: im { @im };
Complex method: initialize { := reim := imre };
Complex method: << { '(' <<c @re << ',' <<c @im << ')' <<c } ;
Integer method: asComplex { Complex new(self, 0) };
Float method: asComplex { Complex new(self, 0) };
 
Complex new(0, 1) Constant new: I
 
Complex method: ==(c) { c re @re == c im @im == and };
Complex method: norm { @re sq @im sq + sqrt };
Complex method: conj { Complex new(@re, @im neg) };
Complex method: +(c) { Complex new(c re @re +, c im @im +) };
Complex method: -(c) { Complex new(c re @re -, c im @im -) };
Complex method: *(c) { Complex new(c re @re * c im @im * -, c re @im * @re c im * + ) };
 
Complex method: inv
{
| n |
@re sq @im sq + asFloat ->n
Complex new(@re n /, @im neg n / ) ;
 
}
Complex method: /(c) { c self inv * };</lang>
 
Usage :
1,015

edits