This triggered a long forgotten memory.  I don't know PL/1 syntax, but the problem 
goes something like this:

        declare x as two digits;
        declare y as two digits;
        declare z as three digits;

        x = 30;
        y = 70;
        z = x + y;

At this point z is zero because the add of x and y is done with two digits of 
accuracy.  I think that the rule is that the add is done in the size of the largest 
item, which is two in my example.  I was going to say that the compiler should warn 
about this, but I don't see how it could, knowing how parsing of the expression is 
done.

There is a similar problem with COBOL, but COBOL programmers do this:

        move 30 to x.
        move 70 to y.

        move x to z.
        add y to z.

This results in the add being done in three digits.  COBOL programmers avoid the 
compute statement because it would have the same result as the PL/1 example.

-----Original Message-----
From: Nix, Robert P. [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 07, 2004 7:04 AM
To: [EMAIL PROTECTED]
Subject: Re: Progress on PL/1 for Linux


The demonstration I was given used three variables, all falling to the default 
definitions (it's been too long to remember the specific letters used; sorry). Two of 
the variables are assigned very large values, and the third is set to a very small 
value, all positive. The three variables are added together to return a result. 
Because of the intermediate temporary variables selected by PL/I to store the partial 
results, both ends of the resulting value are truncated, leaving zero. There is no 
error or warning; you just get a zero result, even though the result could have been 
correctly represented had better intermediates been chosen.

You can get this to happen in many languages... just not as readily. Most make better 
choices of intermediate variables, and most warn you when something like this happens 
at runtime, or at least let you trap the error if you desire.

----
Robert P. Nix                            internet: [EMAIL PROTECTED]
Mayo Clinic                                  phone: 507-284-0844
RO-CE-8-857                                page: 507-270-1182
200 First St. SW
Rochester, MN 55905
----   "Codito, Ergo Sum"
"In theory, theory and practice are the same,
 but in practice, theory and practice are different."



> -----Original Message-----
> From: Linux on 390 Port [SMTP:[EMAIL PROTECTED] On Behalf Of Henry Schaffer
> Sent: Wednesday, July 07, 2004 8:56 AM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Progress on PL/1 for Linux
>
>   It's been a very long time since I last used PL/I, but I don't
> remember anything about its arithmetic which would give this result.
> IIRC it basically used the underlying 360/370 hardware for arithmetic.
>
>   Could you say more about this intriguing error?
>
> --henry schaffer
>
>

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to