(* int-lit.sml * * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) * * COPYRIGHT (c) 2015 The University of Chicago * All rights reserved. *) structure IntLit :> sig type t = IntInf.int val fromInt : int -> t (* arithmetic *) val add : t * t -> t val sub : t * t -> t val mul : t * t -> t val divide : t * t -> t val modulo : t * t -> t val neg : t -> t (* range checks *) val isInt32 : t -> bool (* representable in 32-bits *) val isInt64 : t -> bool (* representable in 64-bits *) (* equality, comparisons, and hashing functions *) val same : (t * t) -> bool val compare : (t * t) -> order val hash : t -> word val toString : t -> string end = struct type t = IntInf.int val fromInt = IntInf.fromInt (* arithmetic *) val add = IntInf.+ val sub = IntInf.- val mul = IntInf.* val divide = IntInf.quot val modulo = IntInf.rem val neg = IntInf.~ (* range checks *) fun isInt32 (n : IntInf.int) = (~0x80000000 <= n) andalso (n < 0x100000000) fun isInt64 (n : IntInf.int) = (~0x8000000000000000 <= n) andalso (n < 0x10000000000000000) (* equality, comparisons, and hashing functions *) fun same (a : IntInf.int, b) = (a = b) val compare = IntInf.compare fun hash i = Word.fromInt(IntInf.toInt(IntInf.andb(i, 0xfffffff))) fun toString i = if (i < 0) then "-" ^ IntInf.toString(IntInf.~ i) else IntInf.toString i end
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: n toString i = if (i < 0) then "-" ^ IntInf.toString(IntInf.~ i) else IntInf.toString i end