From 76da7265320010c7a273ed99f53938c0f32d5fad Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 11 Apr 2012 16:30:13 -0300 Subject: 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. --- math/w_ilogbl.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 math/w_ilogbl.c (limited to 'math/w_ilogbl.c') 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 , 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 + . */ + +#include +#include +#include + +/* 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) -- cgit v1.2.3-70-g09d2