Commits

Albert Bagautdinov committed 2477894

  • Participants
  • Parent commits e0d8e46

Comments (0)

Files changed (1)

 module Complex = 
-	struct 
-		type cmpalg = float * float (* Algebraic form *)
-		type cmptrg = float * float (* Trigonametric form *)
+	struct  
+		(* Algebraic form: tuple of real and imaginary parts *)
+		type cmpalg = float * float
+		(* Trigonametric form: tuple of module and argument *)  
+		type cmptrg = float * float
+		(* Internal transforms *) 
 		let (alg2trg: cmpalg -> cmptrg) = function x ->
 			(sqrt (fst x +. snd x), atan (snd x /. fst x))
 		let (trg2alg: cmptrg -> cmpalg) = function x ->
 			(fst x *. cos (snd x), fst x *. sin (snd x))
+		(* Return of *)
+		let (real: cmpalg -> float) = function x -> fst x
+		let (imaginary: cmpalg -> float) = function x -> snd x
+		let (cmodule: cmptrg -> float) = function x -> fst x
+		let (argument: cmptrg -> float) = function x -> snd x
+		(* Algebraic operations for algebraic form;
+		 * for trigonametric form use trg2alg and alg2trg *)
 		let (sum: cmpalg -> cmpalg -> cmpalg) = fun x y ->
 			(fst x +. fst y, snd x +. snd y)
 		let (sub: cmpalg -> cmpalg -> cmpalg) = fun x y ->
 			(fst x *. fst y, snd x *. snd y)
 		let (div: cmpalg -> cmpalg -> cmpalg) = fun x y ->
 			(fst x /. fst y, snd x /. snd y)
+		(* Equality *)
+		let (equal_alg: cmpalg -> cmpalg -> bool) = fun x y ->
+		  if (fst x == fst y) && (snd x == snd y) then true else false
+		let (equal_trg: cmptrg -> cmptrg -> bool) = fun x y ->
+		  if (fst x == fst y) && (snd x == snd y) then true else false
+		let equal x y = if (fst x == fst y) && (snd x == snd y) then true else false
+		let (sopr: cmpalg -> cmpalg) = function x -> (fst x, -.(snd x))
 	end;;