Advertisement
Guest User

Complex Number

a guest
Jan 5th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. class Complex {
  2.   public double re,im;
  3.  
  4.   Complex(double re, double im) {
  5.     this.re = re;
  6.     this.im = im;
  7.   }
  8.  
  9.   Complex somma(Complex a, Complex b) {
  10.     return new Complex(a.re + b.re, a.im + b.im);
  11.   }
  12.  
  13.   Complex prodotto(Complex a, Complex b) {
  14.     return new Complex(a.re * b.re - a.im * b.im, (a.re * b.im + a.im * b.re));
  15.   }
  16.  
  17.   double abs() {
  18.     return re*re + im*im;
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement