From aec0821ce78e5f006ed45c063b4a129292bb739a Mon Sep 17 00:00:00 2001 From: "Gabriel F. T. Gomes" Date: Thu, 15 Dec 2016 16:41:58 -0200 Subject: Add new templates for IEEE wrappers 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. * 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 +++++++++++++++++++++++++++++++++++++++++++++ 25 files changed, 1041 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 (limited to 'math') diff --git a/math/Makefile b/math/Makefile index 1941abcafd..0cd3a4b4b9 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 0000000000..ea0e7d4f02 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..31f63dbd96 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..41c610245f --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..bfab6e83b8 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..771af5aff8 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..b912e6e6a5 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..8f7997dd35 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..76577c7fca --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..c0a4ec5be3 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +/* 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 0000000000..06d7c75661 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..9298add756 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..f49874fa10 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..6d1058f7e0 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..fd138359be --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..977d1b5fc4 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +#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)) + /* Pole error: lgamma_r(integer x<0). Or 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 0000000000..a60413d937 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +#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)) + /* Pole error: lgamma(integer x<0). Or 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 0000000000..92735f0340 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..a80b287da6 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..3f9830c196 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..50431b985f --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..4ecf10d360 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..7a147ded9d --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..f97074f062 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +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 0000000000..277a8377e3 --- /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 + . */ + +/* Only build wrappers from the templates for the types that define the macro + below. This macro is set in math-type-macros-.h in sysdeps/generic + for each floating-point type. */ +#if __USE_WRAPPER_TEMPLATE + +# include +# include +# include + +#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(integer 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. */ -- cgit 1.4.1