summaryrefslogtreecommitdiff
path: root/math/tgmath.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-07-12 18:17:11 +0000
committerUlrich Drepper <drepper@redhat.com>2007-07-12 18:17:11 +0000
commit1c298d08873e72a2339161517da660bdaff0e3f8 (patch)
tree8dc2c8b8521576cc303468e3203db0eb4d262b0a /math/tgmath.h
parentf98c2d06bb4e04e59bb067b301bacf880fb72a9f (diff)
downloadglibc-1c298d08873e72a2339161517da660bdaff0e3f8.tar.gz
[BZ #4775, BZ #4776]
2007-07-12 Jakub Jelinek <jakub@redhat.com> [BZ #4775] * math/tgmath.h (__tgmath_real_type_sub): Formatting. (__tgmath_real_type): Fix if expr is const int or other const qualified integral type. (__TGMATH_UNARY_REAL_ONLY): Rewritten to avoid using statement expressions and handle const qualified arguments. (__TGMATH_BINARY_FIRST_REAL_ONLY, __TGMATH_UNARY_REAL_IMAG, __TGMATH_UNARY_REAL_IMAG_RET_REAL): Likewise. (__TGMATH_UNARY_REAL_RET_ONLY): Rewritten to avoid using statement expressions. (__TGMATH_BINARY_REAL_ONLY, __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY, __TGMATH_TERNARY_REAL_ONLY, __TGMATH_BINARY_REAL_IMAG): Likewise. (__TGMATH_UNARY_IMAG): Define. (conj, cproj): Use __TGMATH_UNARY_IMAG macro. * math/Makefile (tests): Add test-tgmath2. (CFLAGS-test-tgmath2.c): Add. * math/test-tgmath.c (fy, dy, ly, fz, dz, lz, count_cdouble, count_cfloat, count_cldouble): New variables. (NCCALLS): Define. (main): Check number of complex calls as well. (F(compile_test)): Add complex tests and tests with const qualified arguments. (y, z, ccount): Define. (F(cacos), F(casin), F(catan), F(ccos), F(csin), F(ctan), F(cacosh), F(casinh), F(catanh), F(ccosh), F(csinh), F(ctanh), F(cexp), F(clog), F(csqrt), F(cpow), F(cabs), F(carg), F(creal), F(cimag), F(conj), F(cproj)): New functions. * math/test-tgmath2.c: New test. 2007-07-11 Jakub Jelinek <jakub@redhat.com> [BZ #4776] * elf/dl-load.c (_dl_rtld_di_serinfo): Output / in LD_LIBRARY_PATH, RPATH etc. as "/" rather than "", don't segfault on empty paths, instead output ".". * dlfcn/Makefile (distribute): Add glreflib3.c. (module-names): Add glreflib3. ($(objpfx)tst-dlinfo.out): Depend on glreflib3.so rather than glreflib1.so. (LDFLAGS_glreflib3.so): New. * dlfcn/tst-dlinfo.c (do_test): Load glreflib3.so instead of glreflib1.so. * dlfcn/glreflib3.c: New file. * intl/finddomain.c (_nl_find_domain): If _nl_explode_name returned -1, return NULL. * intl/explodename.c (_nl_explode_name): Return -1 if _nl_normalize_codeset failed.
Diffstat (limited to 'math/tgmath.h')
-rw-r--r--math/tgmath.h321
1 files changed, 153 insertions, 168 deletions
diff --git a/math/tgmath.h b/math/tgmath.h
index f3d23f6e52..4f45aaa0f2 100644
--- a/math/tgmath.h
+++ b/math/tgmath.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
+/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -53,202 +53,187 @@
/* The tgmath real type for T, where E is 0 if T is an integer type and
1 for a floating type. */
# define __tgmath_real_type_sub(T, E) \
- __typeof__(*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
- : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
+ __typeof__ (*(0 ? (__typeof__ (0 ? (double *) 0 : (void *) (E))) 0 \
+ : (__typeof__ (0 ? (T *) 0 : (void *) (!(E)))) 0))
/* The tgmath real type of EXPR. */
# define __tgmath_real_type(expr) \
- __tgmath_real_type_sub(__typeof__(expr), __floating_type(__typeof__(expr)))
+ __tgmath_real_type_sub (__typeof__ ((__typeof__ (expr)) 0), \
+ __floating_type (__typeof__ (expr)))
/* We have two kinds of generic macros: to support functions which are
only defined on real valued parameters and those which are defined
for complex functions as well. */
# define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
- (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
- if (sizeof (Val) == sizeof (double) \
- || __builtin_classify_type (Val) != 8) \
- __tgmres = Fct (Val); \
- else if (sizeof (Val) == sizeof (float)) \
- __tgmres = Fct##f (Val); \
- else \
- __tgmres = __tgml(Fct) (Val); \
- __tgmres; }))
+ (__extension__ ((sizeof (Val) == sizeof (double) \
+ || __builtin_classify_type (Val) != 8) \
+ ? (__tgmath_real_type (Val)) Fct (Val) \
+ : (sizeof (Val) == sizeof (float)) \
+ ? (__tgmath_real_type (Val)) Fct##f (Val) \
+ : (__tgmath_real_type (Val)) __tgml(Fct) (Val)))
# define __TGMATH_UNARY_REAL_RET_ONLY(Val, RetType, Fct) \
- (__extension__ ({ RetType __tgmres; \
- if (sizeof (Val) == sizeof (double) \
- || __builtin_classify_type (Val) != 8) \
- __tgmres = Fct (Val); \
- else if (sizeof (Val) == sizeof (float)) \
- __tgmres = Fct##f (Val); \
- else \
- __tgmres = __tgml(Fct) (Val); \
- __tgmres; }))
+ (__extension__ ((sizeof (Val) == sizeof (double) \
+ || __builtin_classify_type (Val) != 8) \
+ ? (RetType) Fct (Val) \
+ : (sizeof (Val) == sizeof (float)) \
+ ? (RetType) Fct##f (Val) \
+ : (RetType) __tgml(Fct) (Val)))
# define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
- (__extension__ ({ __tgmath_real_type (Val1) __tgmres; \
- if (sizeof (Val1) == sizeof (double) \
- || __builtin_classify_type (Val1) != 8) \
- __tgmres = Fct (Val1, Val2); \
- else if (sizeof (Val1) == sizeof (float)) \
- __tgmres = Fct##f (Val1, Val2); \
- else \
- __tgmres = __tgml(Fct) (Val1, Val2); \
- __tgmres; }))
+ (__extension__ ((sizeof (Val1) == sizeof (double) \
+ || __builtin_classify_type (Val1) != 8) \
+ ? (__tgmath_real_type (Val1)) Fct (Val1, Val2) \
+ : (sizeof (Val1) == sizeof (float)) \
+ ? (__tgmath_real_type (Val1)) Fct##f (Val1, Val2) \
+ : (__tgmath_real_type (Val1)) __tgml(Fct) (Val1, Val2)))
# define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
- (__extension__ ({ __typeof((__tgmath_real_type (Val1)) 0 \
- + (__tgmath_real_type (Val2)) 0) __tgmres; \
- if ((sizeof (Val1) > sizeof (double) \
- || sizeof (Val2) > sizeof (double)) \
- && __builtin_classify_type ((Val1) + (Val2)) == 8) \
- __tgmres = __tgml(Fct) (Val1, Val2); \
- else if (sizeof (Val1) == sizeof (double) \
- || sizeof (Val2) == sizeof (double) \
- || __builtin_classify_type (Val1) != 8 \
- || __builtin_classify_type (Val2) != 8) \
- __tgmres = Fct (Val1, Val2); \
- else \
- __tgmres = Fct##f (Val1, Val2); \
- __tgmres; }))
+ (__extension__ (((sizeof (Val1) > sizeof (double) \
+ || sizeof (Val2) > sizeof (double)) \
+ && __builtin_classify_type ((Val1) + (Val2)) == 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ __tgml(Fct) (Val1, Val2) \
+ : (sizeof (Val1) == sizeof (double) \
+ || sizeof (Val2) == sizeof (double) \
+ || __builtin_classify_type (Val1) != 8 \
+ || __builtin_classify_type (Val2) != 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct (Val1, Val2) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct##f (Val1, Val2)))
# define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
- (__extension__ ({ __typeof((__tgmath_real_type (Val1)) 0 \
- + (__tgmath_real_type (Val2)) 0) __tgmres; \
- if ((sizeof (Val1) > sizeof (double) \
- || sizeof (Val2) > sizeof (double)) \
- && __builtin_classify_type ((Val1) + (Val2)) == 8) \
- __tgmres = __tgml(Fct) (Val1, Val2, Val3); \
- else if (sizeof (Val1) == sizeof (double) \
- || sizeof (Val2) == sizeof (double) \
- || __builtin_classify_type (Val1) != 8 \
- || __builtin_classify_type (Val2) != 8) \
- __tgmres = Fct (Val1, Val2, Val3); \
- else \
- __tgmres = Fct##f (Val1, Val2, Val3); \
- __tgmres; }))
+ (__extension__ (((sizeof (Val1) > sizeof (double) \
+ || sizeof (Val2) > sizeof (double)) \
+ && __builtin_classify_type ((Val1) + (Val2)) == 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ __tgml(Fct) (Val1, Val2, Val3) \
+ : (sizeof (Val1) == sizeof (double) \
+ || sizeof (Val2) == sizeof (double) \
+ || __builtin_classify_type (Val1) != 8 \
+ || __builtin_classify_type (Val2) != 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct (Val1, Val2, Val3) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct##f (Val1, Val2, Val3)))
# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
- (__extension__ ({ __typeof((__tgmath_real_type (Val1)) 0 \
- + (__tgmath_real_type (Val2)) 0 \
- + (__tgmath_real_type (Val3)) 0) __tgmres; \
- if ((sizeof (Val1) > sizeof (double) \
- || sizeof (Val2) > sizeof (double) \
- || sizeof (Val3) > sizeof (double)) \
- && __builtin_classify_type ((Val1) + (Val2) \
- + (Val3)) == 8) \
- __tgmres = __tgml(Fct) (Val1, Val2, Val3); \
- else if (sizeof (Val1) == sizeof (double) \
- || sizeof (Val2) == sizeof (double) \
- || sizeof (Val3) == sizeof (double) \
- || __builtin_classify_type (Val1) != 8 \
- || __builtin_classify_type (Val2) != 8 \
- || __builtin_classify_type (Val3) != 8) \
- __tgmres = Fct (Val1, Val2, Val3); \
- else \
- __tgmres = Fct##f (Val1, Val2, Val3); \
- __tgmres; }))
+ (__extension__ (((sizeof (Val1) > sizeof (double) \
+ || sizeof (Val2) > sizeof (double) \
+ || sizeof (Val3) > sizeof (double)) \
+ && __builtin_classify_type ((Val1) + (Val2) + (Val3)) \
+ == 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0 \
+ + (__tgmath_real_type (Val3)) 0)) \
+ __tgml(Fct) (Val1, Val2, Val3) \
+ : (sizeof (Val1) == sizeof (double) \
+ || sizeof (Val2) == sizeof (double) \
+ || sizeof (Val3) == sizeof (double) \
+ || __builtin_classify_type (Val1) != 8 \
+ || __builtin_classify_type (Val2) != 8 \
+ || __builtin_classify_type (Val3) != 8) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0 \
+ + (__tgmath_real_type (Val3)) 0)) \
+ Fct (Val1, Val2, Val3) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0 \
+ + (__tgmath_real_type (Val3)) 0)) \
+ Fct##f (Val1, Val2, Val3)))
/* XXX This definition has to be changed as soon as the compiler understands
the imaginary keyword. */
# define __TGMATH_UNARY_REAL_IMAG(Val, Fct, Cfct) \
- (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
- if (sizeof (__real__ (Val)) > sizeof (double) \
- && __builtin_classify_type (__real__ (Val)) == 8) \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = __tgml(Fct) (Val); \
- else \
- __tgmres = __tgml(Cfct) (Val); \
- } \
- else if (sizeof (__real__ (Val)) == sizeof (double) \
- || __builtin_classify_type (__real__ (Val)) \
- != 8) \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = Fct (Val); \
- else \
- __tgmres = Cfct (Val); \
- } \
- else \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = Fct##f (Val); \
- else \
- __tgmres = Cfct##f (Val); \
- } \
- __tgmres; }))
+ (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
+ || __builtin_classify_type (__real__ (Val)) != 8) \
+ ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__tgmath_real_type (Val)) Fct (Val) \
+ : (__tgmath_real_type (Val)) Cfct (Val)) \
+ : (sizeof (__real__ (Val)) == sizeof (float)) \
+ ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__tgmath_real_type (Val)) Fct##f (Val) \
+ : (__tgmath_real_type (Val)) Cfct##f (Val)) \
+ : ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__tgmath_real_type (Val)) __tgml(Fct) (Val) \
+ : (__tgmath_real_type (Val)) __tgml(Cfct) (Val))))
+
+# define __TGMATH_UNARY_IMAG(Val, Cfct) \
+ (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
+ || __builtin_classify_type (__real__ (Val)) != 8) \
+ ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
+ + _Complex_I)) Cfct (Val) \
+ : (sizeof (__real__ (Val)) == sizeof (float)) \
+ ? (__typeof__ ((__tgmath_real_type (Val)) 0 \
+ + _Complex_I)) Cfct##f (Val) \
+ : (__typeof__ ((__tgmath_real_type (Val)) 0 \
+ + _Complex_I)) __tgml(Cfct) (Val)))
/* XXX This definition has to be changed as soon as the compiler understands
the imaginary keyword. */
# define __TGMATH_UNARY_REAL_IMAG_RET_REAL(Val, Fct, Cfct) \
- (__extension__ ({ __tgmath_real_type (Val) __tgmres; \
- if (sizeof (__real__ (Val)) > sizeof (double) \
- && __builtin_classify_type (__real__ (Val)) == 8) \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = __tgml(Fct) (Val); \
- else \
- __tgmres = __tgml(Cfct) (Val); \
- } \
- else if (sizeof (__real__ (Val)) == sizeof (double) \
- || __builtin_classify_type (__real__ (Val)) \
- != 8) \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = Fct (Val); \
- else \
- __tgmres = Cfct (Val); \
- } \
- else \
- { \
- if (sizeof (__real__ (Val)) == sizeof (Val)) \
- __tgmres = Fct##f (Val); \
- else \
- __tgmres = Cfct##f (Val); \
- } \
- __real__ __tgmres; }))
+ (__extension__ ((sizeof (__real__ (Val)) == sizeof (double) \
+ || __builtin_classify_type (__real__ (Val)) != 8) \
+ ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ Fct (Val) \
+ : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ Cfct (Val)) \
+ : (sizeof (__real__ (Val)) == sizeof (float)) \
+ ? ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ Fct##f (Val) \
+ : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ Cfct##f (Val)) \
+ : ((sizeof (__real__ (Val)) == sizeof (Val)) \
+ ? (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ __tgml(Fct) (Val) \
+ : (__typeof__ (__real__ (__tgmath_real_type (Val)) 0))\
+ __tgml(Cfct) (Val))))
/* XXX This definition has to be changed as soon as the compiler understands
the imaginary keyword. */
# define __TGMATH_BINARY_REAL_IMAG(Val1, Val2, Fct, Cfct) \
- (__extension__ ({ __typeof((__tgmath_real_type (Val1)) 0 \
- + (__tgmath_real_type (Val2)) 0) __tgmres; \
- if ((sizeof (__real__ (Val1)) > sizeof (double) \
- || sizeof (__real__ (Val2)) > sizeof (double)) \
- && __builtin_classify_type (__real__ (Val1) \
- + __real__ (Val2)) \
- == 8) \
- { \
- if (sizeof (__real__ (Val1)) == sizeof (Val1) \
- && sizeof (__real__ (Val2)) == sizeof (Val2)) \
- __tgmres = __tgml(Fct) (Val1, Val2); \
- else \
- __tgmres = __tgml(Cfct) (Val1, Val2); \
- } \
- else if (sizeof (__real__ (Val1)) == sizeof (double) \
- || sizeof (__real__ (Val2)) == sizeof(double) \
- || (__builtin_classify_type (__real__ (Val1)) \
- != 8) \
- || (__builtin_classify_type (__real__ (Val2)) \
- != 8)) \
- { \
- if (sizeof (__real__ (Val1)) == sizeof (Val1) \
- && sizeof (__real__ (Val2)) == sizeof (Val2)) \
- __tgmres = Fct (Val1, Val2); \
- else \
- __tgmres = Cfct (Val1, Val2); \
- } \
- else \
- { \
- if (sizeof (__real__ (Val1)) == sizeof (Val1) \
- && sizeof (__real__ (Val2)) == sizeof (Val2)) \
- __tgmres = Fct##f (Val1, Val2); \
- else \
- __tgmres = Cfct##f (Val1, Val2); \
- } \
- __tgmres; }))
+ (__extension__ (((sizeof (__real__ (Val1)) > sizeof (double) \
+ || sizeof (__real__ (Val2)) > sizeof (double)) \
+ && __builtin_classify_type (__real__ (Val1) \
+ + __real__ (Val2)) == 8) \
+ ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
+ && sizeof (__real__ (Val2)) == sizeof (Val2)) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ __tgml(Fct) (Val1, Val2) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ __tgml(Cfct) (Val1, Val2)) \
+ : (sizeof (__real__ (Val1)) == sizeof (double) \
+ || sizeof (__real__ (Val2)) == sizeof (double) \
+ || __builtin_classify_type (__real__ (Val1)) != 8 \
+ || __builtin_classify_type (__real__ (Val2)) != 8) \
+ ? ((sizeof (__real__ (Val1)) == sizeof (Val1) \
+ && sizeof (__real__ (Val2)) == sizeof (Val2)) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct (Val1, Val2) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Cfct (Val1, Val2)) \
+ : ((sizeof (__real__ (Val1)) == sizeof (Val1) \
+ && sizeof (__real__ (Val2)) == sizeof (Val2)) \
+ ? (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Fct##f (Val1, Val2) \
+ : (__typeof ((__tgmath_real_type (Val1)) 0 \
+ + (__tgmath_real_type (Val2)) 0)) \
+ Cfct##f (Val1, Val2))))
#else
# error "Unsupported compiler; you cannot use <tgmath.h>"
#endif
@@ -447,10 +432,10 @@
#define carg(Val) __TGMATH_UNARY_REAL_IMAG_RET_REAL (Val, carg, carg)
/* Complex conjugate of Z. */
-#define conj(Val) __TGMATH_UNARY_REAL_IMAG (Val, conj, conj)
+#define conj(Val) __TGMATH_UNARY_IMAG (Val, conj)
/* Projection of Z onto the Riemann sphere. */
-#define cproj(Val) __TGMATH_UNARY_REAL_IMAG (Val, cproj, cproj)
+#define cproj(Val) __TGMATH_UNARY_IMAG (Val, cproj)
/* Decomposing complex values. */