Hi,
On Thu, 8 Jul 2004 08:45:36 -0700, Fargusson.Alan wrote:
> 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.
> ...

All PL/1 implementations I know use for the intermediate result of
    fixed(p1,q1)  +/-  fixed(p2,q2)
    q = max(q1,q2)
    p = 1 + max(p1-q1,p2-q2) + q

p may be limited due to harware capability.
In this case the program should catch an exception - if not disabled.

With floating point operands the smaller may be neglected if the
difference in exponent magnitude exeeds mantissa length.
But thats not PL/1. It depends on the harware.


 = intermediate_


 for fixed point





 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

---
Albert

----------------------------------------------------------------------
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