csci2041/repo-zhan4854/Hwk_07/complexVector.ml

18 lines
523 B
OCaml
Raw Normal View History

2018-01-29 23:35:31 +00:00
open Vector
module Complex_arithmetic: (Arithmetic with type t = float * float) = struct
type t = float * float
let zero = (0.0, 0.0)
let str x =
match x with
| (a, b) -> "(" ^ (string_of_float a) ^ (if b >= 0.0 then "+" else "-") ^ (string_of_float (abs_float b)) ^ "i)"
let add x y =
match x, y with
| (a, b), (c, d) -> (a +. c, b +. d)
let mul x y =
match x, y with
| (a, b), (c, d) -> (a *. c -. b *. d, a *. d +. b *. c)
end
module Complex_vector = Make_vector (Complex_arithmetic)