Exception handling 
Author Message
 Exception handling

Has anyone seen ISO/IEC 10967-1: 1994 "Information
Technology -- Language Independent Arithmetic"
which contains recommendations
for standardizing exception-handling in HLLs including
PL/I ?



Sun, 16 Apr 2000 03:00:00 GMT  
 Exception handling


 on 29 Oct 1997 15:46:39 +1100,

Quote:

>Example to calculate the product x(1) * x(2) * x(3) * . . . * x(n)
>using extended range arithmetic to deal with intermediate products
>that would normally cause overflow or underflow.

>This example has been translated to PL/I, from pseudocode in
>J.R. Hauser, "Handling Floating-Point Exceptions in Numeric Programs",
>in "ACM Transactions on Programming Languages & Systems",
>March 1996

>product.exponent = 0;
>product.significand = 1.0;

>    do i = 1 to n;
>       on overflow begin;
>         do while (abs(product.significand) > 1);
>            product.exp = product.exp + 1;
>            product.significand = product.significand/256;
>         end;
>         go to resume;
>       end;
>      on underflow  begin;
>         do while  (abs(product.significand) < 1);
>            product.exp = product.exp - 1;
>            product.significand = product.signficand*256;
>         end;
>         go to resume;
>      end;

>      temp = product.significand * x(i);

>    resume:
>       product.sig = temp;
>    end;

   Interesting algorithm, Robin, thanks foe posting it (and the
translation to PL/I). BTW, could you give the PL/I definition of the
structure "product"? Thanks.

Quote:
>Curiously, the Paper states that "in principle, several programming
>languages a means for realizing these optimizations at a high level
>with a 'termination' style of exception handling.  Ada is the best-
>known such language; [. . .]".  The paper then goes on to state
>that "Underflows cannot be caught as exceptions within Ada at all."

>I wonder why the author did not mention PL/I ?  which has
>the facility to deal with both underflows and overflows.

   No suprises here, either. It didn't get mentioned because:

          1) ignorance
or
          2) PL/I is viewed in certain circles as being "impure" and
             unworthy of scientific study.... :-(

Dave Jones



Sun, 16 Apr 2000 03:00:00 GMT  
 Exception handling




        >>Example to calculate the product x(1) * x(2) * x(3) * . . . * x(n)
        >>using extended range arithmetic to deal with intermediate products
        >>that would normally cause overflow or underflow.
        >>
        >>This example has been translated to PL/I, from pseudocode in
        >>J.R. Hauser, "Handling Floating-Point Exceptions in Numeric Programs",
        >>in "ACM Transactions on Programming Languages & Systems",
        >>March 1996
        >>
        >>product.exponent = 0;
        >>product.significand = 1.0;
        >>
        >>    do i = 1 to n;
        >>       on overflow begin;
        >>         do while (abs(product.significand) > 1);
        >>            product.exp = product.exp + 1;
        >>            product.significand = product.significand/256;
        >>         end;
        >>           temp = product.significand * x(i); /* re-calculate product. */
        >>         go to resume;
        >>       end;
        >>      on underflow  begin;
        >>         do while  (abs(product.significand) < 1);
        >>            product.exp = product.exp - 1;
        >>            product.significand = product.signficand*256;
        >>         end;
        >>           temp = product.significand * x(i); /* re-calcuate product. */
        >>         go to resume;
        >>      end;
        >>
        >>      temp = product.significand * x(i);
        >>
        >>    resume:
        >>       product.sig = temp;
        >>    end;
        >>
        >   Interesting algorithm, Robin, thanks foe posting it (and the
        >translation to PL/I). BTW, could you give the PL/I definition of the
        >structure "product"? Thanks.

At a guess, I'd say it was something like:

DECLARE 1 product,
          2 significand FLOAT BINARY(51), /* 21 bits OK too if you don't want the accuracy */
          2 exp         FIXED BINARY (31);

The extra exponent gives a huge increase to the exponent.

Shades of the "old days", when one word was devoted to the
mantissa, and another word for the exponent, giving an
exponent range from 2**(-2147483648) thru 2**2147483647.
along with a 31-bit mantissa.

Here, the exponent range is 256**(-2147483648) thru 256**2147483647,
plus whatever range you get from ordinary floating-point.

The deal is that the product is calculated using normal floating-point
hardware at normal speed, until either overflow or underflow occurs,
and then to scale things so that the actual exponent is close to
zero, and then to continue as before using normal floating-point
hardware.....until another f.p. overflow or underfoow occurs.
        >Dave Jones



Mon, 17 Apr 2000 03:00:00 GMT  
 Exception handling

Example to calculate the product x(1) * x(2) * x(3) * . . . * x(n)
using extended range arithmetic to deal with intermediate products
that would normally cause overflow or underflow.

This example has been translated to PL/I, from pseudocode in
J.R. Hauser, "Handling Floating-Point Exceptions in Numeric Programs",
in "ACM Transactions on Programming Languages & Systems",
March 1996

product.exponent = 0;
product.significand = 1.0;

do i = 1 to n;
        on overflow begin;
                do while (abs(product.significand) > 1);
                        product.exp = product.exp + 1;
                        product.significand = product.significand/256;
                end;
                temp = product.significand * x(i); /* re-calculate product */
                go to resume;
        end;
        on underflow  begin;
                do while  (abs(product.significand) < 1);
                        product.exp = product.exp - 1;
                        product.significand = product.signficand*256;
                end;
                temp = product.significand * x(i); /* re-calculate product */
                go to resume;
        end;

        temp = product.significand * x(i);

   resume:
        product.sig = temp;
end;

Curiously, the Paper states that "in principle, several programming
languages a means for realizing these optimizations at a high level
with a 'termination' style of exception handling.  Ada is the best-
known such language; [. . .]".  The paper then goes on to state
that "Underflows cannot be caught as exceptions within Ada at all."

I wonder why the author did not mention PL/I ?  which has
the facility to deal with both underflows and overflows.



Mon, 17 Apr 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Customizing exception handling in VW

2. C++ exception handling for Smalltalkers

3. Dolphin 98 exception handling problem

4. Exception Handling

5. Exception Handling

6. C++ exception handling for Smalltalkers

7. Exception Handling

8. Simple Exception handling questions

9. Exception Handling

10. exception handling in smalltalk /r

11. question about exception handling mechanism

12. Looking for exception handling teaching materials/examples

 

 
Powered by phpBB® Forum Software