Back to index

glibc  2.9
s_clog10f.c
Go to the documentation of this file.
00001 /* Compute complex base 10 logarithm.
00002    Copyright (C) 1997 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <complex.h>
00022 #include <math.h>
00023 
00024 #include "math_private.h"
00025 
00026 
00027 __complex__ float
00028 __clog10f (__complex__ float x)
00029 {
00030   __complex__ float result;
00031   int rcls = fpclassify (__real__ x);
00032   int icls = fpclassify (__imag__ x);
00033 
00034   if (rcls == FP_ZERO && icls == FP_ZERO)
00035     {
00036       /* Real and imaginary part are 0.0.  */
00037       __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
00038       __imag__ result = __copysignf (__imag__ result, __imag__ x);
00039       /* Yes, the following line raises an exception.  */
00040       __real__ result = -1.0 / fabsf (__real__ x);
00041     }
00042   else if (rcls != FP_NAN && icls != FP_NAN)
00043     {
00044       /* Neither real nor imaginary part is NaN.  */
00045       __real__ result = __ieee754_log10f (__ieee754_hypotf (__real__ x,
00046                                                      __imag__ x));
00047       __imag__ result = M_LOG10E * __ieee754_atan2f (__imag__ x, __real__ x);
00048     }
00049   else
00050     {
00051       __imag__ result = __nanf ("");
00052       if (rcls == FP_INFINITE || icls == FP_INFINITE)
00053        /* Real or imaginary part is infinite.  */
00054        __real__ result = HUGE_VALF;
00055       else
00056        __real__ result = __nanf ("");
00057     }
00058 
00059   return result;
00060 }
00061 #ifndef __clog10f
00062 weak_alias (__clog10f, clog10f)
00063 #endif