File: intern.ml

package info (click to toggle)
ocaml-zarith 1.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: ansic: 2,998; ml: 2,767; sh: 288; makefile: 81
file content (24 lines) | stat: -rw-r--r-- 545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(* Unmarshal big integers from the given file, and report errors *)

open Printf

let expect ic n =
  try
    let m = (input_value ic : Z.t) in
    if Z.equal m n then printf " OK" else printf " Wrong"
  with Failure _ ->
    printf " Fail"

let _ =
  let file = Sys.argv.(1) in
  let ic = open_in_bin file in
  for nbits = 16 to 128 do
    printf "%d:" nbits;
    let x = Z.shift_left Z.one nbits in
    expect ic (Z.pred (Z.neg x));
    expect ic (Z.neg x);
    expect ic (Z.pred x);
    expect ic x;
    print_newline()
  done;
  close_in ic