summaryrefslogtreecommitdiff
path: root/testsuite/tests/basic-more/div_by_zero.ml
blob: 7cd910768e55c8f4cec9045883202d93b447e33a (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(* TEST
   include testing
*)

let check f n =
  assert (
    try ignore ((Sys.opaque_identity f) n); false with
      Division_by_zero -> true
  )

let div_int n  = n / 0
let div_int32 n = Int32.div n 0l
let div_int64 n = Int64.div n 0L
let div_nativeint n = Nativeint.div n 0n

let mod_int n  = n mod 0
let mod_int32 n = Int32.rem n 0l
let mod_int64 n = Int64.rem n 0L
let mod_nativeint n = Nativeint.rem n 0n

let div_int_opaque n  = n / (Sys.opaque_identity 0)
let div_int32_opaque n = Int32.div n (Sys.opaque_identity 0l)
let div_int64_opaque n = Int64.div n (Sys.opaque_identity 0L)
let div_nativeint_opaque n = Nativeint.div n (Sys.opaque_identity 0n)

let mod_int_opaque n  = n mod (Sys.opaque_identity 0)
let mod_int32_opaque n = Int32.rem n (Sys.opaque_identity 0l)
let mod_int64_opaque n = Int64.rem n (Sys.opaque_identity 0L)
let mod_nativeint_opaque n = Nativeint.rem n (Sys.opaque_identity 0n)

let () =
  check div_int 33;
  check div_int 0;
  check div_int32 33l;
  check div_int32 0l;
  check div_int64 33L;
  check div_int64 0L;
  check div_nativeint 33n;
  check div_nativeint 0n;

  check mod_int 33;
  check mod_int 0;
  check mod_int32 33l;
  check mod_int32 0l;
  check mod_int64 33L;
  check mod_int64 0L;
  check mod_nativeint 33n;
  check mod_nativeint 0n;

  check div_int_opaque 33;
  check div_int_opaque 0;
  check div_int32_opaque 33l;
  check div_int32_opaque 0l;
  check div_int64_opaque 33L;
  check div_int64_opaque 0L;
  check div_nativeint_opaque 33n;
  check div_nativeint_opaque 0n;

  check mod_int_opaque 33;
  check mod_int_opaque 0;
  check mod_int32_opaque 33l;
  check mod_int32_opaque 0l;
  check mod_int64_opaque 33L;
  check mod_int64_opaque 0L;
  check mod_nativeint_opaque 33n;
  check mod_nativeint_opaque 0n;
  ()

let () =
  print_endline "***** OK *****"