This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


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

V3 PATCH: cabs vs. IRIX



This patch (not checked in, requesting approval) fixes the cabs thing
on IRIX.  The problem is that this function is defined in libm on IRIX
and prototyped in math.h.  That leads to a clash with complex-stub.h
and (because the prototype is different) doesn't let us call the
function from within abs(complex<FLOAT>).

This patch fixes it, but is sort-of ugly.  To some extent, dealing
with lots of systems makes for some inevitable ugliness, but maybe
someone can do better?

Anyhow, here's the patch.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-10-29  Mark Mitchell  <mark@codesourcery.com>

	* acinclude.m4 (GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT): Check 
	for cabs, cabsf, and cabsl, too.
	* aclocal.m4: Regenerated.
	* config.h.in: Likewise.
	* configure: Likewise.
	* libmath/Makefile.am (libmath_la_SOURCES): Remove cabs.c and
	cabsf.c.
	* libmath/Makefile.in: Regenerated.
	* libmath/complex-stub.h (cabs): Don't declare if the system
	already provides this function.
	(cabsf): Likewise.
	(cabsl): Likewise.
	* src/complex.cc (abs): Directly use `hypot' since we can't call
	cabs on IRIX.

Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/acinclude.m4,v
retrieving revision 1.74
diff -c -p -r1.74 acinclude.m4
*** acinclude.m4	2000/10/29 21:05:06	1.74
--- acinclude.m4	2000/10/29 22:26:25
*************** dnl GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT
*** 725,733 ****
  AC_DEFUN(GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT, [
    dnl Check for complex versions of math functions of platform.
    AC_CHECK_HEADERS([complex.h])
!   AC_REPLACE_MATHFUNCS(ccos ccosf ccosh ccoshf cexp cexpf c_log c_logf \
!   clog10 clog10f cpow cpowf csin csinf csinh csinhf csqrt csqrtf \
!   ctan ctanf ctanh ctanhf carg cargf nan hypot hypotf atan2f expf copysignf)
  
    dnl Compile the long double complex functions only if the function 
    dnl provides the non-complex long double functions that are needed.
--- 725,735 ----
  AC_DEFUN(GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT, [
    dnl Check for complex versions of math functions of platform.
    AC_CHECK_HEADERS([complex.h])
!   AC_CHECK_LIB(m, main)
!   AC_REPLACE_MATHFUNCS(cabs cabsf ccos ccosf ccosh ccoshf cexp cexpf \
!   c_log c_logf clog10 clog10f cpow cpowf csin csinf csinh csinhf csqrt \
!   csqrtf ctan ctanf ctanh ctanhf carg cargf nan hypot hypotf atan2f expf \
!   copysignf)
  
    dnl Compile the long double complex functions only if the function 
    dnl provides the non-complex long double functions that are needed.
*************** AC_DEFUN(GLIBCPP_CHECK_COMPLEX_MATH_SUPP
*** 737,743 ****
    if test x$ac_cv_func_atan2l = x"yes" \
       && test x$ac_cv_func_copysignl = x"yes"; then
      USE_COMPLEX_LONG_DOUBLE=yes
!     AC_REPLACE_MATHFUNCS(ccoshl ccosl cexpl cpowl csinhl csinl \
      csqrtl ctanhl ctanl cargl hypotl signbitl c_logl clog10l)
    fi
  
--- 739,745 ----
    if test x$ac_cv_func_atan2l = x"yes" \
       && test x$ac_cv_func_copysignl = x"yes"; then
      USE_COMPLEX_LONG_DOUBLE=yes
!     AC_REPLACE_MATHFUNCS(cabsl ccoshl ccosl cexpl cpowl csinhl csinl \
      csqrtl ctanhl ctanl cargl hypotl signbitl c_logl clog10l)
    fi
  
Index: libmath/Makefile.am
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libmath/Makefile.am,v
retrieving revision 1.4
diff -c -p -r1.4 Makefile.am
*** Makefile.am	2000/10/12 11:45:22	1.4
--- Makefile.am	2000/10/29 22:26:32
*************** libmath_la_LIBADD = \
*** 46,52 ****
  libmath_la_DEPENDENCIES = $(libmath_la_LIBADD)
  
  libmath_la_SOURCES = \
! 	signbit.c signbitf.c cabs.c cabsf.c 
  
  LINK = $(LIBTOOL) --mode=link "$(CCLD)" $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
  
--- 46,52 ----
  libmath_la_DEPENDENCIES = $(libmath_la_LIBADD)
  
  libmath_la_SOURCES = \
! 	signbit.c signbitf.c
  
  LINK = $(LIBTOOL) --mode=link "$(CCLD)" $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
  
Index: libmath/complex-stub.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libmath/complex-stub.h,v
retrieving revision 1.1
diff -c -p -r1.1 complex-stub.h
*** complex-stub.h	2000/10/07 01:01:45	1.1
--- complex-stub.h	2000/10/29 22:26:32
*************** double carg (__complex__ double x);
*** 78,86 ****
--- 78,94 ----
  float cargf (__complex__ float x);
  long double cargl (__complex__ long double x);
  
+ /* Some systems (like IRIX 6.5) already define these functions in 
+    <math.h>.  */
+ #ifndef _GLIBCPP_HAVE_CABS
  double cabs (__complex__ double x);
+ #endif /* defined(_GLIBCPP_HAVE_CABS) */
+ #ifndef _GLIBCPP_HAVE_CABSF
  float cabsf (__complex__ float x);
+ #endif /* defined(_GLIBCPP_HAVE_CABSF) */
+ #ifndef _GLIBCPP_HAVE_CABSL
  long double cabsl (__complex__ long double x);
+ #endif /* defined(_GLIBCPP_HAVE_CABSL) */
  
  #endif
  
Index: src/complex.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/complex.cc,v
retrieving revision 1.3
diff -c -p -r1.3 complex.cc
*** complex.cc	2000/10/05 11:36:52	1.3
--- complex.cc	2000/10/29 22:26:32
***************
*** 1,6 ****
  // The template and inlines for the -*- C++ -*- complex number classes.
  
! // Copyright (C) 1997-1999 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
--- 1,6 ----
  // The template and inlines for the -*- C++ -*- complex number classes.
  
! // Copyright (C) 1997-2000 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
  // software; you can redistribute it and/or modify it under the
*************** namespace std
*** 48,54 ****
    template<>
    FLT
    abs(const complex<FLT>& __x)
!   { return cabs(__x._M_value); }
  
    template<>
    FLT
--- 48,58 ----
    template<>
    FLT
    abs(const complex<FLT>& __x)
!   { 
!     // We don't use cabs here because some systems (IRIX 6.5, for
!     // example) define their own incompatible version.
!     return hypot (__real__ __x._M_value, __imag__ __x._M_value); 
!   }
  
    template<>
    FLT

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