Negative infinity doesn't cause ORA-06502 in PL/SQL?

From: David Gallardo <david_at_gallardo.org>
Date: 21 May 2002 01:11:31 -0700
Message-ID: <c3a44a98.0205210011.2dd0e298_at_posting.google.com>


I'm trying to understand why assigning positive infinity to a floating point number in PL/SQL causes an error ORA-06502 but negative infinity doesn't. I'm hoping someone has an explanation.

The problem can be created by taking advantage of the fact that the tangent of pi radians and 3 pi radians are both undefined--or positive and negative infinity, respectively. Given that acos(0) is pi, the following SQL statements generate overflows as expected at a sqlplus prompt:

 select tan(acos(0)) from dual;
 select tan(3*acos(0)) from dual;

Both generate "ORA-01426: numeric overflow", as expected.

However, if I attempt to assign these to a NUMBER(18,9), for example, in PL/SQL, only the first case, positive infinity gives me an error. Negative infinity results in 0.

This is my PL/SQL block:

  DECLARE
    TANGENT NUMBER(18,9);
    MULT NUMBER := 1;
  BEGIN
    TANGENT := TAN(MULT * ACOS(0));
    DBMS_OUTPUT.PUT_LINE(TANGENT);
  END; This, with MULT = 1, results in "ORA-06502: PL/SQL: numeric or value error: number precision too large". Which is what I expect.

If I replace MULT with 3, however, there's no error and it prints 0 as the result for tangent.

To catch an error here there's this workaround:

  TANGENT := ABS(TAN(MULT * ACOS(0)));
  TANGENT := TANGENT * SIGN(TAN(MULT * ACOS(0))); Taking the absolute value of negative infinity and assigning it to TANGENT does the trick--because now it's positive infinity.

Any insights would be appreciated!

  • David Gallardo
Received on Tue May 21 2002 - 10:11:31 CEST

Original text of this message