[Oberon] REAL math
Jörg Straube
joerg.straube at iaeth.ch
Sat Nov 15 08:40:51 CET 2014
Zdenek
In addition to my experiments on WinAos, I now played with LinuxAos or to be precise with DarwinAos on the Mac. Here my program:
- - - - - - - - - - -
MODULE Untitled;
IMPORT Commands;
PROCEDURE Do*(ctx: Commands.Context);
VAR
epsilon, r: REAL;
digits: INTEGER;
BEGIN
epsilon := 1; digits :=0;
WHILE 1+epsilon # 1 DO epsilon := epsilon /10; INC(digits) END;
ctx.out.Int(digits, 0); ctx.out.Ln;
r := 480/100*100;
ctx.out.Float(r, 20); ctx.out.Ln;
ctx.out.Float(r-480, 20); ctx.out.Ln;
epsilon := 1; digits :=0;
WHILE 1.D0+epsilon # 1 DO epsilon := epsilon /10; INC(digits) END;
ctx.out.Int(digits, 0); ctx.out.Ln;
r := SHORT(480.D0/100*100);
ctx.out.Float(r, 20); ctx.out.Ln;
ctx.out.Float(r-480, 20); ctx.out.Ln;
END Do;
BEGIN
END Untitled.Do
- - - - - - - - - - -
The output is
8
4.80000030518E+002
3.05175781250E-005
16
4.80000000000E+002
0.00000000000E+000
As the result of the WHILE shows, in this AOS environment expressions are evaluated with 8 digits of accuracy (REAL).
Hence the compiler by default evaluates internally constant expressions like „480/100*100“ with REALs as well.
If I force the compiler to use LONGREAL (by writing 1.D0 and 480.D0) the results are more accurate.
br
Jörg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.inf.ethz.ch/pipermail/oberon/attachments/20141115/17d03231/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3644 bytes
Desc: not available
Url : https://lists.inf.ethz.ch/pipermail/oberon/attachments/20141115/17d03231/attachment.bin
More information about the Oberon
mailing list