Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 2009 Matthew Fluet. |
2 | * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * | |
5 | * MLton is released under a BSD-style license. | |
6 | * See the file MLton-LICENSE for details. | |
7 | *) | |
8 | ||
9 | structure Int: | |
10 | sig | |
11 | include INTEGER | |
12 | ||
13 | val maxInt: t option | |
14 | val minInt: t option | |
15 | val precision: Pervasive.Int.int option | |
16 | val roundDownToPowerOfTwo: t -> t | |
17 | val roundUpToPowerOfTwo: t -> t | |
18 | val toReal: t -> real | |
19 | end = | |
20 | struct | |
21 | structure Int = Pervasive.Int | |
22 | structure I = Integer(open Int | |
23 | fun divMod(a, b) = (a div b, a mod b) | |
24 | fun quotRem(a, b) = (quot(a, b), rem(a, b)) | |
25 | val toIntInf = Pervasive.IntInf.fromInt) | |
26 | open I | |
27 | ||
28 | fun roundDownToPowerOfTwo (i: t): t = | |
29 | Word.toInt (Word.roundDownToPowerOfTwo (Word.fromInt i)) | |
30 | ||
31 | fun roundUpToPowerOfTwo (i: t): t = | |
32 | let | |
33 | val i' = roundDownToPowerOfTwo i | |
34 | in | |
35 | if i = i' | |
36 | then i | |
37 | else i' * 2 | |
38 | end | |
39 | ||
40 | type int = t | |
41 | val maxInt = Int.maxInt | |
42 | val minInt = Int.minInt | |
43 | val precision = Int.precision | |
44 | val toReal = Pervasive.Real.fromInt | |
45 | end |