OSDN Git Service

2000-10-13 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libmath / cexpf.c
1 /* Return value of complex exponential function for float complex value. */
2 /* Copyright (C) 1997-1999 Free Software Foundation, Inc.
3
4    This file is part of the GNU ISO C++ Library.  This library is free
5    software; you can redistribute it and/or modify it under the
6    terms of the GNU General Public License as published by the
7    Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License along
16    with this library; see the file COPYING.  If not, write to the Free
17    Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18    USA.
19
20    As a special exception, you may use this file as part of a free software
21    library without restriction.  Specifically, if other files instantiate
22    templates or use macros or inline functions from this file, or you compile
23    this file and link it with other files to produce an executable, this
24    file does not by itself cause the resulting executable to be covered by
25    the GNU General Public License.  This exception does not however
26    invalidate any other reasons why the executable file might be covered by
27    the GNU General Public License.  */
28
29
30 #include <math.h>
31 #include "mathconf.h"
32
33
34 __complex__ float
35 cexpf (__complex__ float x)
36 {
37   __complex__ float retval;
38
39   if (FINITEF_P (__real__ x))
40     {
41       /* Real part is finite.  */
42       if (FINITEF_P (__imag__ x))
43         {
44           /* Imaginary part is finite.  */
45           float exp_val = expf (__real__ x);
46           float sinix = sinf (__imag__ x);
47           float cosix = cosf (__imag__ x);
48
49           if (FINITEF_P (exp_val))
50             {
51               __real__ retval = exp_val * cosix;
52               __imag__ retval = exp_val * sinix;
53             }
54           else
55             {
56               __real__ retval = copysignf (exp_val, cosix);
57               __imag__ retval = copysignf (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 (INFINITEF_P (__real__ x))
69     {
70       /* Real part is infinite.  */
71       if (FINITEF_P (__imag__ x))
72         {
73           /* Imaginary part is finite.  */
74           float value = signbit (__real__ x) ? 0.0 : HUGE_VALF;
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               float sinix = sinf (__imag__ x);
85               float cosix = cosf (__imag__ x);
86
87               __real__ retval = copysignf (value, cosix);
88               __imag__ retval = copysignf (value, sinix);
89             }
90         }
91       else if (signbit (__real__ x) == 0)
92         {
93           __real__ retval = HUGE_VALF;
94           __imag__ retval = NAN;
95         }
96       else
97         {
98           __real__ retval = 0.0;
99           __imag__ retval = copysignf (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 }