OSDN Git Service

* acinclude.m4: Don't forget to remove check for cpowl as it is no
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libmath / cexpl.c
1 /* Return value of complex exp function for long double complex value. */
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 #include <math.h>
31 #include "mathconf.h"
32
33
34 __complex__ long double
35 cexpl (__complex__ long double x)
36 {
37   __complex__ long double retval;
38
39   if (FINITEL_P (__real__ x))
40     {
41       /* Real part is finite.  */
42       if (FINITEL_P (__imag__ x))
43         {
44           /* Imaginary part is finite.  */
45           long double exp_val = expl (__real__ x);
46           long double sinix = sinl (__imag__ x);
47           long double cosix = cosl (__imag__ x);
48
49           if (FINITEL_P (exp_val))
50             {
51               __real__ retval = exp_val * cosix;
52               __imag__ retval = exp_val * sinix;
53             }
54           else
55             {
56               __real__ retval = copysignl (exp_val, cosix);
57               __imag__ retval = copysignl (exp_val, sinix);
58             }
59         }
60       else
61         {
62           /* If the imaginary part is +-inf or NaN and the real part
63              is not +-inf the result is NaN + iNaN.  */
64           __real__ retval = NAN;
65           __imag__ retval = NAN;
66         }
67     }
68   else if (INFINITEL_P (__real__ x))
69     {
70       /* Real part is infinite.  */
71       if (FINITEL_P (__imag__ x))
72         {
73           /* Imaginary part is finite.  */
74           long double value = signbit (__real__ x) ? 0.0 : HUGE_VALL;
75
76           if (__imag__ x == 0.0)
77             {
78               /* Imaginary part is 0.0.  */
79               __real__ retval = value;
80               __imag__ retval = __imag__ x;
81             }
82           else
83             {
84               long double sinix = sinl (__imag__ x);
85               long double cosix = cosl (__imag__ x);
86
87               __real__ retval = copysignl (value, cosix);
88               __imag__ retval = copysignl (value, sinix);
89             }
90         }
91       else if (signbit (__real__ x) == 0)
92         {
93           __real__ retval = HUGE_VALL;
94           __imag__ retval = NAN;
95         }
96       else
97         {
98           __real__ retval = 0.0;
99           __imag__ retval = copysignl (0.0, __imag__ x);
100         }
101     }
102   else
103     {
104       /* If the real part is NaN the result is NaN + iNaN.  */
105       __real__ retval = NAN;
106       __imag__ retval = NAN;
107     }
108
109   return retval;
110 }