Re: [BLACKBOX] Type transfer

From: [at]} <Chris>
Date: Sat, 15 Oct 2011 11:15:49 +1030

----boundary-LibPST-iamunique-173227800_-_-
Content-type: text/plain

________________________________

        From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
Dorta
        Sent: Saturday, 15 October 2011 10:29 AM
        To: BLACKBOX{([at]})nowhere.xy
        Subject: Re: [BLACKBOX] Type transfer
        
        
        In my mind it is:
        VAR i: INTEGER; r: REAL;
        ... r:= i ...


So far so good ...

The problem comes (as in Robert's example) when the right-hand-side (RHS) of
the statement is an expression e.g.

  r := i * i;

If CP was to decide that because LHS is a REAL it should convert all
operands on the RHS to REAL first then Robert might not have needed to ask
the question. Instead because both of the operands on the RHS are INTEGER,
CP calculates i * i as an INTEGER expression first and *then* converts it to
a REAL. That is why the *INTEGER* overflow problem might arise.

I haven't tested them so I cannot be certain (that is the problem) but as
far as I can see, your earlier suggestion should be no more likely to result
in an overflow than Float(n) * n

 r := n;
 r := r * r;

or

 r := n;
 r := r * n;

However, it is all to easy for programmers to overlook or not fully
comprehend the subtleties that apply here. In the most recent (Sept 2011)
revision of Oberon Wirth has reverted back to the use of type transfer /
conversion functions FLOOR, FLT, LONG, SHORT etc. presumably to make these
sorts of type conversions more explicit.
 
  r := FLT(n) * n;

is not even permitted. You would have to write:

  r := FLT(n) * FLT(n);

While it is more wordy there should be no possible confusion as to what the
writer's intentions were.

Regards,
Chris

Chris Burrows
CFB Software
Astrobe v3.4: ARM Oberon Development System
http://www.astrobe.com


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-173227800_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdX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gT2Jlcm9uIFdpcnRoIGhh
cyByZXZlcnRlZCBiYWNrIHRvIHRoZSB1c2Ugb2YgdHlwZSB0cmFuc2ZlciAvXHBhcg0KY29udmVy
c2lvbiBmdW5jdGlvbnMgRkxPT1IsIEZMVCwgTE9ORywgU0hPUlQgZXRjLiBwcmVzdW1hYmx5IHRv
IG1ha2UgdGhlc2VccGFyDQpzb3J0cyBvZiB0eXBlIGNvbnZlcnNpb25zIG1vcmUgZXhwbGljaXQu
XHBhcg0KIFxwYXINCiAgciA6PSBGTFQobikgKiBuO1xwYXINClxwYXINCmlzIG5vdCBldmVuIHBl
cm1pdHRlZC4gWW91IHdvdWxkIGhhdmUgdG8gd3JpdGU6XHBhcg0KXHBhcg0KICByIDo9IEZMVChu
KSAqIEZMVChuKTtccGFyDQpccGFyDQpXaGlsZSBpdCBpcyBtb3JlIHdvcmR5IHRoZXJlIHNob3Vs
ZCBiZSBubyBwb3NzaWJsZSBjb25mdXNpb24gYXMgdG8gd2hhdCB0aGVccGFyDQp3cml0ZXIncyBp
bnRlbnRpb25zIHdlcmUuXHBhcg0KXHBhcg0KUmVnYXJkcyxccGFyDQpDaHJpc1xwYXINClxwYXIN
CkNocmlzIEJ1cnJvd3NccGFyDQpDRkIgU29mdHdhcmVccGFyDQpBc3Ryb2JlIHYzLjQ6IEFSTSBP
YmVyb24gRGV2ZWxvcG1lbnQgU3lzdGVtXHBhcg0KaHR0cDovL3d3dy5hc3Ryb2JlLmNvbVxwYXIN
ClxwYXINClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0
aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hcfX0A
AAAE
----boundary-LibPST-iamunique-173227800_-_---
Received on Sat Oct 15 2011 - 02:45:49 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:10 UTC