Source file TableclothInt.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
type t = int

include TableclothComparator.Make (struct
  type nonrec t = t

  let compare = compare
end)

let minimum_value = Base.Int.min_value

let maximum_value = Base.Int.max_value

let zero = 0

let one = 1

let add = ( + )

let ( + ) = ( + )

let subtract = ( - )

let ( - ) = ( - )

let multiply = ( * )

let ( * ) = multiply

let divide n ~by = n / by

let ( / ) = ( / )

let ( /. ) = Base.Int.( // )

let divide_float ~by n = Base.Int.(n // by)

let power ~base ~exponent = Base.Int.(base ** exponent)

let ( ** ) = Base.Int.( ** )

let negate = ( ~- )

let ( ~- ) = ( ~- )

let modulo n ~by = (if n < 0 then 2 * abs n else n) mod by

let ( mod ) n by = modulo n ~by

let remainder n ~by = Base.Int.rem n by

let maximum = Base.Int.max

let minimum = Base.Int.min

let absolute n = if n < 0 then n * -1 else n

let is_even n = n mod 2 = 0

let is_odd n = n mod 2 <> 0

let clamp n ~lower ~upper =
  if upper < lower
  then
    raise
      (Invalid_argument
         ( "~lower:"
         ^ Base.Int.to_string lower
         ^ " must be less than or equal to ~upper:"
         ^ Base.Int.to_string upper ) )
  else max lower (min upper n)


let in_range n ~lower ~upper =
  if upper < lower
  then
    raise
      (Invalid_argument
         ( "~lower:"
         ^ Base.Int.to_string lower
         ^ " must be less than or equal to ~upper:"
         ^ Base.Int.to_string upper ) )
  else n >= lower && n < upper


let to_float = Base.Int.to_float

let to_string = Base.Int.to_string

let from_string str = try Some (int_of_string str) with _ -> None

let equal = ( = )

let compare = compare