diff options
author | Adhemerval Zanella <azanella@linux.vnet.ibm.com> | 2012-04-11 16:30:13 -0300 |
---|---|---|
committer | Andreas Jaeger <aj@suse.de> | 2012-04-17 22:12:53 +0200 |
commit | 76da7265320010c7a273ed99f53938c0f32d5fad (patch) | |
tree | f094871a5f38652d2d320a11423fee602a8746e6 /math | |
parent | 0396e69dbefb3630651d93e0a7526c4326a071bb (diff) | |
download | glibc-76da7265320010c7a273ed99f53938c0f32d5fad.tar.gz |
Fix ilogb exception and errno (bug 6794)
[BZ #6794]
Following Joseph comments about bug 6794, here is a proposed fix. It turned out
to be a large fix mainly because I had to move some file along to follow libm
files/names conventions.
Basically I have added wrappers (w_ilogb.c, w_ilogbf.c, w_ilogbl.c) that now calls
the symbol '__ieee754_ilogb'. The wrappers checks for '__ieee754_ilogb' output and
set the errno and raise exceptions as expected.
The '__ieee754_ilogb' is implemented in sysdeps. I have moved the 's_ilogb[f|l]' files
to e_ilogb[f|l] and renamed the '__ilogb[f|l]' to '__ieee754_ilogb[f|l]'.
I also found out a bug in i386 and x86-64 assembly coded ilogb implementation where
it raises a FE_DIVBYZERO when argument is '0.0'. I corrected this issue as well.
Finally I added the errno and FE_INVALID tests for 0.0, NaN and +-InF argument. Tested
on i386, x86-64, ppc32 and ppc64.
Diffstat (limited to 'math')
-rw-r--r-- | math/Makefile | 4 | ||||
-rw-r--r-- | math/libm-test.inc | 23 | ||||
-rw-r--r-- | math/w_ilogb.c | 42 | ||||
-rw-r--r-- | math/w_ilogbf.c | 38 | ||||
-rw-r--r-- | math/w_ilogbl.c | 37 |
5 files changed, 136 insertions, 8 deletions
diff --git a/math/Makefile b/math/Makefile index 3a671aac71..abeba7a931 100644 --- a/math/Makefile +++ b/math/Makefile @@ -42,14 +42,16 @@ libm-support = k_standard s_lib_version s_matherr s_signgam \ libm-calls = e_acos e_acosh e_asin e_atan2 e_atanh e_cosh e_exp e_fmod \ e_hypot e_j0 e_j1 e_jn e_lgamma_r e_log e_log10 e_pow \ e_rem_pio2 e_remainder e_scalb e_sinh e_sqrt e_gamma_r \ + e_ilogb \ k_cos k_rem_pio2 k_sin k_tan s_asinh s_atan s_cbrt \ s_ceil s_cos s_erf s_expm1 s_fabs \ - s_floor s_ilogb s_log1p s_logb \ + s_floor s_log1p s_logb \ s_nextafter s_nexttoward s_rint s_scalbln \ s_significand s_sin s_tan s_tanh w_acos w_acosh w_asin \ w_atan2 w_atanh w_cosh w_drem w_exp w_exp2 w_exp10 w_fmod \ w_tgamma w_hypot w_j0 w_j1 w_jn w_lgamma w_lgamma_r \ w_log w_log10 w_pow w_remainder w_scalb w_sinh w_sqrt \ + w_ilogb \ s_fpclassify s_fmax s_fmin s_fdim s_nan s_trunc \ s_remquo e_log2 e_exp2 s_round s_nearbyint s_sincos \ conj cimag creal cabs carg s_cexp s_csinh s_ccosh s_clog \ diff --git a/math/libm-test.inc b/math/libm-test.inc index 2809d57d09..94d60bff7e 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -3802,13 +3802,22 @@ ilogb_test (void) TEST_f_i (ilogb, 1024, 10); TEST_f_i (ilogb, -2000, 10); - /* XXX We have a problem here: the standard does not tell us whether - exceptions are allowed/required. ignore them for now. */ - - TEST_f_i (ilogb, 0.0, FP_ILOGB0, EXCEPTIONS_OK); - TEST_f_i (ilogb, nan_value, FP_ILOGBNAN, EXCEPTIONS_OK); - TEST_f_i (ilogb, plus_infty, INT_MAX, EXCEPTIONS_OK); - TEST_f_i (ilogb, minus_infty, INT_MAX, EXCEPTIONS_OK); + /* ilogb (0.0) == FP_ILOGB0 plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, 0.0, FP_ILOGB0, INVALID_EXCEPTION); + check_int ("errno for ilogb(0.0) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (NaN) == FP_ILOGBNAN plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, nan_value, FP_ILOGBNAN, INVALID_EXCEPTION); + check_int ("errno for ilogb(NaN) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (inf) == INT_MAX plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, plus_infty, INT_MAX, INVALID_EXCEPTION); + check_int ("errno for ilogb(Inf) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (-inf) == INT_MAX plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, minus_infty, INT_MAX, INVALID_EXCEPTION); + check_int ("errno for ilogb(-Inf) unchanged", errno, EDOM, 0, 0, 0); END (ilogb); } diff --git a/math/w_ilogb.c b/math/w_ilogb.c new file mode 100644 index 0000000000..c87b517c50 --- /dev/null +++ b/math/w_ilogb.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + 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/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogb */ +int +__ilogb (double x) +{ + int r = __ieee754_ilogb (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} + +weak_alias (__ilogb, ilogb) +#ifdef NO_LONG_DOUBLE +strong_alias (__ilogb, __ilogbl) +weak_alias (__ilogb, ilogbl) +#endif diff --git a/math/w_ilogbf.c b/math/w_ilogbf.c new file mode 100644 index 0000000000..ae3574a75d --- /dev/null +++ b/math/w_ilogbf.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + 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/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogbf */ +int +__ilogbf (float x) +{ + int r = __ieee754_ilogbf (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} + +weak_alias (__ilogbf, ilogbf) diff --git a/math/w_ilogbl.c b/math/w_ilogbl.c new file mode 100644 index 0000000000..8c30caa48b --- /dev/null +++ b/math/w_ilogbl.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + 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/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogbl */ +int +__ilogbl (long double x) +{ + int r = __ieee754_ilogbl (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} +weak_alias (__ilogbl, ilogbl) |