Java Reference
In-Depth Information
public
public Complex subtract ( Complex other ) {
return
return subtract ( this
this , other );
}
/** Subtract two Complexes
*/
public
public static
static Complex subtract ( Complex c1 , Complex c2 ) {
return
return new
new Complex ( c1 . r - c2 . r , c1 . i - c2 . i );
}
/** Multiply this Complex times another one
*/
public
public Complex multiply ( Complex other ) {
return
return multiply ( this
this , other );
}
/** Multiply two Complexes
*/
public
public static
static Complex multiply ( Complex c1 , Complex c2 ) {
return
return new
new Complex ( c1 . r * c2 . r - c1 . i * c2 . i , c1 . r * c2 . i + c1 . i * c2 . r );
}
/** Divide c1 by c2.
* @author Gisbert Selke.
*/
public
public static
static Complex divide ( Complex c1 , Complex c2 ) {
return
return new
new Complex (
( c1 . r * c2 . r + c1 . i * c2 . i )/( c2 . r * c2 . r + c2 . i * c2 . i ),
( c1 . i * c2 . r - c1 . r * c2 . i )/( c2 . r * c2 . r + c2 . i * c2 . i ));
}
/* Compare this Complex number with another
*/
public
public boolean
boolean equals ( Object o ) {
iif ( o . getClass () != Complex . class ) {
throw
throw new
new IllegalArgumentException (
"Complex.equals argument must be a Complex" );
}
Complex other = ( Complex ) o ;
return
return r == other . r && i == other . i ;
}
/* Generate a hashCode; not sure how well distributed these are.
*/
public
public int
int hashCode () {
return
return ( int
int )( r ) | ( int
int ) i ;
Search WWH ::




Custom Search