Commits

Albert Bagautdinov committed 34de126

Add simple implementation of complex numbers

  • Participants
  • Parent commits 93abc63

Comments (0)

Files changed (1)

+module Complex = 
+	struct 
+		type cmpalg = float * float (* Algebraic form *)
+		type cmptrg = float * float (* Trigonametric form *)
+		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))
+		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 (mul: 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)
+	end;;