Source

blaise / stdlib.ml

Full commit
let call fname args = match (fname, args) with
  | ("write", _) -> List.iter (fun x -> print_int x; print_newline ()) args;
                    (Some 0)
  | ("read", []) -> Some (read_int ())
  | ("random", [a]) -> Some (Random.int a)
  | ("max", [a; b]) -> Some (max a b)
  | ("min", [a; b]) -> Some (min a b)
  | ("mod", [a; b]) -> Some (a mod b)
  | ("xor", [a; b]) -> Some (a lxor b)
  | ("succ", [a]) -> Some (succ a)
  | ("pred", [a]) -> Some (pred a)
  | ("abs", [a]) -> Some (abs a)
  | ("pow", [a;n]) -> Some (truncate ((float a) ** (float n)))
  | ("sqrt", [a]) -> Some (truncate (sqrt (float a)))
  | ("exp", [a]) -> Some (truncate (exp (float a)))
  | ("log", [a]) -> Some (truncate (log (float a)))
  | ("log10", [a]) -> Some (truncate (log10 (float a)))
  | ("cos", [a]) -> Some (truncate (cos (float a)))
  | ("sin", [a]) -> Some (truncate (sin (float a)))
  | ("tan", [a]) -> Some (truncate (tan (float a)))
  | ("acos", [a]) -> Some (truncate (acos (float a)))
  | ("asin", [a]) -> Some (truncate (asin (float a)))
  | ("atan", [a]) -> Some (truncate (atan (float a)))
  | ("cosh", [a]) -> Some (truncate (cosh (float a)))
  | ("sinh", [a]) -> Some (truncate (sinh (float a)))
  | ("tanh", [a]) -> Some (truncate (tanh (float a)))
  | ("atan2", [a;b]) -> Some (truncate (atan2 (float a) (float b)))
  | _ -> None