IntInf and word operations

Stephen Weeks sweeks@intertrust.com
Fri, 22 Sep 2000 19:08:56 -0700 (PDT)


> Sorry  about  the  fromLargeInt  problem.   I  forgot that IntInf.toInt would
> overflow.  Here is one that is correct, but slow:
> 
>     fun fromLargeInt (i: IntInf.int): Word.word =
>            let val low32 = IntInf.mod (i, 4294967296)       (* should be 1<<32 *)
>            in if low32 >= 2147483648                        (* should be 1<<31 *)
>                  then Word.fromInt (IntInf.toInt (low32 - 4294967296))
>                  else Word.fromInt (IntInf.toInt low32)
>            end

Is the following definition for Word8.fromLargeInt correct?

structure Word8 =
   struct
     ...

     fun fromLargeInt (i: IntInf.int): word =
	fromInt (IntInf.toInt (IntInf.mod (i, 256)))
   end