1 let () = Random.self_init ();;
5 fst (List.fold_left (fun (ok, i) (b,m) ->
6 let above_maxp = 1 lsl i in
7 let maxp = pred above_maxp in
8 let minp = - (above_maxp lsr 1) in
9 let below_minp = pred minp in
11 try ignore (b maxp); true
14 try ignore (b above_maxp); false
17 try ignore (b minp); true
20 try ignore (b below_minp); false
25 let plage = Int32.shift_left 1l i in
28 Int32.to_int ( Int32.add (Random.int32 plage) (Int32.of_int minp) ) in
29 let bits = b signed_number in
30 let number' = m bits in
31 if signed_number = number' then true
34 Printf.printf "bits:%d n=%d read=%d (%d %d)\n" i signed_number number' minp maxp;
38 for i = 1 to 10_000 do
39 res := !res && test ()
43 (gut && gut2 && gut3 && gut4 && gut5 && ok, succ i)
48 (fun n -> BITSTRING { n : 9 : signed }),
49 (fun b -> bitmatch b with { n: 9 : signed } -> n);
50 (fun n -> BITSTRING { n : 10 : signed }),
51 (fun b -> bitmatch b with { n : 10 : signed } -> n);
52 (fun n -> BITSTRING { n : 11 : signed }),
53 (fun b -> bitmatch b with { n : 11 : signed } -> n);
54 (fun n -> BITSTRING { n : 12 : signed }),
55 (fun b -> bitmatch b with { n : 12 : signed } -> n);
56 (fun n -> BITSTRING { n : 13 : signed }),
57 (fun b -> bitmatch b with { n : 13 : signed } -> n);
58 (fun n -> BITSTRING { n : 14 : signed }),
59 (fun b -> bitmatch b with { n : 14 : signed } -> n);
60 (fun n -> BITSTRING { n : 15 : signed }),
61 (fun b -> bitmatch b with { n : 15 : signed } -> n);
62 (fun n -> BITSTRING { n : 16 : signed }),
63 (fun b -> bitmatch b with { n : 16 : signed } -> n);
64 (fun n -> BITSTRING { n : 17 : signed }),
65 (fun b -> bitmatch b with { n : 17 : signed } -> n);
66 (fun n -> BITSTRING { n : 18 : signed }),
67 (fun b -> bitmatch b with { n : 18 : signed } -> n);
68 (fun n -> BITSTRING { n : 19 : signed }),
69 (fun b -> bitmatch b with { n : 19 : signed } -> n);
70 (fun n -> BITSTRING { n : 20 : signed }),
71 (fun b -> bitmatch b with { n : 20 : signed } -> n);
72 (fun n -> BITSTRING { n : 21 : signed }),
73 (fun b -> bitmatch b with { n : 21 : signed } -> n);
74 (fun n -> BITSTRING { n : 22 : signed }),
75 (fun b -> bitmatch b with { n : 22 : signed } -> n);
76 (fun n -> BITSTRING { n : 23 : signed }),
77 (fun b -> bitmatch b with { n : 23 : signed } -> n);
78 (fun n -> BITSTRING { n : 24 : signed }),
79 (fun b -> bitmatch b with { n : 24 : signed } -> n);
80 (fun n -> BITSTRING { n : 25 : signed }),
81 (fun b -> bitmatch b with { n : 25 : signed } -> n);
82 (fun n -> BITSTRING { n : 26 : signed }),
83 (fun b -> bitmatch b with { n : 26 : signed } -> n);
84 (fun n -> BITSTRING { n : 27 : signed }),
85 (fun b -> bitmatch b with { n : 27 : signed } -> n);
86 (fun n -> BITSTRING { n : 28 : signed }),
87 (fun b -> bitmatch b with { n : 28 : signed } -> n);
88 (fun n -> BITSTRING { n : 29 : signed }),
89 (fun b -> bitmatch b with { n : 29 : signed } -> n);
90 (fun n -> BITSTRING { n : 30 : signed }),
91 (fun b -> bitmatch b with { n : 30 : signed } -> n);
97 if Sys.word_size = 32 then
99 ignore (BITSTRING { max_int : 31 : signed });
100 ignore (BITSTRING { min_int : 31 : signed });
104 ignore (BITSTRING { pred (1 lsl 31) : 31 : signed });
105 ignore (BITSTRING { (-1 lsl 30) : 31 : signed });
116 if Sys.word_size = 64 then
118 ignore (BITSTRING { 1 lsl 31 : 31 : signed });
119 ignore (BITSTRING { pred (-1 lsl 30) : 31 : signed });
128 failwith("t141_signed_int_limits: failed")
131 (* Manquent les tests random pour bits = 31 *)