csci2041/repo-zhan4854/Hwk_07/complexVector.ml
Michael Zhang 399845160c
f
2018-01-29 17:35:31 -06:00

17 lines
523 B
OCaml

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)