Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 60 lines (45 sloc) 1.458 kB
4c151a9 @akoprow [feature] Int.t: introducing 64-bit integer type.
akoprow authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 #<Ifstatic:OCAML_WORD_SIZE 64>
20
21 type t = Nativeint.t
22
23 let ( + ) = Nativeint.add
24 let ( - ) = Nativeint.sub
25 let ( * ) = Nativeint.mul
26 let ( / ) = Nativeint.div
27
28 exception Overflow
29 let of_int = Nativeint.of_int
30 let to_int v =
31 let res = Nativeint.to_int v in
32 (* make sure that we don't loose the representation during the conversion *)
33 if v == of_int res then
34 res
35 else
36 raise Overflow
37
38 #<Else>
39
40 type t = Int64.t
41
42 let ( + ) = Int64.add
43 let ( - ) = Int64.sub
44 let ( * ) = Int64.mul
45 let ( / ) = Int64.div
46
47 let of_int v =
48 Int64.of_nativeint (Nativeint.of_int v)
49
50 exception Overflow
51 let to_int v =
52 let res = Nativeint.to_int (Int64.to_nativeint v) in
53 (* make sure that we don't loose the representation during the conversion *)
54 if v == of_int res then
55 res
56 else
57 raise Overflow
58
59 #<End>
Something went wrong with that request. Please try again.