mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Fix clog overflow/underflow (bug 13629).
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/* Compute complex base 10 logarithm.
|
||||
Copyright (C) 1997, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 1997-2012 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
||||
|
||||
@ -20,7 +20,10 @@
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
#include <math_private.h>
|
||||
#include <float.h>
|
||||
|
||||
/* log_10 (2). */
|
||||
#define M_LOG10_2 0.3010299956639811952137388947244930267682
|
||||
|
||||
__complex__ double
|
||||
__clog10 (__complex__ double x)
|
||||
@ -40,8 +43,27 @@ __clog10 (__complex__ double x)
|
||||
else if (__builtin_expect (rcls != FP_NAN && icls != FP_NAN, 1))
|
||||
{
|
||||
/* Neither real nor imaginary part is NaN. */
|
||||
__real__ result = __ieee754_log10 (__ieee754_hypot (__real__ x,
|
||||
__imag__ x));
|
||||
double d;
|
||||
int scale = 0;
|
||||
|
||||
if (fabs (__real__ x) > DBL_MAX / 2.0
|
||||
|| fabs (__imag__ x) > DBL_MAX / 2.0)
|
||||
{
|
||||
scale = -1;
|
||||
__real__ x = __scalbn (__real__ x, scale);
|
||||
__imag__ x = __scalbn (__imag__ x, scale);
|
||||
}
|
||||
else if (fabs (__real__ x) < DBL_MIN
|
||||
&& fabs (__imag__ x) < DBL_MIN)
|
||||
{
|
||||
scale = DBL_MANT_DIG;
|
||||
__real__ x = __scalbn (__real__ x, scale);
|
||||
__imag__ x = __scalbn (__imag__ x, scale);
|
||||
}
|
||||
|
||||
d = __ieee754_hypot (__real__ x, __imag__ x);
|
||||
|
||||
__real__ result = __ieee754_log10 (d) - scale * M_LOG10_2;
|
||||
__imag__ result = M_LOG10E * __ieee754_atan2 (__imag__ x, __real__ x);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user