Source

ocaml-bicycle / complex.ml

Full commit
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;;