From: Kbwms AT aol DOT com Message-ID: <18.348fb69c.2c8122ce@aol.com> Date: Fri, 29 Aug 2003 17:42:38 EDT Subject: Re: Arithmetic Exceptions in C99 To: djgpp-workers AT delorie DOT com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="part1_18.348fb69c.2c8122ce_boundary" X-Mailer: 8.0 for Windows sub 6015 Reply-To: djgpp-workers AT delorie DOT com --part1_18.348fb69c.2c8122ce_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit In a message dated 8/29/2003 5:10:01 PM Eastern Standard Time, ams AT ludd DOT luth DOT se writes: > >In this case, the affected math function sets errno to ERANGE and > (possibly) > >raises an appropriate exception. In no case should a math function issue > >SIGFPE. > > What signal should it generate if not SIGFPE? > > For me raise an exception == generate a signal. Both Eli and you > seems to say that raising an exception is something else than > generating a signal. > > Can somebody explain this to me? > You mentioned acos(2) somewhere in this thread. Appended to this email as a postscript is acosl.c. In the first few steps, if the absolute value of the argument exceeds 1, the function takes actions prescribed in C99, pages 229 (7.12.4.1) and 446 (F.9.11). The actions include raising the invalid floating point exception. KB Williams PS /* ------- */ /* acosl.c */ /* ------- */ #include #include #include #include /* Written for DJGPP/GCC by KB Williams, kbwms AT aol DOT com, December 2001 */ # ifdef __STDC__ long double acosl(long double Arg) # else long double acosl(Arg) long double Arg; # endif // 1. If |Arg| > 1 // Set errno to EDOM, set Retval to NaN, // raise invalid exception // 2. If |Arg| == 1 // Retval = (Arg > 0) ? 0 : Pi // 3. If Arg == 0 // Set Retval to Pi/2 // 4. Calculate acos(Arg) for // x in (-1, -.5), or (+.5, +1) or [-.5, +.5] { long double AbsArg, Retval; AbsArg = fabsl(Arg); if (AbsArg >= 1) // Steps 1 & 2 { if (AbsArg > 1) { errno = EDOM; Retval = NANL; // Return NaN feraiseexcept(FE_INVALID); // Raise invalid exception } else // Arg == +- 1 { if (Arg > 0) // acosl(1) = 0 Retval = 0; else // acosl(-1) = pi Retval = PIL; } } else if (Arg == 0) // Step 3 { Retval = PIO2L; } else if (Arg < -0.5L) // Step 4 { Retval = (PIL - 2.0L * asinl(sqrtl(0.5L * (1.0L + Arg)))); } else if (Arg > 0.5L) { Retval = (2.0L * asinl(sqrtl(0.5L * (1.0L - Arg)))); } else { Retval = (PIO2L - asinl(Arg)); } return Retval; } --part1_18.348fb69c.2c8122ce_boundary Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable In a message dated 8/29/2003 5:10:01 PM Eastern Standard= Time, ams AT ludd DOT luth DOT se writes:

>In this case, the affected math function sets errno to=20= ERANGE and (possibly)
>raises an appropriate exception.  In no case should a math function= issue
>SIGFPE.

What signal should it generate if not SIGFPE?

For me raise an exception =3D=3D generate a signal. Both Eli and you
seems to say that raising an exception is something else than
generating a signal.

Can somebody explain this to me?


You mentioned acos(2) somewhere in this thread.  Appended to this email= as a postscript is acosl.c.  In the first few steps, if the absolute v= alue of the argument exceeds 1, the function takes actions prescribed in C99= , pages 229 (7.12.4.1) and 446 (F.9.11).  The actions include raising t= he invalid floating point exception.


KB Williams

PS

/* ------- */
/* acosl.c */
/* ------- */
#include <errno.h>
#include <math.h>
#include <fdlibml.h>
#include <fenv.h>
/*
Written for DJGPP/GCC by KB Williams, kbwms AT aol DOT com,
December 2001
*/
# ifdef __STDC__
long double
acosl(long double Arg)
# else
long double
acosl(Arg)
long double Arg;
# endif
//      1. If |Arg| > 1
//         Set errno to EDOM, set Re= tval to NaN,
//         raise invalid exception //      2. If |Arg| =3D=3D 1
//         Retval =3D (Arg > 0) ?= 0 : Pi
//      3. If Arg =3D=3D 0
//         Set Retval to Pi/2
//      4. Calculate acos(Arg) for
//         x in (-1, -.5), or (+.5,=20= +1) or [-.5, +.5]
{
    long double AbsArg, Retval;

    AbsArg =3D fabsl(Arg);

    if (AbsArg >=3D 1)      =             &nbs= p; // Steps 1 & 2
    {
        if (AbsArg > 1)
        {
            errno=20= =3D EDOM;
            Retval=20= =3D NANL;           &= nbsp;  // Return NaN
            feraiseex= cept(FE_INVALID);  // Raise invalid exception
        }
        else     = ;            &nb= sp;          // Arg =3D=3D +- 1=
        {
            if (Arg &= gt; 0)           &nbs= p;    // acosl(1) =3D 0
            &nbs= p;   Retval =3D 0;
            else = ;            &nb= sp;          // acosl(-1) =3D p= i
            &nbs= p;   Retval =3D PIL;
        }
    }
    else if (Arg =3D=3D 0)      = ;            // Step=20= 3
    {
        Retval =3D PIO2L;
    }
    else if (Arg < -0.5L)     &nb= sp;         // Step 4
    {
        Retval =3D (PIL - 2.0L * asinl(sq= rtl(0.5L * (1.0L + Arg))));
    }
    else if (Arg > 0.5L)
    {
        Retval =3D (2.0L * asinl(sqrtl(0.= 5L * (1.0L - Arg))));
    }
    else
    {
        Retval =3D (PIO2L - asinl(Arg));<= BR>     }
    return Retval;
}
--part1_18.348fb69c.2c8122ce_boundary--