[M3devel] TInt/TWord/m3back
Tony Hosking
hosking at cs.purdue.edu
Thu Feb 25 18:20:49 CET 2010
This all speaks to your trying to use TInt for purposes it was never intended. It is there in support of the compiler front-end not compiler back-ends.
On 25 Feb 2010, at 08:24, Jay K wrote:
> Tony, it should now be much closer to your intent.
> I grant maybe the constants are misplaced, and I should try again to use ToBytes.
>
>
> I'm worried though.
> It used to be I could do:
>
>
> TInt.Add(Int{4,FF,FF,FF,7}, One)
> and be told it overflowed, in 4 bytes of precision.
You must check explicitly that there is no overflow. This is easy enough.
TInt.LT(result, Target.Int32.min) OR TInt.LT(Target.Int32.max, result)
> Now it'll just do it in 8 and no overflow.
>
>
> And chop always succeeds.
>
> Maybe:
>
>
> PROCEDURE CheckChop (VAR r: Int; n: CARDINAL) =
> BEGIN
> IF And (r [n-1], SignMask) = 0
> THEN FOR i := n TO LAST(Int) DO IF r [i] # 0 THEN RETURN FALSE END; END;
> ELSE FOR i := n TO LAST(Int) DO IF r [i] # Mask THEN RETURN FALSE END; END;
> END;
> RETURN TRUE;
> END CheckChop;
>
> ?
>
> - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100225/e8eb806f/attachment-0002.html>
More information about the M3devel
mailing list