delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/11/07/17:09:35

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
From: Kbwms AT aol DOT com
Message-ID: <1eb.12bb4eae.2cdd71ca@aol.com>
Date: Fri, 7 Nov 2003 17:08:10 EST
Subject: Re: C99 Functions Under Development and Checkout
To: djgpp-workers AT delorie DOT com
MIME-Version: 1.0
X-Mailer: 8.0 for Windows sub 6021
Reply-To: djgpp-workers AT delorie DOT com

--part1_1eb.12bb4eae.2cdd71ca_boundary
Content-Type: multipart/alternative;
	boundary="part1_1eb.12bb4eae.2cdd71ca_alt_boundary"


--part1_1eb.12bb4eae.2cdd71ca_alt_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Attached to this email is the C code that implements global variable 
math_errhandling and associated macros.  Noted below are additions to math.h:

#define MATH_ERRNO          1
#define MATH_ERREXCEPT  2
extern int math_errhandling;


int get_math_errhandling    (void);
int set_math_errhandling    (int);
void    set_errno       (int);
int raise_except        (int);

Here are the headers for the four functions:

// ------------------------------------------------------------
// set_math_errhandling - Sets global variable math_errhandling
// ------------------------------------------------------------

// ---------------------------------------------------------------------
// get_math_errhandling - Returns value of math_errhandling for this run
// ---------------------------------------------------------------------

// ----------------------------------------------------
// set_errno - Sets global variable errno when required
// ----------------------------------------------------

// -------------------------------------------------------------
// raise_except - Raises floating point exceptions when required
// -------------------------------------------------------------


I have implemented this feature in 49 C functions.  My thanks to all who 
contributed to this effort.


Comments are welcome.  Please look the code over and let me know whether 
there is a gotcha lurking.


KB Williams

--part1_1eb.12bb4eae.2cdd71ca_alt_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<HTML><FONT FACE=3Darial,helvetica><FONT  SIZE=3D3 FAMILY=3D"SERIF" FACE=3D"=
Georgia" LANG=3D"0">Attached to this email is the C code that implements glo=
bal variable math_errhandling and associated macros.&nbsp; Noted below are a=
dditions to math.h:<BR>
<BR>
#define MATH_ERRNO  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  1<BR>
#define MATH_ERREXCEPT  2<BR>
extern int math_errhandling;<BR>
<BR>
<BR>
int get_math_errhandling    (void);<BR>
int set_math_errhandling    (int);<BR>
void    set_errno       (int);<BR>
int raise_except        (int);<BR>
<BR>
Here are the headers for the four functions:<BR>
<BR>
// ------------------------------------------------------------<BR>
// set_math_errhandling - Sets global variable math_errhandling<BR>
// ------------------------------------------------------------<BR>
<BR>
// ---------------------------------------------------------------------<BR>
// get_math_errhandling - Returns value of math_errhandling for this run<BR>
// ---------------------------------------------------------------------<BR>
<BR>
// ----------------------------------------------------<BR>
// set_errno - Sets global variable errno when required<BR>
// ----------------------------------------------------<BR>
<BR>
// -------------------------------------------------------------<BR>
// raise_except - Raises floating point exceptions when required<BR>
// -------------------------------------------------------------<BR>
<BR>
<BR>
I have implemented this feature in 49 C functions.&nbsp; My thanks to all wh=
o contributed to this effort.<BR>
<BR>
<BR>
Comments are welcome.&nbsp; Please look the code over and let me know whethe=
r there is a gotcha lurking.<BR>
<BR>
<BR>
KB Williams</FONT></HTML>

--part1_1eb.12bb4eae.2cdd71ca_alt_boundary--

--part1_1eb.12bb4eae.2cdd71ca_boundary
Content-Type: text/plain; name="errhndlr.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; filename="errhndlr.c"

// ----------
// errhndlr.c
// ----------

#include <errno.h>
#include <fenv.h>
#include <math.h>

int=09    math_errhandling;
static int  LocalMathErrHandling =3D 0;

// ------------------------------------------------------------
// set_math_errhandling - Sets global variable math-errhandling
// ------------------------------------------------------------
int=09set_math_errhandling(int Value)
{
    if (LocalMathErrHandling =3D=3D 0)=09=09// First Pass?
    {
    =09Value &=3D (MATH_ERRNO | MATH_ERREXCEPT);=09// Yes

=09if (Value =3D=3D 0)
=09{
    =09    Value =3D MATH_ERRNO | MATH_ERREXCEPT;
=09}

=09LocalMathErrHandling =3D Value;=09=09// Set local value
    }

    math_errhandling =3D LocalMathErrHandling;=09// (Re)set global value

    return Value;
}
// ---------------------------------------------------------------------
// get_math_errhandling - Returns value of math_errhandling for this run
// ---------------------------------------------------------------------
int=09get_math_errhandling(void)
{
    if (LocalMathErrHandling =3D=3D 0)=09=09// First Pass?
    {
    =09set_math_errhandling(math_errhandling);=09// Yes.
    }

    return  LocalMathErrHandling;
}

// ----------------------------------------------------
// set_errno - Sets global variable errno when required
// ----------------------------------------------------
void=09set_errno(int Value)
{
    if (LocalMathErrHandling =3D=3D 0)=09=09// First pass here?
    {
=09set_math_errhandling(math_errhandling);=09// Yes - set control variable
    }

    math_errhandling =3D LocalMathErrHandling;=09// Reset control variable

    if (math_errhandling & MATH_ERRNO)=09=09// Set errno when required
    {
    =09errno =3D Value;
    }
}

// -------------------------------------------------------------
// raise_except - Raises floating point exceptions when required
// -------------------------------------------------------------
int raise_except(int Value)
{
    int     Retval =3D -1;=09=09=09// Default Return Value

    if (LocalMathErrHandling =3D=3D 0)=09=09// First pass here?
    {
=09set_math_errhandling(math_errhandling); // Yes - set control variable
    }

    math_errhandling =3D LocalMathErrHandling;    // Reset control variable

    if (math_errhandling & MATH_ERREXCEPT)      // Raise exception when requ=
ired
    {
    =09Retval =3D feraiseexcept(Value);
    }

    return Retval;
}

--part1_1eb.12bb4eae.2cdd71ca_boundary--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019