industrialNETworXnetx

| 16.10.2008 | 15:21 | 1 reply

math.h and __errno

Hi,

I use GCC 4.0.3 and i included math.h and stdlib.h.
My program compiles and runs with sin() and pow() function, but doesn't with sqrt().
Compiler claims undefined __errno.
Defining this variable on my own i success.
Where is the compiler error source?

Thanks,

M T

M T

Hilscher Gesellschaft für Systemautomation mbH

| 16.10.2008 | 16:17

The Standard C library that comes with the compiler (I assume it is the Hitex compiler) needs this. Hitex uses the newlib library as Standard C library.

Usually the variable "errno" is used as a global variable containing the error of the last function. See below for the sqrt function inside the newlib library (which can be downloaded from http://sourceware.org/newlib/).

The library expects "errno" (respectively __errno) to be provided by an O/S or the user.

/*
 * wrapper sqrt(x)
 */

#include "fdlibm.h"
#include

#ifndef _DOUBLE_IS_32BITS

#ifdef __STDC__
double sqrt(double x) /* wrapper sqrt */
#else
double sqrt(x) /* wrapper sqrt */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sqrt(x);
#else
struct exception exc;
double z;
z = __ieee754_sqrt(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<0.0) {
exc.type = DOMAIN;
exc.name = "sqrt";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}

#endif /* defined(_DOUBLE_IS_32BITS) */

Regards

MT

Login