[Oberon] Understanding ORS.Mod.txt
Jörg Straube
joerg.straube at iaeth.ch
Mon Jun 13 08:59:01 CEST 2016
Srinivas
The algorithm bases on the binary representation of variable „e“.
In your example „e" is 5 (= „101“ in binary). The WHILE loops over all bits in „e“ starting with LSB and going up to the highest „1“ set in „e“.
The statement IF ODD(e) is true for all „1“ set in „e".
While looping the variable „t" is 10^1, 10^2, 10^4, 10^8, 10^16 and 10^32.
10^5 = 10^(4+1) = 10^4 * 10^1.
br
Jörg
> Am 12.06.2016 um 17:34 schrieb Srinivas Nayak <sinu.nayak2001 at gmail.com>:
>
> Hmmm...
>
> I feel...while invoking Ten(), if e=5 (say),
> then immediately inside WHILE,
> IF ODD(e) THEN x := t * x END ;
> will be executed and x will hold a value 10.
>
> After that e will never be ODD.
> So t will gather the value 10000.
>
> While returning, we should multiply x to t resulting 100000.
>
> Please correct me.
>
>
> With thanks and best regards,
>
> Yours sincerely,
> Srinivas Nayak
>
> Home: http://www.mathmeth.com/sn/
> Blog: http://srinivas-nayak.blogspot.in/
>
> On 06/12/2016 08:48 PM, John R. Strohm wrote:
>> "RETURN x" is correct.
>>
>> On exit from the loop, e = 0. (Strictly, x <= 0, but DIV preserves the sign of the dividend, so it is not possible for e to go negative.)
>>
>> On the pass immediately before exiting from the loop, e = 1. ODD(1) is TRUE, so x := t * x will be executed in that pass.
>>
>> -----Original Message----- From: Srinivas Nayak
>> Sent: Sunday, June 12, 2016 8:41 AM
>> To: ETH Oberon and related systems
>> Subject: [Oberon] Understanding ORS.Mod.txt
>>
>> We see
>>
>> PROCEDURE Ten(e: LONGINT): REAL;
>>
>> VAR x, t: REAL;
>>
>> BEGIN x := 1.0; t := 10.0;
>>
>> WHILE e > 0 DO
>>
>> IF ODD(e) THEN x := t * x END ;
>>
>> t := t * t; e := e DIV 2
>>
>> END ;
>>
>> RETURN x
>>
>> END Ten;
>>
>> Should it be, RETURN x * t ?
>>
>>
>> With thanks and best regards,
>>
>> Yours sincerely,
>> Srinivas Nayak
>>
>> Home: http://www.mathmeth.com/sn/
>> Blog: http://srinivas-nayak.blogspot.in/
>>
>> On 06/12/2016 07:01 PM, Srinivas Nayak wrote:
>>> Dear Friends,
>>>
>>> Finally I could gather my courage to read NW's compiler implementation.
>>> Hope to get your help when I get doubts.
>>>
>>> In ORS.Mod.txt we see
>>>
>>> PROCEDURE Mark*(msg: ARRAY OF CHAR);
>>>
>>> VAR p: LONGINT;
>>>
>>> BEGIN p := Pos();
>>>
>>> IF (p > errpos) & (errcnt < 25) THEN
>>>
>>> Texts.WriteLn(W); Texts.WriteString(W, " pos "); Texts.WriteInt(W, p, 1); Texts.Write(W, " ");
>>>
>>> Texts.WriteString(W, msg); Texts.Append(Oberon.Log, W.buf)
>>>
>>> END ;
>>>
>>> INC(errcnt); errpos := p + 4
>>>
>>> END Mark;
>>>
>>> Why we did, errpos := p + 4 ?
>>> How do I understand/interpret this?
>>> I was thinking, it should be errpos := p + 1 ...
>>> Kindly correct me.
>>>
>>>
>>> With thanks and best regards,
>>>
>>> Yours sincerely,
>>> Srinivas Nayak
>>>
>>> Home: http://www.mathmeth.com/sn/
>>> Blog: http://srinivas-nayak.blogspot.in/
>> --
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
>>
>> --
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3583 bytes
Desc: not available
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20160613/45704e24/attachment.p7s>
More information about the Oberon
mailing list