(obstack_free): Explicitly convert __obj to
[kopensolaris-gnu/glibc.git] / math / tgmath.h
index 4c7d957..1a6591e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    only defined on real valued parameters and those which are defined
    for complex functions as well.  */
 # define __TGMATH_UNARY_REAL_ONLY(Val, Fct) \
-     (__extension__ (sizeof (__real__ (Val)) == sizeof (long double)         \
-                    ? Fct##l (Val)                                           \
-                    : (sizeof (__real__ (Val)) == sizeof (double)            \
-                       ? Fct (Val)                                           \
-                       : Fct##f (Val))))
+     (__extension__ ({ __typeof__ (Val) __tgmres;                            \
+                      if (sizeof (Val) == sizeof (double))                   \
+                        __tgmres = Fct (Val);                                \
+                      else if (sizeof (Val) == sizeof (float))               \
+                        __tgmres = Fct##f (Val);                             \
+                      else                                                   \
+                        __tgmres = Fct##l (Val);                             \
+                      __tgmres; }))
 
 # define __TGMATH_BINARY_FIRST_REAL_ONLY(Val1, Val2, Fct) \
-     (__extension__ (sizeof (__real__ (Val1)) == sizeof (long double)        \
-                    ? Fct##l (Val1, Val2)                                    \
-                    : (sizeof (__real__ (Val1)) == sizeof (double)           \
-                       ? Fct (Val1, Val2)                                    \
-                       : Fct##f (Val1, Val2))))
+     (__extension__ ({ __typeof__ (Val1) __tgmres;                           \
+                      if (sizeof (Val1) == sizeof (double))                  \
+                        __tgmres = Fct (Val1, Val2);                         \
+                      else if (sizeof (Val1) == sizeof (float))              \
+                        __tgmres = Fct##f (Val1, Val2);                      \
+                      else                                                   \
+                        __tgmres = Fct##l (Val1, Val2);                      \
+                      __tgmres; }))
 
 # define __TGMATH_BINARY_REAL_ONLY(Val1, Val2, Fct) \
-     (__extension__ (sizeof (Val1) == sizeof (long double)                   \
-                    || sizeof (Val2) == sizeof (long double)                 \
-                    ? Fct##l (Val1, Val2)                                    \
-                    : (sizeof (Val1) == sizeof (double)                      \
-                       || sizeof (Val2) == sizeof (double)                   \
-                       ? Fct (Val1, Val2)                                    \
-                       : Fct##f (Val1, Val2))))
+     (__extension__ ({ __typeof__ ((Val1) + (Val2)) __tgmres;                \
+                      if (sizeof (Val1) > sizeof (double)                    \
+                          || sizeof (Val2) > sizeof (double))                \
+                        __tgmres = Fct##l (Val1, Val2);                      \
+                      else if (sizeof (Val1) == sizeof (double)              \
+                               || sizeof (Val2) == sizeof (double))          \
+                        __tgmres = Fct (Val1, Val2);                         \
+                      else                                                   \
+                        __tgmres = Fct (Val1, Val2);                         \
+                      __tgmres; }))
 
 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
-     (__extension__ (sizeof (Val1) == sizeof (long double)                   \
-                    || sizeof (Val2) == sizeof (long double)                 \
-                    ? Fct##l (Val1, Val2, Val3)                              \
-                    : (sizeof (Val1) == sizeof (double)                      \
-                       || sizeof (Val2) == sizeof (double)                   \
-                       ? Fct (Val1, Val2, Val3)                              \
-                       : Fct##f (Val1, Val2, Val3))))
-
+     (__extension__ ({ __typeof__ ((Val1) + (Val2)) __tgmres;                \
+                      if (sizeof (Val1) > sizeof (double)                    \
+                          || sizeof (Val2) > sizeof (double))                \
+                        __tgmres = Fct##l (Val1, Val2, Val3);                \
+                      else if (sizeof (Val1) == sizeof (double)              \
+                               || sizeof (Val2) == sizeof (double))          \
+                        __tgmres = Fct (Val1, Val2, Val3);                   \
+                      else                                                   \
+                        __tgmres = Fct (Val1, Val2, Val3);                   \
+                      __tgmres; }))
+
+# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
+     (__extension__ ({ __typeof__ ((Val1) + (Val2) + (Val3)) __tgmres;       \
+                      if (sizeof (Val1) > sizeof (double)                    \
+                          || sizeof (Val2) > sizeof (double)                 \
+                          || sizeof (Val3) > sizeof (double))                \
+                        __tgmres = Fct##l (Val1, Val2, Val3);                \
+                      else if (sizeof (Val1) == sizeof (double)              \
+                               || sizeof (Val2) == sizeof (double)           \
+                               || sizeof (Val3) == sizeof (double))          \
+                        __tgmres = Fct (Val1, Val2, Val3);                   \
+                      else                                                   \
+                        __tgmres = Fct (Val1, Val2, Val3);                   \
+                      __tgmres; }))
+
+/* 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__ (sizeof (__real__ (Val)) == sizeof (long double)         \
-                    ? (sizeof (__real__ (Val)) == sizeof (Val)               \
-                       ? Fct##l (Val)                                        \
-                       : Cfct##l (Val))                                      \
-                    : (sizeof (__real__ (Val)) == sizeof (double)            \
-                       ? (sizeof (__real__ (Val)) == sizeof (Val)            \
-                          ? Fct (Val)                                        \
-                          : Cfct (Val))                                      \
-                       : (sizeof (__real__ (Val)) == sizeof (Val)            \
-                          ? Fct##f (Val)                                     \
-                          : Cfct##f (Val)))))
-
+     (__extension__ ({ __typeof__ (Val) __tgmres;                            \
+                      if (sizeof (__real__ (Val)) > sizeof (double))         \
+                        {                                                    \
+                          if (sizeof (__real__ (Val)) == sizeof (Val))       \
+                            __tgmres = Fct##l (Val);                         \
+                          else                                               \
+                            __tgmres = Cfct##l (Val);                        \
+                        }                                                    \
+                      else if (sizeof (__real__ (Val)) == sizeof (double))   \
+                        {                                                    \
+                          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; }))
+
+/* XXX This definition has to be changed as soon as the compiler understands
+   the imaginary keyword.  */
 # define __TGMATH_UNARY_IMAG_ONLY(Val, Fct) \
-     (__extension__ (sizeof (Val) == sizeof (__complex__ long double)        \
-                    ? Fct##l (Val)                                           \
-                    : (sizeof (Val) == sizeof (__complex__ double)           \
-                       ? Fct (Val)                                           \
-                       : Fct##f (Val))))
-
+     (__extension__ ({ __typeof__ (Val) __tgmres;                            \
+                      if (sizeof (Val) == sizeof (__complex__ double))       \
+                        __tgmres = Fct (Val);                                \
+                      else if (sizeof (Val) == sizeof (__complex__ float))   \
+                        __tgmres = Fct##f (Val);                             \
+                      else                                                   \
+                        __tgmres = Fct##l (Val);                             \
+                      __tgmres; }))
+
+/* 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__ (sizeof (__real__ (Val1)) == sizeof (long double)        \
-                    || sizeof (__real__ (Val2)) == sizeof (long double)      \
-                    ? (sizeof (__real__ (Val1)) == sizeof (Val1)             \
-                       && sizeof (__real__ (Val2)) == sizeof (Val2)          \
-                       ? Fct##l (Val1, Val2)                                 \
-                       : Cfct##l (Val1, Val2))                               \
-                    : (sizeof (__real__ (Val1)) == sizeof (double)           \
-                       || sizeof (__real__ (Val2)) == sizeof (double)        \
-                       ? (sizeof (__real__ (Val1)) == sizeof (Val1)          \
-                          && sizeof (__real__ (Val2)) == sizeof (Val2)       \
-                          ? Fct (Val1, Val2)                                 \
-                          : Cfct (Val1, Val2))                               \
-                       : (sizeof (__real__ (Val1)) == sizeof (Val1)          \
-                          && sizeof (__real__ (Val2)) == sizeof (Val2)       \
-                          ? Fct##f (Val1, Val2)                              \
-                          : Cfct##f (Val1, Val2)))))
+     (__extension__ ({ __typeof__ ((Val1) + (Val2)) __tgmres;                \
+                      if (sizeof (__real__ (Val1)) > sizeof (double)         \
+                          || sizeof (__real__ (Val2)) > sizeof (double))     \
+                        {                                                    \
+                          if (sizeof (__real__ (Val1)) == sizeof (Val1)      \
+                              && sizeof (__real__ (Val2)) == sizeof (Val2))  \
+                            __tgmres = Fct##l (Val1, Val2);                  \
+                          else                                               \
+                            __tgmres = Cfct##l (Val1, Val2);                 \
+                        }                                                    \
+                      else if (sizeof (__real__ (Val1)) == sizeof (double)   \
+                               || sizeof (__real__ (Val2)) == sizeof(double))\
+                        {                                                    \
+                          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; }))
 #else
 # error "Unsupported compiler; you cannot use <tgmath.h>"
 #endif
 /* Arc tangent of X.  */
 #define atan(Val) __TGMATH_UNARY_REAL_IMAG (Val, atan, catan)
 /* Arc tangent of Y/X.  */
-#define atan2(Val) __TGMATH_UNARY_REAL_ONLY (Val, atan2)
+#define atan2(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, atan2)
 
 /* Cosine of X.  */
 #define cos(Val) __TGMATH_UNARY_REAL_IMAG (Val, cos, ccos)
 #define log(Val) __TGMATH_UNARY_REAL_IMAG (Val, log, clog)
 
 /* Base-ten logarithm of X.  */
-#define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, __clog10)
+#ifdef __USE_GNU
+# define log10(Val) __TGMATH_UNARY_REAL_IMAG (Val, log10, __clog10)
+#else
+# define log10(Val) __TGMATH_UNARY_REAL_ONLY (Val, log10)
+#endif
 
 /* Return exp(X) - 1.  */
 #define expm1(Val) __TGMATH_UNARY_REAL_ONLY (Val, expm1)
 
 /* Return X + epsilon if X < Y, X - epsilon if X > Y.  */
 #define nextafter(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, nextafter)
-#define nextafterx(Val1, Val2) \
-     __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nextafterx)
+#define nexttoward(Val1, Val2) \
+     __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, nexttoward)
 
 /* Return the remainder of integer divison X / Y with infinite precision.  */
 #define remainder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, remainder)
 
 /* Return X times (2 to the Nth power).  */
+#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
 #define scalb(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, scalb)
+#endif
 
 /* Return X times (2 to the Nth power).  */
 #define scalbn(Val1, Val2) __TGMATH_BINARY_FIRST_REAL_ONLY (Val1, Val2, scalbn)
 #define fmin(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fmin)
 
 
+/* Multiply-add function computed as a ternary operation.  */
+#define fma(Vat1, Val2, Val3) \
+     __TGMATH_TERNARY_REAL_ONLY (Val1, Val2, Val3, fma)
+
+
 /* Absolute value, conjugates, and projection.  */
 
 /* Argument value of Z.  */