Hello!

Currently, gfortran.dg/erf_3.F90 FAILs on targets with 128bit
(quadruple) long double, since high-precision erfc_scaled_r16 gets
defined only for __float128 quadruple precision.

Attached patch defines this function also for 128bit long double targets.

[BTW: The patch really implements what FX's ChangeLog says:

    * intrinsics/erfc_scaled_inc.c: Do not provide quadruple
    precision variant.]

2013-12-01  Uros Bizjak  <ubiz...@gmail.com>

    PR libfortran/59313
    * intrinsics/erfc_scaled.c (erfc_scaled_r16): Also provide for
    quadruple precision long double variant.

Tested on x86_64-pc-linux-gnu and alphaev68-pc-linux-gnu.

OK for mainline?

Uros.
Index: intrinsics/erfc_scaled.c
===================================================================
--- intrinsics/erfc_scaled.c    (revision 205539)
+++ intrinsics/erfc_scaled.c    (working copy)
@@ -45,33 +45,50 @@ see the files COPYING3 and COPYING.RUNTIME respect
 #include "erfc_scaled_inc.c"
 #endif
 
-#if defined(HAVE_GFC_REAL_16) && defined(GFC_REAL_16_IS_LONG_DOUBLE)
-#undef KIND
-#define KIND 16
-#include "erfc_scaled_inc.c"
-#endif
+#ifdef HAVE_GFC_REAL_16
 
+/* For quadruple-precision, netlib's implementation is
+   not accurate enough.  We provide another one.  */
 
 #ifdef GFC_REAL_16_IS_FLOAT128
 
-/* For quadruple-precision (__float128), netlib's implementation is
-   not accurate enough.  We provide another one.  */
+# define _THRESH -106.566990228185312813205074546585730Q
+# define _M_2_SQRTPI M_2_SQRTPIq
+# define _INF __builtin_infq()
+# define _ERFC(x) erfcq(x)
+# define _EXP(x) expq(x)
 
+#else
+
+# define _THRESH -106.566990228185312813205074546585730L
+# define _M_2_SQRTPI M_2_SQRTPIl
+# define _INF __builtin_infl()
+# ifdef HAVE_ERFCL
+#  define _ERFC(x) erfcl(x)
+# endif
+# ifdef HAVE_EXPL
+#  define _EXP(x) expl(x)
+# endif
+
+#endif
+
+#if defined(_ERFC) && defined(_EXP)
+
 extern GFC_REAL_16 erfc_scaled_r16 (GFC_REAL_16);
 export_proto(erfc_scaled_r16);
 
 GFC_REAL_16
 erfc_scaled_r16 (GFC_REAL_16 x)
 {
-  if (x < -106.566990228185312813205074546585730Q)
+  if (x < _THRESH)
     {
-      return __builtin_infq();
+      return _INF;
     }
   if (x < 12)
     {
       /* Compute directly as ERFC_SCALED(x) = ERFC(x) * EXP(X**2).
         This is not perfect, but much better than netlib.  */
-      return erfcq(x) * expq(x * x);
+      return _ERFC(x) * _EXP(x * x);
     }
   else
     {
@@ -97,9 +114,10 @@ erfc_scaled_r16 (GFC_REAL_16 x)
          n++;
        }
 
-      return (1 + sum) / x * (M_2_SQRTPIq / 2);
+      return (1 + sum) / x * (_M_2_SQRTPI / 2);
     }
 }
 
 #endif
 
+#endif
Index: intrinsics/erfc_scaled_inc.c
===================================================================
--- intrinsics/erfc_scaled_inc.c        (revision 205539)
+++ intrinsics/erfc_scaled_inc.c        (working copy)
@@ -39,7 +39,7 @@ see the files COPYING3 and COPYING.RUNTIME respect
 # define EXP(x) exp(x)
 # define TRUNC(x) trunc(x)
 
-#elif (KIND == 10) || (KIND == 16 && defined(GFC_REAL_16_IS_LONG_DOUBLE))
+#elif (KIND == 10)
 
 # ifdef HAVE_EXPL
 #  define EXP(x) expl(x)

Reply via email to