OSDN Git Service

* acinclude.m4 (GLIBCPP_ENABLE_CSTDIO): Make
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libmath / clog10l.c
1 /* Compute complex natural logarithm. */
2
3 /* Copyright (C) 1997-1999 Free Software Foundation, Inc.
4
5    This file is part of the GNU ISO C++ Library.  This library is free
6    software; you can redistribute it and/or modify it under the
7    terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License along
17    with this library; see the file COPYING.  If not, write to the Free
18    Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19    USA.
20
21    As a special exception, you may use this file as part of a free software
22    library without restriction.  Specifically, if other files instantiate
23    templates or use macros or inline functions from this file, or you compile
24    this file and link it with other files to produce an executable, this
25    file does not by itself cause the resulting executable to be covered by
26    the GNU General Public License.  This exception does not however
27    invalidate any other reasons why the executable file might be covered by
28    the GNU General Public License.  */
29
30 #ifndef _GNU_SOURCE
31 #define _GNU_SOURCE
32 #endif
33 #include <math.h>
34 #include "mathconf.h"
35 #ifndef M_PIl
36 #define M_PIl M_PI
37 #endif
38
39 /* Thanks to SGI we have to trick here.  At least Irix 6.2 provides hypotl,
40    but it has a wrong prototype.  Grrr.  */
41 extern long double local_hypotl (long double, long double) asm ("hypotl");
42
43
44 __complex__ long double
45 clog10l (__complex__ long double x)
46 {
47   __complex__ long double result;
48
49   if (x == 0.0)
50     {
51       /* Real and imaginary part are 0.0.  */
52       __imag__ result = signbit (__real__ x) ? M_PIl : 0.0;
53       __imag__ result = copysignl (__imag__ result, __imag__ x);
54       /* Yes, the following line raises an exception.  */
55       __real__ result = -1.0 / fabsl (__real__ x);
56     }
57   else if (__real__ x == __real__ x && __imag__ x == __imag__ x)
58     {
59       /* Neither real nor imaginary part is NaN.  */
60       __real__ result = log10l (local_hypotl (__real__ x, __imag__ x));
61       __imag__ result = atan2l (__imag__ x, __real__ x);
62     }
63   else
64     {
65       __imag__ result = NAN;
66       if (INFINITEL_P (__real__ x) || INFINITEL_P (__imag__ x))
67         /* Real or imaginary part is infinite.  */
68         __real__ result = HUGE_VALL;
69       else
70         __real__ result = NAN;
71     }
72
73   return result;
74 }