[M3devel] TInt/TWord/m3back
Jay K
jay.krell at cornell.edu
Fri Feb 26 00:18:38 CET 2010
Ok, I think maybe I should go back to the version where the type carries precision and each function is a small wrapper over TInt where I extend, call TInt, and then checked truncate.
Or at least call TInt and checked truncate, maybe no need for extend.
Something like that.
That will still leave the hard work in TInt.
I had hoped TInt could do "everything" for me.
It is a little disappointing -- it was for doing "target math", which is what I want, but now it is just for doing 64bit math on any host. Probably should be called Int64..
On the other hand, m3back historically just did host INTEGER math, no overflow checks. So maybe ok asis.
Adding the overflow checks found overflow in user source though, so I think a good thing.
I'll probably just go back a day or so, as described, where each function in M3BackInt/M3BackWord is about one line. No need for th TInt/TWord changes then, even though they were acceptable.
- Jay
From: hosking at cs.purdue.edu
Date: Thu, 25 Feb 2010 12:20:49 -0500
To: jay.krell at cornell.edu
CC: m3devel at elegosoft.com
Subject: Re: [M3devel] TInt/TWord/m3back
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/c27772f2/attachment-0002.html>
More information about the M3devel
mailing list