Home My Page Projects Code Snippets Project Openings diderot
 Summary Activity Tracker Tasks SCM

# SCM Repository

[diderot] Annotation of /trunk/src/common/integer-lit.sml
 [diderot] / trunk / src / common / integer-lit.sml

# Annotation of /trunk/src/common/integer-lit.sml

 1 : jhr 26 (* integer-lit.sml 2 : * 3 : * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) 4 : * All rights reserved. 5 : *) 6 : 7 : structure IntegerLit :> sig 8 : 9 : type integer = IntInf.int 10 : 11 : (* range checks *) 12 : val isInt : integer -> bool (* representable in 32-bits *) 13 : val isLong : integer -> bool (* representable in 64-bits *) 14 : 15 : (* equality, comparisons, and hashing functions *) 16 : val same : (integer * integer) -> bool 17 : val compare : (integer * integer) -> order 18 : val hash : integer -> word 19 : 20 : val toString : integer -> string 21 : 22 : end = struct 23 : 24 : type integer = IntInf.int 25 : 26 : (* range checks *) 27 : fun isInt (n : IntInf.int) = 28 : (~0x80000000 <= n) andalso (n < 0x100000000) 29 : fun isLong (n : IntInf.int) = 30 : (~0x8000000000000000 <= n) andalso (n < 0x10000000000000000) 31 : 32 : (* equality, comparisons, and hashing functions *) 33 : fun same (a : IntInf.int, b) = (a = b) 34 : val compare = IntInf.compare 35 : fun hash i = Word.fromInt(IntInf.toInt(IntInf.andb(i, 0xfffffff))) 36 : 37 : fun toString i = if (i < 0) 38 : then "-" ^ IntInf.toString(IntInf.~ i) 39 : else IntInf.toString i 40 : 41 : end

 root@smlnj-gforge.cs.uchicago.edu ViewVC Help Powered by ViewVC 1.0.0