Source file complexp.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
open Types
open Errors
open Typecheck

let realpart args =
  let x = match args with
    | [|x|] -> unpack_complex x
    | _ -> iraise WrongPrimitiveArgs in
  EvtFloat(x.re)

let imagpart args =
  let x = match args with
    | [|x|] -> unpack_complex x
    | _ -> iraise WrongPrimitiveArgs in
  EvtFloat(x.im)

let conj args =
  let x = match args with
    | [|x|] -> unpack_complex x
    | _ -> iraise WrongPrimitiveArgs in
  EvtComplex(Complex.conj x)

let inv args =
  let x = match args with
    | [|x|] -> unpack_complex x
    | _ -> iraise WrongPrimitiveArgs in
  EvtComplex(Complex.inv x)

let of_polar args =
  let x, y = match args with
    | [|x; y|] -> unpack_float x, unpack_float y;
    | _ -> iraise WrongPrimitiveArgs in
  EvtComplex(Complex.polar x y)


let table = [
  ("real", Primitive (realpart, ("real", [|"num"|], Numerical)));
  ("imag", Primitive (imagpart, ("imag", [|"num"|], Numerical)));
  ("conj", Primitive (conj, ("conj", [|"num"|], Numerical)));
  ("inv", Primitive (inv, ("inv", [|"num"|], Numerical)));
]