package tablecloth-native

  1. Overview
  2. Docs

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
type t = int

include TableclothComparator.Make (struct
  type nonrec t = t

  let compare = compare
end)

let minimumValue = Base.Int.min_value

let minimum_value = minimumValue

let maximumValue = Base.Int.max_value

let maximum_value = maximumValue

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 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 isEven n = n mod 2 = 0

let is_even = isEven

let isOdd n = n mod 2 <> 0

let is_odd = isOdd

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 inRange 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 in_range = inRange

let toFloat = Base.Int.to_float

let to_float = toFloat

let toString = Base.Int.to_string

let to_string = toString

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

let from_string = fromString

let equal = ( = )

let compare = compare