[BZ,#22243] fix log2(0) and log(10) in downward rounding

Message ID 59D3C21A.4010704@arm.com
State Committed
Commit 8f8f8ef7aba40ef883291e4c4d95a419c3327d70
Headers

Commit Message

Szabolcs Nagy Oct. 3, 2017, 5 p.m. UTC
  On 64bit targets if the SVID compat wrapper is suppressed (e.g. static linking)
then log2(0) and log10(0) returned inf instead of -inf.

2017-10-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	[BZ #22243]
	* sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c (__ieee754_log10): Use fabs.
	* sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c (__ieee754_log2): Likewise.
  

Comments

Joseph Myers Oct. 3, 2017, 5:43 p.m. UTC | #1
On Tue, 3 Oct 2017, Szabolcs Nagy wrote:

> On 64bit targets if the SVID compat wrapper is suppressed (e.g. static linking)
> then log2(0) and log10(0) returned inf instead of -inf.
> 
> 2017-10-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>
> 
> 	[BZ #22243]
> 	* sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c (__ieee754_log10): Use fabs.
> 	* sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c (__ieee754_log2): Likewise.

OK.
  

Patch

diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c b/sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c
index 4f5a81669e..cd5567182f 100644
--- a/sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c
@@ -65,7 +65,7 @@  __ieee754_log10 (double x)
   if (hx < INT64_C(0x0010000000000000))
     {				/* x < 2**-1022  */
       if (__glibc_unlikely ((hx & UINT64_C(0x7fffffffffffffff)) == 0))
-	return -two54 / (x - x);	/* log(+-0)=-inf */
+	return -two54 / fabs (x);	/* log(+-0)=-inf */
       if (__glibc_unlikely (hx < 0))
 	return (x - x) / (x - x);	/* log(-#) = NaN */
       k -= 54;
diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c b/sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c
index 5ccb78cf03..f08d5b337d 100644
--- a/sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c
@@ -81,7 +81,7 @@  __ieee754_log2 (double x)
   if (hx < INT64_C(0x0010000000000000))
     {				/* x < 2**-1022  */
       if (__glibc_unlikely ((hx & UINT64_C(0x7fffffffffffffff)) == 0))
-	return -two54 / (x - x);	/* log(+-0)=-inf */
+	return -two54 / fabs (x);	/* log(+-0)=-inf */
       if (__glibc_unlikely (hx < 0))
 	return (x - x) / (x - x);	/* log(-#) = NaN */
       k -= 54;