Add new templates for IEEE wrappers

Message ID 1487348516-18343-1-git-send-email-gftg@linux.vnet.ibm.com
State Committed
Delegated to: Joseph Myers
Headers

Commit Message

Gabriel F T Gomes Feb. 17, 2017, 4:21 p.m. UTC
  The functions implemented in these new wrapper templates are not built
for float, double, and long double.  This is intentional.

On the other hand, the new wrappers do get built for float128.  Since
float128 is only enabled on the float128 branch, I also tested this
patch on that branch.

---8<---
Several wrappers for IEEE functions use _LIB_VERSION / matherr /
__kernel_standard functionality, which we want to obsolete.  New
wrappers, such as for float128, must not use this functionality.

This patch adds new wrappers that only __set_errno and can be used by
the new float128 wrappers.

Tested for powerpc64le.

2017-02-17  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
	    Gabriel F. T. Gomes  <gftg@linux.vnet.ibm.com>

	* math/Makefile: Add wrappers to gen-libm-calls.
	* math/w_acos_template.c: New file.
	* math/w_acosh_template.c: Likewise.
	* math/w_asin_template.c: Likewise.
	* math/w_atan2_template.c: Likewise.
	* math/w_atanh_template.c: Likewise.
	* math/w_cosh_template.c: Likewise.
	* math/w_exp10_template.c: Likewise.
	* math/w_exp2_template.c: Likewise.
	* math/w_exp_template.c: Likewise.
	* math/w_fmod_template.c: Likewise.
	* math/w_hypot_template.c: Likewise.
	* math/w_j0_template.c: Likewise.
	* math/w_j1_template.c: Likewise.
	* math/w_jn_template.c: Likewise.
	* math/w_lgamma_r_template.c: Likewise.
	* math/w_lgamma_template.c: Likewise.
	* math/w_log10_template.c: Likewise.
	* math/w_log2_template.c: Likewise.
	* math/w_log_template.c: Likewise.
	* math/w_pow_template.c: Likewise.
	* math/w_remainder_template.c: Likewise.
	* math/w_sinh_template.c: Likewise.
	* math/w_sqrt_template.c: Likewise.
	* math/w_tgamma_template.c: Likewise.: Likewise.
	* sysdeps/generic/math-type-macros-double.h
	(__USE_WRAPPER_TEMPLATE): New macro to control inclusion of
	the new wrappers.
	* sysdeps/generic/math-type-macros-float.h: Likewise.
	* sysdeps/generic/math-type-macros-ldouble.h: Likewise.
---
 math/Makefile                              |  6 +++-
 math/w_acos_template.c                     | 38 +++++++++++++++++++++
 math/w_acosh_template.c                    | 38 +++++++++++++++++++++
 math/w_asin_template.c                     | 38 +++++++++++++++++++++
 math/w_atan2_template.c                    | 39 +++++++++++++++++++++
 math/w_atanh_template.c                    | 44 ++++++++++++++++++++++++
 math/w_cosh_template.c                     | 39 +++++++++++++++++++++
 math/w_exp10_template.c                    | 39 +++++++++++++++++++++
 math/w_exp2_template.c                     | 39 +++++++++++++++++++++
 math/w_exp_template.c                      | 43 ++++++++++++++++++++++++
 math/w_fmod_template.c                     | 39 +++++++++++++++++++++
 math/w_hypot_template.c                    | 39 +++++++++++++++++++++
 math/w_j0_template.c                       | 51 ++++++++++++++++++++++++++++
 math/w_j1_template.c                       | 51 ++++++++++++++++++++++++++++
 math/w_jn_template.c                       | 51 ++++++++++++++++++++++++++++
 math/w_lgamma_r_template.c                 | 53 +++++++++++++++++++++++++++++
 math/w_lgamma_template.c                   | 42 +++++++++++++++++++++++
 math/w_log10_template.c                    | 44 ++++++++++++++++++++++++
 math/w_log2_template.c                     | 44 ++++++++++++++++++++++++
 math/w_log_template.c                      | 44 ++++++++++++++++++++++++
 math/w_pow_template.c                      | 51 ++++++++++++++++++++++++++++
 math/w_remainder_template.c                | 39 +++++++++++++++++++++
 math/w_sinh_template.c                     | 39 +++++++++++++++++++++
 math/w_sqrt_template.c                     | 38 +++++++++++++++++++++
 math/w_tgamma_template.c                   | 54 ++++++++++++++++++++++++++++++
 sysdeps/generic/math-type-macros-double.h  |  3 ++
 sysdeps/generic/math-type-macros-float.h   |  3 ++
 sysdeps/generic/math-type-macros-ldouble.h |  3 ++
 28 files changed, 1050 insertions(+), 1 deletion(-)
 create mode 100644 math/w_acos_template.c
 create mode 100644 math/w_acosh_template.c
 create mode 100644 math/w_asin_template.c
 create mode 100644 math/w_atan2_template.c
 create mode 100644 math/w_atanh_template.c
 create mode 100644 math/w_cosh_template.c
 create mode 100644 math/w_exp10_template.c
 create mode 100644 math/w_exp2_template.c
 create mode 100644 math/w_exp_template.c
 create mode 100644 math/w_fmod_template.c
 create mode 100644 math/w_hypot_template.c
 create mode 100644 math/w_j0_template.c
 create mode 100644 math/w_j1_template.c
 create mode 100644 math/w_jn_template.c
 create mode 100644 math/w_lgamma_r_template.c
 create mode 100644 math/w_lgamma_template.c
 create mode 100644 math/w_log10_template.c
 create mode 100644 math/w_log2_template.c
 create mode 100644 math/w_log_template.c
 create mode 100644 math/w_pow_template.c
 create mode 100644 math/w_remainder_template.c
 create mode 100644 math/w_sinh_template.c
 create mode 100644 math/w_sqrt_template.c
 create mode 100644 math/w_tgamma_template.c
  

Comments

Joseph Myers Feb. 20, 2017, 11:14 p.m. UTC | #1
On Fri, 17 Feb 2017, Gabriel F. T. Gomes wrote:

> +#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE

I think throughout you should just use "#if __USE_WRAPPER_TEMPLATE", so 
that not being defined is an error.

> diff --git a/math/w_lgamma_r_template.c b/math/w_lgamma_r_template.c

> +  if (__glibc_unlikely (!isfinite (y)) && isfinite (x))
> +    /* Overflow.  */

Or pole error for negative integer arguments (inaccurate comment).

> diff --git a/math/w_lgamma_template.c b/math/w_lgamma_template.c

> +  if (__glibc_unlikely (!isfinite (y)) && isfinite (x))
> +    /* Overflow.  */

Likewise.

> +      else if (M_SUF (__floor) (x) == x && x < 0)
> +	/* Domain error: tgamma(x<0).  */

*integer* x < 0, not any x < 0 (inaccurate comment).

OK with those changes.
  

Patch

diff --git a/math/Makefile b/math/Makefile
index 2735212..9e29ad0 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -54,7 +54,11 @@  gen-libm-calls = cargF conjF cimagF crealF cabsF s_cacosF		  \
 		 s_ctanF s_ctanhF s_cexpF s_clogF s_cprojF s_csqrtF	  \
 		 s_cpowF s_clog10F s_fdimF s_nextdownF s_fmaxF s_fminF	  \
 		 s_nanF s_iseqsigF s_canonicalizeF w_ilogbF w_llogbF	  \
-		 w_log1pF w_scalblnF s_fmaxmagF s_fminmagF
+		 w_log1pF w_scalblnF s_fmaxmagF s_fminmagF w_acosF	  \
+		 w_acoshF w_asinF w_atan2F w_atanhF w_coshF w_exp10F	  \
+		 w_exp2F w_fmodF w_hypotF w_j0F w_j1F w_jnF w_logF	  \
+		 w_log10F w_log2F w_powF w_remainderF w_sinhF w_sqrtF	  \
+		 w_tgammaF w_lgammaF w_lgammaF_r w_expF
 
 libm-calls =								  \
 	e_acosF e_acoshF e_asinF e_atan2F e_atanhF e_coshF e_expF e_fmodF \
diff --git a/math/w_acos_template.c b/math/w_acos_template.c
new file mode 100644
index 0000000..25bbfef
--- /dev/null
+++ b/math/w_acos_template.c
@@ -0,0 +1,38 @@ 
+/* Wrapper to set errno for acos.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__acos) (FLOAT x)
+{
+  if (__glibc_unlikely (isgreater (M_SUF (fabs) (x), M_LIT (1.0))))
+    /* Domain error: acos(|x|>1).  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_acos) (x);
+}
+declare_mgen_alias (__acos, acos)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_acosh_template.c b/math/w_acosh_template.c
new file mode 100644
index 0000000..90237f6
--- /dev/null
+++ b/math/w_acosh_template.c
@@ -0,0 +1,38 @@ 
+/* Wrapper to set errno for acosh.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__acosh) (FLOAT x)
+{
+  if (__glibc_unlikely (isless (x,  M_LIT (1.0))))
+    /* Domain error: acosh(x<1).  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_acosh) (x);
+}
+declare_mgen_alias (__acosh, acosh)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_asin_template.c b/math/w_asin_template.c
new file mode 100644
index 0000000..30c817c
--- /dev/null
+++ b/math/w_asin_template.c
@@ -0,0 +1,38 @@ 
+/* Wrapper to set errno for asin.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__asin) (FLOAT x)
+{
+  if (__glibc_unlikely (isgreater (M_SUF (fabs) (x),  M_LIT (1.0))))
+    /* Domain error: asin(|x|>1).  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_asin) (x);
+}
+declare_mgen_alias (__asin, asin)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_atan2_template.c b/math/w_atan2_template.c
new file mode 100644
index 0000000..df24d41
--- /dev/null
+++ b/math/w_atan2_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for atan2.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <errno.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__atan2) (FLOAT y, FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_atan2) (y, x);
+  if (__glibc_unlikely (z == 0 && y != 0 && isfinite (x)))
+    /* Underflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__atan2, atan2)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_atanh_template.c b/math/w_atanh_template.c
new file mode 100644
index 0000000..53f7867
--- /dev/null
+++ b/math/w_atanh_template.c
@@ -0,0 +1,44 @@ 
+/* Wrapper to set errno for atanh.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__atanh) (FLOAT x)
+{
+  if (__glibc_unlikely (isgreaterequal (M_SUF (fabs) (x), M_LIT (1.0))))
+    {
+      if (M_SUF (fabs) (x) == 1)
+	/* Pole error: atanh(|x|==1).  */
+	__set_errno (ERANGE);
+      else
+	/* Domain error: atanh(|x|>1).  */
+	__set_errno (EDOM);
+    }
+  return M_SUF (__ieee754_atanh) (x);
+}
+declare_mgen_alias (__atanh, atanh)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_cosh_template.c b/math/w_cosh_template.c
new file mode 100644
index 0000000..0d6e7dd
--- /dev/null
+++ b/math/w_cosh_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for cosh.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__cosh) (FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_cosh) (x);
+  if (__glibc_unlikely (!isfinite (z)) && isfinite (x))
+    /* Overflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__cosh, cosh)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_exp10_template.c b/math/w_exp10_template.c
new file mode 100644
index 0000000..d125419
--- /dev/null
+++ b/math/w_exp10_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for exp10.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__exp10) (FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_exp10) (x);
+  if (__glibc_unlikely (!isfinite (z) || z == 0) && isfinite (x))
+    /* Overflow or underflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__exp10, exp10)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_exp2_template.c b/math/w_exp2_template.c
new file mode 100644
index 0000000..b505b04
--- /dev/null
+++ b/math/w_exp2_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for exp2.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__exp2) (FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_exp2) (x);
+  if (__glibc_unlikely (!isfinite (z) || z == 0) && isfinite (x))
+    /* Overflow or underflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__exp2, exp2)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_exp_template.c b/math/w_exp_template.c
new file mode 100644
index 0000000..1f3312e
--- /dev/null
+++ b/math/w_exp_template.c
@@ -0,0 +1,43 @@ 
+/* Wrapper to set errno for exp.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+/* Provide an additional macro expansion for hidden_def.  */
+#define hidden_def_x(name) hidden_def (name)
+
+FLOAT
+M_DECL_FUNC (__exp) (FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_exp) (x);
+  if (__glibc_unlikely (!isfinite (z) || z == 0) && isfinite (x))
+    /* Overflow or underflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+hidden_def_x (M_SUF (__exp))
+declare_mgen_alias (__exp, exp)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_fmod_template.c b/math/w_fmod_template.c
new file mode 100644
index 0000000..fb5842d
--- /dev/null
+++ b/math/w_fmod_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for fmod.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__fmod) (FLOAT x, FLOAT y)
+{
+  if (__builtin_expect (isinf (x) || y == 0, 0) && !isnan (y) && !isnan (x))
+    /* Domain error: fmod(+-Inf,y) or fmod(x,0).
+       If x or y are nan, these conditions should not be considered.  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_fmod) (x, y);
+}
+declare_mgen_alias (__fmod, fmod)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_hypot_template.c b/math/w_hypot_template.c
new file mode 100644
index 0000000..99fe179
--- /dev/null
+++ b/math/w_hypot_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for hypot.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__hypot) (FLOAT x, FLOAT y)
+{
+  FLOAT z = M_SUF (__ieee754_hypot) (x, y);
+  if (__glibc_unlikely (!isfinite (z)) && isfinite (x) && isfinite (y))
+    /* Overflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__hypot, hypot)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_j0_template.c b/math/w_j0_template.c
new file mode 100644
index 0000000..de4e5a1
--- /dev/null
+++ b/math/w_j0_template.c
@@ -0,0 +1,51 @@ 
+/* Wrapper to set errno for j0 and y0.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__j0) (FLOAT x)
+{
+  return M_SUF (__ieee754_j0) (x);
+}
+declare_mgen_alias (__j0, j0)
+
+FLOAT
+M_DECL_FUNC (__y0) (FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x < 0)
+	/* Domain error: y0(x<0).  */
+	__set_errno (EDOM);
+      else if (x == 0)
+	/* Pole error: y0(0).  */
+	__set_errno (ERANGE);
+    }
+  return M_SUF (__ieee754_y0) (x);
+}
+declare_mgen_alias (__y0, y0)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_j1_template.c b/math/w_j1_template.c
new file mode 100644
index 0000000..182e95c
--- /dev/null
+++ b/math/w_j1_template.c
@@ -0,0 +1,51 @@ 
+/* Wrapper to set errno for j1 and y1.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__j1) (FLOAT x)
+{
+  return M_SUF (__ieee754_j1) (x);
+}
+declare_mgen_alias (__j1, j1)
+
+FLOAT
+M_DECL_FUNC (__y1) (FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x < 0)
+	/* Domain error: y1(x<0).  */
+	__set_errno (EDOM);
+      else if (x == 0)
+	/* Pole error: y1(0).  */
+	__set_errno (ERANGE);
+    }
+  return M_SUF (__ieee754_y1) (x);
+}
+declare_mgen_alias (__y1, y1)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_jn_template.c b/math/w_jn_template.c
new file mode 100644
index 0000000..3471569
--- /dev/null
+++ b/math/w_jn_template.c
@@ -0,0 +1,51 @@ 
+/* Wrapper to set errno for jn and yn.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__jn) (int n, FLOAT x)
+{
+  return M_SUF (__ieee754_jn) (n, x);
+}
+declare_mgen_alias (__jn, jn)
+
+FLOAT
+M_DECL_FUNC (__yn) (int n, FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x < 0)
+	/* Domain error: yn(x<0).  */
+	__set_errno (EDOM);
+      else if (x == 0)
+	/* Pole error: yn(0).  */
+	__set_errno (ERANGE);
+    }
+  return M_SUF (__ieee754_yn) (n, x);
+}
+declare_mgen_alias (__yn, yn)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_lgamma_r_template.c b/math/w_lgamma_r_template.c
new file mode 100644
index 0000000..707cde6
--- /dev/null
+++ b/math/w_lgamma_r_template.c
@@ -0,0 +1,53 @@ 
+/* Wrapper to set errno for lgamma_r.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+#define M_DECL_FUNC_R_X(x) x ## _r
+#define M_DECL_FUNC_R_S(x) M_DECL_FUNC_R_X (x)
+#define M_DECL_FUNC_R(x) M_DECL_FUNC_R_S (M_SUF (x))
+
+#define M_CALL_FUNC_R_X(x) x ## _r
+#define M_CALL_FUNC_R_S(x) M_CALL_FUNC_R_X (x)
+#define M_CALL_FUNC_R(x) M_CALL_FUNC_R_S (M_SUF (x))
+
+#define declare_mgen_alias_r_x(from, to) weak_alias (from ## _r, to ## _r)
+#define declare_mgen_alias_r_s(from, to) \
+	declare_mgen_alias_r_x (from, to)
+#define declare_mgen_alias_r(from, to) \
+	declare_mgen_alias_r_s (M_SUF (from), M_SUF (to))
+
+FLOAT
+M_DECL_FUNC_R (__lgamma) (FLOAT x, int *signgamp)
+{
+  FLOAT y = M_CALL_FUNC_R (__ieee754_lgamma) (x, signgamp);
+  if (__glibc_unlikely (!isfinite (y)) && isfinite (x))
+    /* Overflow.  */
+    __set_errno (ERANGE);
+  return y;
+}
+declare_mgen_alias_r (__lgamma, lgamma)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_lgamma_template.c b/math/w_lgamma_template.c
new file mode 100644
index 0000000..294d0fb
--- /dev/null
+++ b/math/w_lgamma_template.c
@@ -0,0 +1,42 @@ 
+/* Wrapper to set errno for lgamma.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+#define M_CALL_FUNC_X(x) x ## _r
+#define M_CALL_FUNC(x) M_CALL_FUNC_X (x)
+
+FLOAT
+M_DECL_FUNC (__lgamma) (FLOAT x)
+{
+  FLOAT y = M_CALL_FUNC (M_SUF (__ieee754_lgamma)) (x, &__signgam);
+  if (__glibc_unlikely (!isfinite (y)) && isfinite (x))
+    /* Overflow.  */
+    __set_errno (ERANGE);
+  return y;
+}
+declare_mgen_alias (__lgamma, lgamma)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_log10_template.c b/math/w_log10_template.c
new file mode 100644
index 0000000..5166932
--- /dev/null
+++ b/math/w_log10_template.c
@@ -0,0 +1,44 @@ 
+/* Wrapper to set errno for log10.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__log10) (FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x == 0)
+	/* Pole error: log10(0).  */
+	__set_errno (ERANGE);
+      else
+	/* Domain error: log10(<0).  */
+	__set_errno (EDOM);
+    }
+  return M_SUF (__ieee754_log10) (x);
+}
+declare_mgen_alias (__log10, log10)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_log2_template.c b/math/w_log2_template.c
new file mode 100644
index 0000000..5e9cad5
--- /dev/null
+++ b/math/w_log2_template.c
@@ -0,0 +1,44 @@ 
+/* Wrapper to set errno for log2.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__log2) (FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x == 0)
+	/* Pole error: log2(0).  */
+	__set_errno (ERANGE);
+      else
+	/* Domain error: log2(<0).  */
+	__set_errno (EDOM);
+    }
+  return M_SUF (__ieee754_log2) (x);
+}
+declare_mgen_alias (__log2, log2)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_log_template.c b/math/w_log_template.c
new file mode 100644
index 0000000..13a16f4
--- /dev/null
+++ b/math/w_log_template.c
@@ -0,0 +1,44 @@ 
+/* Wrapper to set errno for log.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__log) (FLOAT x)
+{
+  if (__glibc_unlikely (islessequal (x, M_LIT (0.0))))
+    {
+      if (x == 0)
+	/* Pole error: log(0).  */
+	__set_errno (ERANGE);
+      else
+	/* Domain error: log(<0).  */
+	__set_errno (EDOM);
+    }
+  return M_SUF (__ieee754_log) (x);
+}
+declare_mgen_alias (__log, log)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_pow_template.c b/math/w_pow_template.c
new file mode 100644
index 0000000..7a6db19
--- /dev/null
+++ b/math/w_pow_template.c
@@ -0,0 +1,51 @@ 
+/* Wrapper to set errno for pow.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__pow) (FLOAT x, FLOAT y)
+{
+  FLOAT z = M_SUF (__ieee754_pow) (x, y);
+  if (__glibc_unlikely (!isfinite (z)))
+    {
+      if (isfinite (x) && isfinite (y))
+	{
+	  if (isnan (z))
+	    /* Domain error: pow(x<0,y=non-integer).  */
+	    __set_errno (EDOM);
+	  else
+	    /* Pole error: pow(x=0,y<0).  Or overflow.  */
+	    __set_errno (ERANGE);
+	}
+    }
+  else if (__glibc_unlikely (z == 0) && isfinite (x) && x != 0 && isfinite (y))
+    /* Underflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__pow, pow)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_remainder_template.c b/math/w_remainder_template.c
new file mode 100644
index 0000000..9a0176d
--- /dev/null
+++ b/math/w_remainder_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for remainder.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__remainder) (FLOAT x, FLOAT y)
+{
+  if (__glibc_unlikely (isinf (x) || y == 0) && !isnan (y) && !isnan (x))
+    /* Domain error: remainder(+-Inf,y) or remainder(x,0).
+       If x or y are nan, these conditions should not be considered.  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_remainder) (x, y);
+}
+declare_mgen_alias (__remainder, remainder)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_sinh_template.c b/math/w_sinh_template.c
new file mode 100644
index 0000000..7000fd3
--- /dev/null
+++ b/math/w_sinh_template.c
@@ -0,0 +1,39 @@ 
+/* Wrapper to set errno for sinh.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__sinh) (FLOAT x)
+{
+  FLOAT z = M_SUF (__ieee754_sinh) (x);
+  if (__glibc_unlikely (!isfinite (z)) && isfinite (x))
+    /* Overflow.  */
+    __set_errno (ERANGE);
+  return z;
+}
+declare_mgen_alias (__sinh, sinh)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_sqrt_template.c b/math/w_sqrt_template.c
new file mode 100644
index 0000000..d204a76
--- /dev/null
+++ b/math/w_sqrt_template.c
@@ -0,0 +1,38 @@ 
+/* Wrapper to set errno for sqrt.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+FLOAT
+M_DECL_FUNC (__sqrt) (FLOAT x)
+{
+  if (__glibc_unlikely (isless (x, M_LIT (0.0))))
+    /* Domain error: sqrt(x<-0).  */
+    __set_errno (EDOM);
+  return M_SUF (__ieee754_sqrt) (x);
+}
+declare_mgen_alias (__sqrt, sqrt)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/math/w_tgamma_template.c b/math/w_tgamma_template.c
new file mode 100644
index 0000000..d4c8529
--- /dev/null
+++ b/math/w_tgamma_template.c
@@ -0,0 +1,54 @@ 
+/* Wrapper to set errno for tgamma.
+   Copyright (C) 2017 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Only build wrappers from the templates for the types that define the macro
+   below.  This macro is set in math-type-macros-<type>.h in sysdeps/generic
+   for each floating-point type.  */
+#if defined __USE_WRAPPER_TEMPLATE && __USE_WRAPPER_TEMPLATE
+
+# include <fenv.h>
+# include <math.h>
+# include <math_private.h>
+
+#define M_CALL_FUNC_X(x) x ## _r
+#define M_CALL_FUNC(x) M_CALL_FUNC_X (x)
+
+FLOAT
+M_DECL_FUNC (__tgamma) (FLOAT x)
+{
+  int local_signgam;
+  FLOAT y = M_CALL_FUNC (M_SUF (__ieee754_gamma)) (x, &local_signgam);
+
+  if (__glibc_unlikely (!isfinite (y) || y == 0)
+      && (isfinite (x) || (isinf (x) && x < 0)))
+    {
+      if (x == 0)
+	/* Pole error: tgamma(x=0).  */
+	__set_errno (ERANGE);
+      else if (M_SUF (__floor) (x) == x && x < 0)
+	/* Domain error: tgamma(x<0).  */
+	__set_errno (EDOM);
+      else
+	/* Overflow or underflow.  */
+	__set_errno (ERANGE);
+    }
+  return local_signgam < 0 ? -y : y;
+}
+declare_mgen_alias (__tgamma, tgamma)
+
+#endif /* __USE_WRAPPER_TEMPLATE.  */
diff --git a/sysdeps/generic/math-type-macros-double.h b/sysdeps/generic/math-type-macros-double.h
index 8048d38..6116f7f 100644
--- a/sysdeps/generic/math-type-macros-double.h
+++ b/sysdeps/generic/math-type-macros-double.h
@@ -47,4 +47,7 @@ 
 /* Supply the generic macros.  */
 #include <math-type-macros.h>
 
+/* Do not use the type-generic wrapper templates.  */
+#define __USE_WRAPPER_TEMPLATE 0
+
 #endif
diff --git a/sysdeps/generic/math-type-macros-float.h b/sysdeps/generic/math-type-macros-float.h
index 03079ce..712e517 100644
--- a/sysdeps/generic/math-type-macros-float.h
+++ b/sysdeps/generic/math-type-macros-float.h
@@ -33,4 +33,7 @@ 
 /* Supply the generic macros.  */
 #include <math-type-macros.h>
 
+/* Do not use the type-generic wrapper templates.  */
+#define __USE_WRAPPER_TEMPLATE 0
+
 #endif
diff --git a/sysdeps/generic/math-type-macros-ldouble.h b/sysdeps/generic/math-type-macros-ldouble.h
index 31591a3..4e02e53 100644
--- a/sysdeps/generic/math-type-macros-ldouble.h
+++ b/sysdeps/generic/math-type-macros-ldouble.h
@@ -30,4 +30,7 @@ 
 /* Supply the generic macros.  */
 #include <math-type-macros.h>
 
+/* Do not use the type-generic wrapper templates.  */
+#define __USE_WRAPPER_TEMPLATE 0
+
 #endif