1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
use std::io; pub fn readCom()->(f64,f64){ let mut x = String::new(); let mut y = String::new(); println!("Real Part : "); io::stdin().read_line(&mut x).expect("invalid input"); println!("Imaginary Part : "); io::stdin().read_line(&mut y).expect("invalid input"); let x :f64 = x.trim().parse().expect("invalid input"); let y :f64 = y.trim().parse().expect("invalid input"); (x,y) } pub mod Operations{ pub fn ComAdd(c1:&(f64,f64), c2:&(f64,f64))->(f64,f64){ (c1.0 + c2.0, c1.1 + c2.1) } pub fn ComSubstract(c1:&(f64,f64), c2:&(f64,f64))->(f64,f64){ (c1.0 - c2.0, c1.1 - c2.1) } pub fn ComDistance(c1:&(f64,f64), c2:&(f64,f64))->f64{ let x= c1.0 - c2.0; let y= c1.1 - c2.1; let d= x*x + y*y; d.sqrt() } pub fn ComMult(c1:&(f64,f64), c2:&(f64,f64))-> (f64, f64){ let x = (c1.0*c2.0)-(c1.1*c2.1); let y = (c1.1*c2.0)+(c1.0*c2.1); (x,y) } pub fn ComDiv(c1:&(f64,f64), c2:&(f64,f64))-> (f64, f64){ let x_num = (c1.0*c2.0)+(c1.1*c2.1); let y_num = (c1.1*c2.0)-(c1.0*c2.1); let den = c2.0*c2.0 + c2.1*c2.1; (x_num/den,y_num/den) } pub fn ComAdd_Inv(c1: &(f64,f64))->(f64,f64){ (-c1.0,-c1.1) } pub fn ComMult_Inv(c1: &(f64,f64)) ->(f64,f64){ let x_num = c1.0; let y_num = -c1.1; let den = c1.0*c1.0 + c1.1*c1.1; (x_num/den,y_num/den) } pub fn ComMod(c1: &(f64,f64))->f64{ let x = c1.0*c1.0; let y = c1.1*c1.1; let m = x+y; m.sqrt() } pub fn CompCompare(c1: &(f64,f64),c2 :&(f64,f64)){ let d1 = ComMod(c1) ; let d2 = ComMod(c2); if d1>d2 { println!("{:?} is greater than {:?}.",c1,c2); } else if d2>d1 { println!("{:?} is greater than {:?}.",c2,c1); } else { println!("{:?} is equal to {:?}",c1,c2); } } }