X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Sat, 25 Oct 2003 21:09:55 +0100 From: "Richard Dawe" Sender: rich AT phekda DOT freeserve DOT co DOT uk To: djgpp-workers AT delorie DOT com, max_payne AT hotpop DOT com X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 Subject: math.h: Better C99 and C++ compliance [PATCH] Message-Id: Reply-To: djgpp-workers AT delorie DOT com Hello. math.h needs some work to comply with the C99 and C++ standards. For C99 we need to move definitions from the non-standard section into the C99 section. For C++ we need to make some of the definitions available even when -ansi is used. This is because std::cos, etc. are actually overloaded functions with versions available for float, double and long double. libstdc++ provides these by calling ::cosf, etc. So now there are two C99 sections: one for C99 stuff that should be able for C++ even when -ansi was used to compile; one for normal C99 stuff. Without this patch, the following C++ test program fails to build: #include int main (void) { return 0; } when built with: gcc -ansi -o foo foo.c You get errors like this: In file included from dashansi.cpp:1: c:/djgpp/lang/cxx/3.23/cmath: In function `float std::acos(float)': c:/djgpp/lang/cxx/3.23/cmath:99: `::acosf' undeclared (first use here) For more information, see the text below table 80 in the ISO C++ standard. It lists the functions that are overloaded there. (Basically the ones that I have moved.) I tested with stdlibc++ from gcc 3.2.1, but it still happens with gcc 3.3.2. (See today's messages in comp.os.msdos.djgpp.) OK to commit? Bye, Rich =] Index: include/math.h =================================================================== RCS file: /cvs/djgpp/djgpp/include/math.h,v retrieving revision 1.10 diff -p -u -3 -r1.10 math.h --- include/math.h 25 Oct 2003 11:22:53 -0000 1.10 +++ include/math.h 25 Oct 2003 19:50:55 -0000 @@ -42,6 +42,49 @@ double sqrt(double _x); double tan(double _x); double tanh(double _x); +/* The C++ standard has overloaded versions of cos, etc. for floats + * and long doubles. libstdc++ calls the C99-standardised float + * and long double versions of cos, etc. in the global namespace + * to provide the overloaded versions. So we place the float + * and long double versions in the global namespace for C++ + * even when __STRICT_ANSI__ is defined. + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ + || !defined(__STRICT_ANSI__) \ + || defined(__cplusplus) + +long double modfl(long double _x, long double *_pint); + +/* These are in libm.a (Cygnus). You must link -lm to get these */ +/* See libm/math.h for comments */ + +extern float acosf(float); +extern float asinf(float); +extern float atanf(float); +extern float atan2f(float, float); +extern float cosf(float); +extern float sinf(float); +extern float tanf(float); +extern float coshf(float); +extern float sinhf(float); +extern float tanhf(float); +extern float expf(float); +extern float frexpf(float, int *); +extern float ldexpf(float, int); +extern float logf(float); +extern float log10f(float); +extern float modff(float, float *); +extern float powf(float, float); +extern float sqrtf(float); +extern float ceilf(float); +extern float fabsf(float); +extern float floorf(float); +extern float fmodf(float, float); + +/* End libm.a. */ + +#endif + #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \ || !defined(__STRICT_ANSI__) @@ -82,6 +125,50 @@ double nan(const char *); float nanf(const char *); long double nanl(const char *); +double acosh(double); +double asinh(double); +double atanh(double); +double cbrt(double); +double exp2(double _x); +double expm1(double); +double hypot(double, double); +double log1p(double); +double log2(double _x); + +/* These are in libm.a (Cygnus). You must link -lm to get these */ +/* See libm/math.h for comments */ + +extern double erf(double); +extern double erfc(double); +extern double lgamma(double); +extern double logb(double); +extern double nextafter(double, double); +extern double remainder(double, double); +extern double copysign(double, double); +extern int ilogb(double); +extern double rint(double); +extern double scalbn(double, int); +extern float erff(float); +extern float erfcf(float); +extern float hypotf(float, float); +extern float lgammaf(float); +extern float acoshf(float); +extern float asinhf(float); +extern float atanhf(float); +extern float cbrtf(float); +extern float logbf(float); +extern float nextafterf(float, float); +extern float remainderf(float, float); +extern float scalbf(float, float); +extern float copysignf(float, float); +extern int ilogbf(float); +extern float rintf(float); +extern float scalbnf(float, int); +extern float expm1f(float); +extern float log1pf(float); + +/* End libm.a. */ + #endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */ #ifndef __STRICT_ANSI__ @@ -104,17 +191,7 @@ long double nanl(const char *); #define PI M_PI #define PI2 M_PI_2 -double acosh(double); -double asinh(double); -double atanh(double); -double cbrt(double); double exp10(double _x); -double exp2(double _x); -double expm1(double); -double hypot(double, double); -double log1p(double); -double log2(double _x); -long double modfl(long double _x, long double *_pint); double pow10(double _x); double pow2(double _x); double powi(double, int); @@ -134,84 +211,34 @@ struct exception { }; #endif -extern double erf(double); -extern double erfc(double); extern double gamma(double); extern int finite(double); extern double j0(double); extern double j1(double); extern double jn(int, double); -extern double lgamma(double); extern double y0(double); extern double y1(double); extern double yn(int, double); -extern double logb(double); -extern double nextafter(double, double); -extern double remainder(double, double); extern double scalb(double, double); #ifndef __cplusplus extern int matherr(struct exception *); #endif extern double significand(double); -extern double copysign(double, double); -extern int ilogb(double); -extern double rint(double); -extern double scalbn(double, int); extern double drem(double, double); extern double gamma_r(double, int *); extern double lgamma_r(double, int *); -extern float acosf(float); -extern float asinf(float); -extern float atanf(float); -extern float atan2f(float, float); -extern float cosf(float); -extern float sinf(float); -extern float tanf(float); -extern float coshf(float); -extern float sinhf(float); -extern float tanhf(float); -extern float expf(float); -extern float frexpf(float, int *); -extern float ldexpf(float, int); -extern float logf(float); -extern float log10f(float); -extern float modff(float, float *); -extern float powf(float, float); -extern float sqrtf(float); -extern float ceilf(float); -extern float fabsf(float); -extern float floorf(float); -extern float fmodf(float, float); -extern float erff(float); -extern float erfcf(float); extern float gammaf(float); -extern float hypotf(float, float); extern int isinff(float); extern int isnanf(float); extern int finitef(float); extern float j0f(float); extern float j1f(float); extern float jnf(int, float); -extern float lgammaf(float); extern float y0f(float); extern float y1f(float); extern float ynf(int, float); -extern float acoshf(float); -extern float asinhf(float); -extern float atanhf(float); -extern float cbrtf(float); -extern float logbf(float); -extern float nextafterf(float, float); -extern float remainderf(float, float); -extern float scalbf(float, float); extern float significandf(float); -extern float copysignf(float, float); -extern int ilogbf(float); -extern float rintf(float); -extern float scalbnf(float, int); extern float dremf(float, float); -extern float expm1f(float); -extern float log1pf(float); extern float gammaf_r(float, int *); extern float lgammaf_r(float, int *);