Hi all,
Recently when looking into seemingly wrong output of my code for Texts.WriteReal and Texts.WriteRealFix I discovered that Project Oberon RISC5 floating point multiplication gives wrong results for certain selected values.
Specifically when multiplying a number containing the digits of a whole power of 2 by a whole power of 10 sometimes results in *half* the value of the right result; this only occurs when the result is (the REAL representation of) an exact whole power of 2; but puzzlingly in some of these cases the error is not produced.
E.g.:
100.0 * 2.56 results in 1.280000E+02 = 128.0 (encoded ('raw') hexadecimal integer value: 43000000H)
The right result of this multiplication (2.560000E+02) in hex is 43800000H
1.0E5 * 1.31072 results in 6.553600E+04 = 65536.0 (encoded ('raw') hexadecimal integer value: 47800000H)
The right result of this multiplication (131072.0) in hex is 48000000H
1.0E6 * 1.048576 results in 5.242880E+05 = 524288.0 (encoded ('raw') hexadecimal integer value: 49000000H)
The right result of this multiplication (1048576.0) in hex is 49800000H
But in the following similar case the right result is produced:
1.0E3 * 8.192 results in 8.192000 = 8192.0 (encoded ('raw') hexadecimal integer value: 46000000H)
You can verify the integer encodings for IEEE 754 floating point values on the following web page:
https://float.exposed (click on 'float' (not on 'double'), paste the hex value (without trailing H) into the field 'Raw Hexadecimal Integer Value' and then press Enter).
That these wrong results are not explained by wrong output of Texts.WriteReal is indicated by the hexadecimal encoded results, and also by the fact that the output of Texts.WriteReal for slightly different values is correct.
E.g.:
1000.0 * 2.56 results in 2.560000E+03 = 2560.0 (encoded ('raw') hexadecimal integer value: 45200000H)
1.0E6 * 1.048577 results in 1.048577E+06 = 1048577.0 (encoded ('raw') hexadecimal integer value: 49800008H)
I compiled and ran the procedure below to test this on Peter de Wachter's RISC emulator.
Could someone compile and run this test module on a hardware RISC5 FPGA board to verify the results?
Is this a known issue? Does anyone have an explanation?
Hans Klaver
MODULE TestRealMul;
IMPORT Texts, Oberon;
VAR W: Texts.Writer;
PROCEDURE WriteRealHex* (VAR W: Texts.Writer; x: REAL);
(* Write the encoded ('raw') hexadecimal INTEGER value of a REAL.
Verify on https://float.exposed *)
BEGIN
Texts.WriteHex(W, ORD(x)); Texts.Write(W, "H")
END WriteRealHex;
PROCEDURE Do*;
BEGIN
Texts.WriteString(W, "1.0E6 * 1.048575 = ");
Texts.WriteReal(W, 1.0E6 * 1.048575, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E6 * 1.048576 = ");
Texts.WriteReal(W, 1.0E6 * 1.048576, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E6 * 1.048576 = ");
Texts.WriteRealHex(W, 1.0E6 * 1.048576); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E6 * 1.048577 = ");
Texts.WriteReal(W, 1.0E6 * 1.048577, 16); Texts.WriteLn(W); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E6 * 2.097152 = ");
Texts.WriteReal(W, 1.0E6 * 2.097152, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E6 * 4.194304 = ");
Texts.WriteReal(W, 1.0E6 * 4.194304, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E5 * 1.31072 = ");
Texts.WriteReal(W, 1.0E5 * 1.31072, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E4 * 3.2768 = ");
Texts.WriteReal(W, 1.0E4 * 3.2768, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E4 * 1.6384 = ");
Texts.WriteReal(W, 1.0E4 * 1.6384, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E3 * 8.192 = ");
Texts.WriteReal(W, 1.0E3 * 8.192, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E3 * 4.096 = ");
Texts.WriteReal(W, 1.0E3 * 4.096, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E3 * 2.048 = ");
Texts.WriteReal(W, 1.0E3 * 2.048, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E3 * 1.024 = ");
Texts.WriteReal(W, 1.0E3 * 1.024, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E2 * 2.56 = ");
Texts.WriteReal(W, 1.0E2 * 2.56, 16); Texts.WriteLn(W);
Texts.WriteString(W, "100.0 * 2.56 = ");
Texts.WriteReal(W, 100.0 * 2.56, 16); Texts.WriteLn(W);
Texts.WriteString(W, "100.0 * 2.56 = ");
Texts.WriteRealHex(W, 100.0 * 2.56); Texts.WriteLn(W);
Texts.WriteString(W, "1000.0 * 2.56 = ");
Texts.WriteReal(W, 1000.0 * 2.56, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E2 * 1.28 = ");
Texts.WriteReal(W, 1.0E2 * 1.28, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E1 * 6.4 = ");
Texts.WriteReal(W, 1.0E1 * 6.4, 16); Texts.WriteLn(W);
Texts.WriteString(W, "1.0E1 * 3.2 = ");
Texts.WriteReal(W, 1.0E1 * 3.2, 16); Texts.WriteLn(W);
Texts.Append(Oberon.Log, W.buf)
END Do;
BEGIN Texts.OpenWriter(W)
END TestRealMul.Do
System.Free TestRealMul ~
Hi,
A link to the module currently in the archive is in the left column here.
https://en.wikibooks.org/wiki/Oberon/A2#Oberon.NetSystem
My revision of the module is here.
https://en.wikibooks.org/wiki/Oberon/A2/Unix.Oberon.NetSystem.Mod
(1) Setuser in ETH Oberon assumed that the user or user ID did not
contain the "@" character. No problem until the user was identified by
email address. Consequently
NetSystem.SetUser pop:jdoe@something.tld:password@mailhost.com ~
failed by taking everything after the first @ as the host. The
limitation was removed by parsing correctly. The improvement was put
in the git archive months ago. =8~)
(2) From joerg.straube at iaeth.ch Sat Aug 26 18:46:04 2023
> Personally, I would only call the set („user“, „password“)
> „Credential“. As you store the host and the service as well, I would
> call the bundle of these 4 strings „ServiceLogin“ or „
> ServiceAccess“ or something along these lines. But feel free to call
> it „Credential“, if you like.
Sound observation. Thanks.
After dithering and thought I constrained your suggestion. =8~)
Access = POINTER TO AccessDesc;
AccessDesc = RECORD
service, user, host, passwd: ARRAY 64 OF CHAR;
next: Access
END;
Further debate welcome. =8~)
(3) From andreas_pirklbauer at yahoo.com Thu Sep 28 20:26:53 2017
> Local procedures are in fact almost identical to global procedures ...
For me, SetUser was one of the more difficult procedures. Four local
procedures contributed to the difficulty. So I globalized those
procedures. A few additional parameters were needed but the net effect
was more evident allocation of responsibility.
(4) PROCEDURE State* violated the RETURN-at-the-end rule. Fixed.
(5) SetUser involved local variable ok in terminating a WHILE loop. ok
occurred in several places in the loop, therefore obfuscating as
successfully as multiple RETURNs. =8~/ So I made Next return a
success flag, added a loop for Next and removed ok. Again I believe
the result is more comprehensible. Debate welcome. =8~)
(6) From paulreed at paddedcell.com Sun Aug 12 14:57:20 2018
> But to take Andreas' example of using module Out for this, just replace
> the (dynamically-loaded) Out module with a stub version in production.
>
> I know the *system* is not the same, but at least your compiled code is.
> The overhead of the empty call and return is pretty low, at least in a
> non-cached system. :)
SetUser had a debugging facility before I began tampering. =8~)
Specfically, it recognizes "\v" among the access parameters. After
finding \v SetUser delivers debug output to System.Log. The switch is
used at run time. No risk from changing the executable.
(7) I've revised comments and added comments. In some cases changed
or deleted only a word. Complaints welcome.
(8) SMTP and NNTP connections can be authenticated now. I run the
connections through Linux Stunnel. Is a similar tunnel available in
A2? Probably I should apologize to Guenter for lack of familiarity
with his work.
Thanks, ... P.L.
.
-
VoIP: +1 604 670 0140
work: https://en.wikibooks.org/wiki/User:PeterEasthope