]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - math/s_ctan_template.c
Convert _Complex tangent functions to generated code
[thirdparty/glibc.git] / math / s_ctan_template.c
index 8e8bf2ee2bb8aa7cd3ea2586420a075c9e1ca402..96efa47465b766db79770e909dd489779c3a4009 100644 (file)
@@ -1,4 +1,4 @@
-/* Complex tangent function for double.
+/* Complex tangent function for a complex float type.
    Copyright (C) 1997-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 #include <math_private.h>
 #include <float.h>
 
-__complex__ double
-__ctan (__complex__ double x)
+CFLOAT
+M_DECL_FUNC (__ctan) (CFLOAT x)
 {
-  __complex__ double res;
+  CFLOAT res;
 
   if (__glibc_unlikely (!isfinite (__real__ x) || !isfinite (__imag__ x)))
     {
       if (isinf (__imag__ x))
        {
-         if (isfinite (__real__ x) && fabs (__real__ x) > 1.0)
+         if (isfinite (__real__ x) && M_FABS (__real__ x) > 1)
            {
-             double sinrx, cosrx;
-             __sincos (__real__ x, &sinrx, &cosrx);
-             __real__ res = __copysign (0.0, sinrx * cosrx);
+             FLOAT sinrx, cosrx;
+             M_SINCOS (__real__ x, &sinrx, &cosrx);
+             __real__ res = M_COPYSIGN (0, sinrx * cosrx);
            }
          else
-           __real__ res = __copysign (0.0, __real__ x);
-         __imag__ res = __copysign (1.0, __imag__ x);
+           __real__ res = M_COPYSIGN (0, __real__ x);
+         __imag__ res = M_COPYSIGN (1, __imag__ x);
        }
-      else if (__real__ x == 0.0)
+      else if (__real__ x == 0)
        {
          res = x;
        }
       else
        {
-         __real__ res = __nan ("");
-         __imag__ res = __nan ("");
+         __real__ res = M_NAN;
+         __imag__ res = M_NAN;
 
          if (isinf (__real__ x))
            feraiseexcept (FE_INVALID);
@@ -57,34 +57,34 @@ __ctan (__complex__ double x)
     }
   else
     {
-      double sinrx, cosrx;
-      double den;
-      const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2);
+      FLOAT sinrx, cosrx;
+      FLOAT den;
+      const int t = (int) ((M_MAX_EXP - 1) * M_MLIT (M_LN2) / 2);
 
       /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y))
         = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */
 
-      if (__glibc_likely (fabs (__real__ x) > DBL_MIN))
+      if (__glibc_likely (M_FABS (__real__ x) > M_MIN))
        {
-         __sincos (__real__ x, &sinrx, &cosrx);
+         M_SINCOS (__real__ x, &sinrx, &cosrx);
        }
       else
        {
          sinrx = __real__ x;
-         cosrx = 1.0;
+         cosrx = 1;
        }
 
-      if (fabs (__imag__ x) > t)
+      if (M_FABS (__imag__ x) > t)
        {
          /* Avoid intermediate overflow when the real part of the
             result may be subnormal.  Ignoring negligible terms, the
             imaginary part is +/- 1, the real part is
             sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y).  */
-         double exp_2t = __ieee754_exp (2 * t);
+         FLOAT exp_2t = M_EXP (2 * t);
 
-         __imag__ res = __copysign (1.0, __imag__ x);
+         __imag__ res = M_COPYSIGN (1, __imag__ x);
          __real__ res = 4 * sinrx * cosrx;
-         __imag__ x = fabs (__imag__ x);
+         __imag__ x = M_FABS (__imag__ x);
          __imag__ x -= t;
          __real__ res /= exp_2t;
          if (__imag__ x > t)
@@ -94,23 +94,23 @@ __ctan (__complex__ double x)
              __real__ res /= exp_2t;
            }
          else
-           __real__ res /= __ieee754_exp (2 * __imag__ x);
+           __real__ res /= M_EXP (2 * __imag__ x);
        }
       else
        {
-         double sinhix, coshix;
-         if (fabs (__imag__ x) > DBL_MIN)
+         FLOAT sinhix, coshix;
+         if (M_FABS (__imag__ x) > M_MIN)
            {
-             sinhix = __ieee754_sinh (__imag__ x);
-             coshix = __ieee754_cosh (__imag__ x);
+             sinhix = M_SINH (__imag__ x);
+             coshix = M_COSH (__imag__ x);
            }
          else
            {
              sinhix = __imag__ x;
-             coshix = 1.0;
+             coshix = 1;
            }
 
-         if (fabs (sinhix) > fabs (cosrx) * DBL_EPSILON)
+         if (M_FABS (sinhix) > M_FABS (cosrx) * M_EPSILON)
            den = cosrx * cosrx + sinhix * sinhix;
          else
            den = cosrx * cosrx;
@@ -122,8 +122,9 @@ __ctan (__complex__ double x)
 
   return res;
 }
-weak_alias (__ctan, ctan)
-#ifdef NO_LONG_DOUBLE
-strong_alias (__ctan, __ctanl)
-weak_alias (__ctan, ctanl)
+
+declare_mgen_alias (__ctan, ctan)
+
+#if M_LIBM_NEED_COMPAT (ctan)
+declare_mgen_libm_compat (__ctan, ctan)
 #endif