This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Builtins and C++ and such (take 2)



> I'm for it. Please check it in. Sorry for the delay. This makes <cstring>
> and <cmath> consistent, which to me is an unremarked-upon side benefit. Yay!
>
> Roger, as you've noticed, dealing with C++/C header issues is no picnic
> as it involves aspects of libstdc++/glibc/g++. Thanks for sticking with it.

Many thanks for the approval.

Following Ben's recent fixes to include/c_std/std_cmath.h, the patch I
previously posted no longer applies cleanly.  To make applying these
changes a bit easier (I don't have write access myself), I've attached
a diff against current CVS.  I hope this helps.


2002-03-27  Roger Sayle  <roger@eyesopen.com>
	* include/c_std/std_cmath.h:  To prevent problems overloading
	g++ builtins, use the double variants from the global namespace
	before defining float and long double variants in std::.


Index: std_cmath.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/c_std/std_cmath.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 std_cmath.h
*** std_cmath.h	27 Mar 2002 04:29:32 -0000	1.4
--- std_cmath.h	28 Mar 2002 03:25:43 -0000
*************** namespace std
*** 89,106 ****
        return __x < _Tp() ? -__x : __x;
      }

-   inline float
-   abs(float __x)
-   { return __builtin_fabsf(__x); }
-
    inline double
    abs(double __x)
    { return __builtin_fabs(__x); }

    inline long double
    abs(long double __x)
    { return __builtin_fabsl(__x); }

  #if _GLIBCPP_HAVE_ACOSF
    inline float
    acos(float __x) { return ::acosf(__x); }
--- 89,108 ----
        return __x < _Tp() ? -__x : __x;
      }

    inline double
    abs(double __x)
    { return __builtin_fabs(__x); }

+   inline float
+   abs(float __x)
+   { return __builtin_fabsf(__x); }
+
    inline long double
    abs(long double __x)
    { return __builtin_fabsl(__x); }

+   using ::acos;
+
  #if _GLIBCPP_HAVE_ACOSF
    inline float
    acos(float __x) { return ::acosf(__x); }
*************** namespace std
*** 109,116 ****
    acos(float __x) { return ::acos(static_cast<double>(__x)); }
  #endif

-   using ::acos;
-
  #if _GLIBCPP_HAVE_ACOSL
    inline long double
    acos(long double __x) { return ::acosl(__x); }
--- 111,116 ----
*************** namespace std
*** 119,124 ****
--- 119,126 ----
    acos(long double __x) { return ::acos(static_cast<double>(__x)); }
  #endif

+   using ::asin;
+
  #if _GLIBCPP_HAVE_ASINF
    inline float
    asin(float __x) { return ::asinf(__x); }
*************** namespace std
*** 127,134 ****
    asin(float __x) { return ::asin(static_cast<double>(__x)); }
  #endif

-   using ::asin;
-
  #if _GLIBCPP_HAVE_ASINL
    inline long double
    asin(long double __x) { return ::asinl(__x); }
--- 129,134 ----
*************** namespace std
*** 137,142 ****
--- 137,144 ----
    asin(long double __x) { return ::asin(static_cast<double>(__x)); }
  #endif

+   using ::atan;
+
  #if _GLIBCPP_HAVE_ATANF
    inline float
    atan(float __x) { return ::atanf(__x); }
*************** namespace std
*** 145,152 ****
    atan(float __x) { return ::atan(static_cast<double>(__x)); }
  #endif

-   using ::atan;
-
  #if _GLIBCPP_HAVE_ATANL
    inline long double
    atan(long double __x) { return ::atanl(__x); }
--- 147,152 ----
*************** namespace std
*** 155,160 ****
--- 155,162 ----
    atan(long double __x) { return ::atan(static_cast<double>(__x)); }
  #endif

+   using ::atan2;
+
  #if _GLIBCPP_HAVE_ATAN2F
    inline float
    atan2(float __y, float __x) { return ::atan2f(__y, __x); }
*************** namespace std
*** 164,171 ****
    { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
  #endif

-   using ::atan2;
-
  #if _GLIBCPP_HAVE_ATAN2L
    inline long double
    atan2(long double __y, long double __x) { return ::atan2l(__y, __x); }
--- 166,171 ----
*************** namespace std
*** 175,180 ****
--- 175,182 ----
    { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
  #endif

+   using ::ceil;
+
  #if _GLIBCPP_HAVE_CEILF
    inline float
    ceil(float __x) { return ::ceilf(__x); }
*************** namespace std
*** 183,190 ****
    ceil(float __x) { return ::ceil(static_cast<double>(__x)); }
  #endif

-   using ::ceil;
-
  #if _GLIBCPP_HAVE_CEILL
    inline long double
    ceil(long double __x) { return ::ceill(__x); }
--- 185,190 ----
*************** namespace std
*** 193,208 ****
    ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
  #endif

    inline float
    cos(float __x)
    { return __builtin_cosf(__x); }

-   using ::cos;
-
    inline long double
    cos(long double __x)
    { return __builtin_cosl(__x); }

  #if _GLIBCPP_HAVE_COSHF
    inline float
    cosh(float __x) { return ::coshf(__x); }
--- 193,210 ----
    ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
  #endif

+   using ::cos;
+
    inline float
    cos(float __x)
    { return __builtin_cosf(__x); }

    inline long double
    cos(long double __x)
    { return __builtin_cosl(__x); }

+   using ::cosh;
+
  #if _GLIBCPP_HAVE_COSHF
    inline float
    cosh(float __x) { return ::coshf(__x); }
*************** namespace std
*** 211,218 ****
    cosh(float __x) { return ::cosh(static_cast<double>(__x)); }
  #endif

-   using ::cosh;
-
  #if _GLIBCPP_HAVE_COSHL
    inline long double
    cosh(long double __x) { return ::coshl(__x); }
--- 213,218 ----
*************** namespace std
*** 221,226 ****
--- 221,228 ----
    cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
  #endif

+   using ::exp;
+
  #if _GLIBCPP_HAVE_EXPF
    inline float
    exp(float __x) { return ::expf(__x); }
*************** namespace std
*** 229,236 ****
    exp(float __x) { return ::exp(static_cast<double>(__x)); }
  #endif

-   using ::exp;
-
  #if _GLIBCPP_HAVE_EXPL
    inline long double
    exp(long double __x) { return ::expl(__x); }
--- 231,236 ----
*************** namespace std
*** 239,254 ****
    exp(long double __x) { return ::exp(static_cast<double>(__x)); }
  #endif

    inline float
    fabs(float __x)
    { return __builtin_fabsf(__x); }

-   using ::fabs;
-
    inline long double
    fabs(long double __x)
    { return __builtin_fabsl(__x); }

  #if _GLIBCPP_HAVE_FLOORF
    inline float
    floor(float __x) { return ::floorf(__x); }
--- 239,256 ----
    exp(long double __x) { return ::exp(static_cast<double>(__x)); }
  #endif

+   using ::fabs;
+
    inline float
    fabs(float __x)
    { return __builtin_fabsf(__x); }

    inline long double
    fabs(long double __x)
    { return __builtin_fabsl(__x); }

+   using ::floor;
+
  #if _GLIBCPP_HAVE_FLOORF
    inline float
    floor(float __x) { return ::floorf(__x); }
*************** namespace std
*** 257,264 ****
    floor(float __x) { return ::floor(static_cast<double>(__x)); }
  #endif

-   using ::floor;
-
  #if _GLIBCPP_HAVE_FLOORL
    inline long double
    floor(long double __x) { return ::floorl(__x); }
--- 259,264 ----
*************** namespace std
*** 267,272 ****
--- 267,274 ----
    floor(long double __x) { return ::floor(static_cast<double>(__x)); }
  #endif

+   using ::fmod;
+
  #if _GLIBCPP_HAVE_FMODF
    inline float
    fmod(float __x, float __y) { return ::fmodf(__x, __y); }
*************** namespace std
*** 276,283 ****
    { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

-   using ::fmod;
-
  #if _GLIBCPP_HAVE_FMODL
    inline long double
    fmod(long double __x, long double __y) { return ::fmodl(__x, __y); }
--- 278,283 ----
*************** namespace std
*** 287,292 ****
--- 287,294 ----
    { return ::fmod(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

+   using ::frexp;
+
  #if _GLIBCPP_HAVE_FREXPF
    inline float
    frexp(float __x, int* __exp) { return ::frexpf(__x, __exp); }
*************** namespace std
*** 295,302 ****
    frexp(float __x, int* __exp) { return ::frexp(__x, __exp); }
  #endif

-   using ::frexp;
-
  #if _GLIBCPP_HAVE_FREXPL
    inline long double
    frexp(long double __x, int* __exp) { return ::frexpl(__x, __exp); }
--- 297,302 ----
*************** namespace std
*** 306,311 ****
--- 306,313 ----
    { return ::frexp(static_cast<double>(__x), __exp); }
  #endif

+   using ::ldexp;
+
  #if _GLIBCPP_HAVE_LDEXPF
    inline float
    ldexp(float __x, int __exp) { return ::ldexpf(__x, __exp); }
*************** namespace std
*** 315,322 ****
    { return ::ldexp(static_cast<double>(__x), __exp); }
  #endif

-   using ::ldexp;
-
  #if _GLIBCPP_HAVE_LDEXPL
    inline long double
    ldexp(long double __x, int __exp) { return ::ldexpl(__x, __exp); }
--- 317,322 ----
*************** namespace std
*** 326,331 ****
--- 326,333 ----
    { return ::ldexp(static_cast<double>(__x), __exp); }
  #endif

+   using ::log;
+
  #if _GLIBCPP_HAVE_LOGF
    inline float
    log(float __x) { return ::logf(__x); }
*************** namespace std
*** 334,341 ****
    { return ::log(static_cast<double>(__x)); }
  #endif

-   using ::log;
-
  #if _GLIBCPP_HAVE_LOGL
    inline long double
    log(long double __x) { return ::logl(__x); }
--- 336,341 ----
*************** namespace std
*** 344,349 ****
--- 344,351 ----
    log(long double __x) { return ::log(static_cast<double>(__x)); }
  #endif

+   using ::log10;
+
  #if _GLIBCPP_HAVE_LOG10F
    inline float
    log10(float __x) { return ::log10f(__x); }
*************** namespace std
*** 352,359 ****
    log10(float __x) { return ::log10(static_cast<double>(__x)); }
  #endif

-   using ::log10;
-
  #if _GLIBCPP_HAVE_LOG10L
    inline long double
    log10(long double __x) { return ::log10l(__x); }
--- 354,359 ----
*************** namespace std
*** 362,367 ****
--- 362,369 ----
    log10(long double __x) { return ::log10(static_cast<double>(__x)); }
  #endif

+   using ::modf;
+
  #if _GLIBCPP_HAVE_MODFF
    inline float
    modf(float __x, float* __iptr) { return ::modff(__x, __iptr); }
*************** namespace std
*** 376,383 ****
    }
  #endif

-   using ::modf;
-
  #if _GLIBCPP_HAVE_MODFL
    inline long double
    modf(long double __x, long double* __iptr) { return ::modfl(__x, __iptr); }
--- 378,383 ----
*************** namespace std
*** 401,406 ****
--- 401,408 ----
          : __cmath_power(__x, __n);
      }

+   using ::pow;
+
  #if _GLIBCPP_HAVE_POWF
    inline float
    pow(float __x, float __y) { return ::powf(__x, __y); }
*************** namespace std
*** 410,417 ****
    { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

-   using ::pow;
-
  #if _GLIBCPP_HAVE_POWL
    inline long double
    pow(long double __x, long double __y) { return ::powl(__x, __y); }
--- 412,417 ----
*************** namespace std
*** 421,448 ****
    { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

-   inline float
-   pow(float __x, int __n)
-   { return __pow_helper(__x, __n); }
-
    inline double
    pow(double __x, int __i)
    { return __pow_helper(__x, __i); }

    inline long double
    pow(long double __x, int __n)
    { return __pow_helper(__x, __n); }

    inline float
    sin(float __x)
    { return __builtin_sinf(__x); }

-   using ::sin;
-
    inline long double
    sin(long double __x)
    { return __builtin_sinl(__x); }

  #if _GLIBCPP_HAVE_SINHF
    inline float
    sinh(float __x) { return ::sinhf(__x); }
--- 421,450 ----
    { return ::pow(static_cast<double>(__x), static_cast<double>(__y)); }
  #endif

    inline double
    pow(double __x, int __i)
    { return __pow_helper(__x, __i); }

+   inline float
+   pow(float __x, int __n)
+   { return __pow_helper(__x, __n); }
+
    inline long double
    pow(long double __x, int __n)
    { return __pow_helper(__x, __n); }

+   using ::sin;
+
    inline float
    sin(float __x)
    { return __builtin_sinf(__x); }

    inline long double
    sin(long double __x)
    { return __builtin_sinl(__x); }

+   using ::sinh;
+
  #if _GLIBCPP_HAVE_SINHF
    inline float
    sinh(float __x) { return ::sinhf(__x); }
*************** namespace std
*** 451,458 ****
    sinh(float __x) { return ::sinh(static_cast<double>(__x)); }
  #endif

-   using ::sinh;
-
  #if _GLIBCPP_HAVE_SINHL
    inline long double
    sinh(long double __x) { return ::sinhl(__x); }
--- 453,458 ----
*************** namespace std
*** 461,476 ****
    sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
  #endif

    inline float
    sqrt(float __x)
    { return __builtin_sqrtf(__x); }

-   using ::sqrt;
-
    inline long double
    sqrt(long double __x)
    { return __builtin_sqrtl(__x); }

  #if _GLIBCPP_HAVE_TANF
    inline float
    tan(float __x) { return ::tanf(__x); }
--- 461,478 ----
    sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
  #endif

+   using ::sqrt;
+
    inline float
    sqrt(float __x)
    { return __builtin_sqrtf(__x); }

    inline long double
    sqrt(long double __x)
    { return __builtin_sqrtl(__x); }

+   using ::tan;
+
  #if _GLIBCPP_HAVE_TANF
    inline float
    tan(float __x) { return ::tanf(__x); }
*************** namespace std
*** 479,486 ****
    tan(float __x) { return ::tan(static_cast<double>(__x)); }
  #endif

-   using ::tan;
-
  #if _GLIBCPP_HAVE_TANL
    inline long double
    tan(long double __x) { return ::tanl(__x); }
--- 481,486 ----
*************** namespace std
*** 489,494 ****
--- 489,496 ----
    tan(long double __x) { return ::tan(static_cast<double>(__x)); }
  #endif

+   using ::tanh;
+
  #if _GLIBCPP_HAVE_TANHF
    inline float
    tanh(float __x) { return ::tanhf(__x); }
*************** namespace std
*** 496,503 ****
    inline float
    tanh(float __x) { return ::tanh(static_cast<double>(__x)); }
  #endif
-
-   using ::tanh;

  #if _GLIBCPP_HAVE_TANHL
    inline long double
--- 498,503 ----

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]